| | |
| | | #include "sample_face_search.h" |
| | | #include <cv_face.h> |
| | | |
| | | #define FDP_FDR_INVALID FDP_FaceDetectResult(0, 0, 0) |
| | | #define ENABLE_AUTO_CREATE_STFACEDB |
| | | #define ENABLE_SEARCH_IN_NEGATIVE_DBID |
| | | #define ENABLE_SEARCH_IN_NEGATIVE_DBID |
| | | #define RESULT_CONFIDENCE 0.70 |
| | | |
| | | struct STFaceCacheContext |
| | | { |
| | | cv_handle_t handle_verify; |
| | |
| | | |
| | | STFaceCache::STFaceCache(const std::string& _stfacedbPath) |
| | | : stfacedbPath(_stfacedbPath), stfaceModels(STFACESDK_BASE "/models"), |
| | | _dbContext(new stface_ctx_map_t), _cacheContext(new STFaceCacheContext) |
| | | _dbContext(new stface_ctx_map_t), _cacheContext(new STFaceCacheContext), |
| | | tempdbFaceCount(0) |
| | | { |
| | | LOG_INFO << "st face db: " << stfacedbPath << LOG_ENDL; |
| | | LOG_INFO << "st face sdk models: " << stfaceModels << LOG_ENDL; |
| | |
| | | return FDP_FDR_INVALID; |
| | | } |
| | | |
| | | #ifdef ENABLE_SEARCH_IN_NEGATIVE_DBID |
| | | #ifdef ENABLE_DETECT_IN_NEGATIVE_DBID |
| | | STFaceImage imgNeg(img); |
| | | imgNeg.db_id = -1; |
| | | return detect(imgNeg); |
| | | #else |
| | | return FDP_FDR_INVALID; |
| | | FDP_FaceDetectResult res(FDP_FDR_INVALID); |
| | | |
| | | imgNeg.db_id = STFS_DBID_VISITOR_1; |
| | | res = detect(imgNeg); // #todo optimize extract feature once |
| | | if (res.db_id != STFS_DBID_INVALID) |
| | | return res; |
| | | |
| | | imgNeg.db_id = STFS_DBID_TEMPDB_1; |
| | | res = detect(imgNeg); |
| | | if (res.db_id != STFS_DBID_INVALID) |
| | | return res; |
| | | #endif |
| | | |
| | | return FDP_FDR_INVALID; |
| | | } |
| | | |
| | | FDP_FaceDetectResult STFaceCache::detect(const STFaceImage& img) |
| | |
| | | return FDP_FDR_INVALID; |
| | | } |
| | | |
| | | #ifdef ENABLE_ADD_TO_TEMPDB_WHEN_NOT_DETECT |
| | | tempdbFaceCount++; |
| | | #endif |
| | | |
| | | int idx = stface_db_add(ctx.handles, img); |
| | | LOG_INFO << "stface_db_add dbid=" << img.db_id << ", idx=" << idx << LOG_ENDL; |
| | | if (idx <= 1) |
| | |
| | | { |
| | | stface_ctx_map_t& dbContext(*(stface_ctx_map_t*)_dbContext); |
| | | STFaceCacheContext& cacheContext(*(STFaceCacheContext*)_cacheContext); |
| | | |
| | | |
| | | for(stface_ctx_map_t::iterator iterCtx = dbContext.begin(); iterCtx != dbContext.end(); ++iterCtx) |
| | | { |
| | |
| | | topResult.push_back(FDP_FaceDetectResult(1, 6, 5)); |
| | | */ |
| | | } |
| | | |
| | | void STFaceCache::delete_db(int dbid) |
| | | { |
| | | stface_ctx_map_t& dbContext(*(stface_ctx_map_t*)_dbContext); |
| | | STFaceCacheContext& cacheContext(*(STFaceCacheContext*)_cacheContext); |
| | | |
| | | stface_ctx_map_t::iterator iterCtx = dbContext.find(dbid); |
| | | if (iterCtx == dbContext.end()) |
| | | { |
| | | LOG_WARN << "no dbid=%d" << dbid << LOG_ENDL; |
| | | return; |
| | | } |
| | | |
| | | STFaceDBContext& ctx(iterCtx->second); |
| | | ctx.close_db(); |
| | | |
| | | char mvDBtoBak[1000]; |
| | | sprintf(mvDBtoBak, "cd %s; mv %s %d.bak;", stfacedbPath.c_str(), ctx.db_full_path().c_str(), dbid); |
| | | system(mvDBtoBak); |
| | | |
| | | dbContext.erase(iterCtx); |
| | | } |