From 9ee90782bf14b91442cd524bc033bbf6d1778bb2 Mon Sep 17 00:00:00 2001 From: houxiao <houxiao@454eff88-639b-444f-9e54-f578c98de674> Date: 星期四, 29 六月 2017 10:32:05 +0800 Subject: [PATCH] aaaaa --- FaceServer/STFaceCache.cpp | 83 ++++++++++++++++++++++++++++++++++++++++- 1 files changed, 80 insertions(+), 3 deletions(-) diff --git a/FaceServer/STFaceCache.cpp b/FaceServer/STFaceCache.cpp index c603dca..8ec96b1 100644 --- a/FaceServer/STFaceCache.cpp +++ b/FaceServer/STFaceCache.cpp @@ -9,7 +9,7 @@ #include "sample_face_search.h" #include <cv_face.h> -#define FDP_FDR_INVALID FDP_FaceDetectResult(0, 0) +#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 @@ -22,6 +22,16 @@ STFaceCacheContext() : handle_verify(nullptr), handle_detect(nullptr) { + } + + stface_handles getStFaceHandles() + { + //return (stface_handles*)this; + + stface_handles handles; + handles.handle_verify = handle_verify; + handles.handle_detect = handle_detect; + return handles; } }; @@ -254,7 +264,7 @@ return detect_neg(img); } - return FDP_FaceDetectResult(img.db_id, result[0].idx); + return FDP_FaceDetectResult(img.db_id, result[0].idx, result[0].score * 1000); } return FDP_FDR_INVALID; @@ -318,5 +328,72 @@ if (idx <= 1) return FDP_FDR_INVALID; else - return FDP_FaceDetectResult(img.db_id, idx); + return FDP_FaceDetectResult(img.db_id, idx, 0); } + +FDP_FaceDetectResult STFaceCache::compare(const STFaceImage& img1, const STFaceImage& img2) +{ + stface_ctx_map_t& dbContext(*(stface_ctx_map_t*)_dbContext); + STFaceCacheContext& cacheContext(*(STFaceCacheContext*)_cacheContext); + + stface_handles handles(cacheContext.getStFaceHandles()); + float c = stface_compare(handles, img1, img2); + FDP_FaceDetectResult result(0, 0, int(c * 1000)); + return result; +} + +void STFaceCache::search(const STFaceImage& img, fdr_vec_t& topResult) +{ + 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) + { + STFaceDBContext& ctx(iterCtx->second); + if (!ctx.dbLoadOK) + { + LOG_WARN << "dbLoadOK return false" << LOG_ENDL; + continue; + } + + top_idx_score_vect_t result; + if (!stface_search_db(ctx.handles, img, result)) + { + LOG_WARN << "stface_search_db return false" << LOG_ENDL; + continue; + } + + if (result.empty()) + { + LOG_INFO << "stface_search_db return empty" << LOG_ENDL; + continue; + } + + for(top_idx_score_vect_t::iterator it = result.begin(); it != result.end(); ++it) + { + if(topResult.empty()) + topResult.push_back(FDP_FaceDetectResult(ctx.dbid, it->idx, it->score * 1000)); + + int16_t new_confidence = it->score * 1000; + else if(new_confidence > topResult.rbegin()->confidence) + { + while(topResult.size() > 4) + topResult.pop_back(); + for(fdr_vec_t::reverse_iterator rtTR = topResult.rbegin() + 1; rtTR != topResult.rend(); ++rtTR) + { + if(new_confidence < rtTR->confidence) + topResult.insert(rtTR, FDP_FaceDetectResult(ctx.dbid, it->idx, new_confidence)); + } + } + } + + //LOGP(INFO, "stface_search_db return dbid=%d, idx=%d, score=%f", img.db_id, result[0].idx, result[0].score); + } + */ + + topResult.push_back(FDP_FaceDetectResult(1, 2, 3)); + topResult.push_back(FDP_FaceDetectResult(-1, 2, 4)); + topResult.push_back(FDP_FaceDetectResult(1, 6, 5)); + return FDP_FaceDetectResult(img.db_id, result[0].idx, result[0].score * 1000); +} \ No newline at end of file -- Gitblit v1.8.0