From 004e5b3424f02b2b413a52d7162594c4cc5c5547 Mon Sep 17 00:00:00 2001
From: houxiao <houxiao@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期三, 28 六月 2017 14:02:52 +0800
Subject: [PATCH] add compare bin proto
---
FaceServer/STFaceCache.cpp | 21 ++++++++++
FaceServer/main_face_daemon.cpp | 11 ++---
FaceServer/face_daemon_proto.h | 2
FaceServer/sample_face_search.h | 6 ++-
FaceServer/compare2.jpg | 0
FaceServer/sample_face_search.cpp | 40 ++++++++++++++++++++
FaceServer/test_client_compare.cpp | 32 ++++++++++++---
FaceServer/STFaceCache.h | 2
8 files changed, 97 insertions(+), 17 deletions(-)
diff --git a/FaceServer/STFaceCache.cpp b/FaceServer/STFaceCache.cpp
index b527a40..fa5bf46 100644
--- a/FaceServer/STFaceCache.cpp
+++ b/FaceServer/STFaceCache.cpp
@@ -23,6 +23,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;
+ }
};
struct STFaceDBContext
@@ -320,3 +330,14 @@
else
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;
+}
diff --git a/FaceServer/STFaceCache.h b/FaceServer/STFaceCache.h
index 4a9f723..6d5442b 100644
--- a/FaceServer/STFaceCache.h
+++ b/FaceServer/STFaceCache.h
@@ -20,7 +20,7 @@
FDP_FaceDetectResult detect(const STFaceImage& img);
FDP_FaceDetectResult add(const STFaceImage& img);
fdr_vec_t search(const STFaceImage& img);
- FDP_FaceDetectResult compare(const STFaceImage& img);
+ FDP_FaceDetectResult compare(const STFaceImage& img1, const STFaceImage& img2);
//#todo need a delete img, if business not linked faceid and its personid
// they can delete it and save/find again!
diff --git a/FaceServer/compare2.jpg b/FaceServer/compare2.jpg
new file mode 100644
index 0000000..36f65e4
--- /dev/null
+++ b/FaceServer/compare2.jpg
Binary files differ
diff --git a/FaceServer/face_daemon_proto.h b/FaceServer/face_daemon_proto.h
index 1ac3a8a..2c2aca0 100644
--- a/FaceServer/face_daemon_proto.h
+++ b/FaceServer/face_daemon_proto.h
@@ -53,7 +53,7 @@
{
int32_t db_id;
int32_t st_id; // sensetime id
- int16_t confidence; // 1000 times of float confidence
+ int16_t confidence; // 1000 times of float confidence, less than zero means error
FDP_FaceDetectResult(int32_t _db_id, int32_t _st_id, int _confidence) : db_id(_db_id), st_id(_st_id), confidence(_confidence)
{}
diff --git a/FaceServer/main_face_daemon.cpp b/FaceServer/main_face_daemon.cpp
index ec706f7..039ec87 100644
--- a/FaceServer/main_face_daemon.cpp
+++ b/FaceServer/main_face_daemon.cpp
@@ -183,12 +183,11 @@
//fclose(pFile);
//pFile = nullptr;
- //fdr_vec_t result;
- //FDP_FaceDetectResult fdrResult = g_STFaceCache.add(stfaceImg);
- //result.push_back(fdrResult);
- //
- //int ret = (fdrResult.db_id == 0 ? -1 : 0);
- //return send_SensetimeFaceDetectResultJson(client, result, ret);
+ fdr_vec_t result;
+ FDP_FaceDetectResult fdrResult = g_STFaceCache.compare(stfaceImg1, stfaceImg2);
+ result.push_back(fdrResult);
+
+ return send_SensetimeFaceDetectResultJson(client, result, 0);
}
bool ev_dispatcher_proto_pb(EVClientStub& client)
diff --git a/FaceServer/sample_face_search.cpp b/FaceServer/sample_face_search.cpp
index 93a6bdc..ac36fc4 100644
--- a/FaceServer/sample_face_search.cpp
+++ b/FaceServer/sample_face_search.cpp
@@ -133,6 +133,17 @@
// fclose(pFile);
//}
}
+ else if (image.mb_type == MB_Frame::MBFT_JPEG)
+ {
+ Mat matTmp = imdecode(_InputArray(image.buff, image.size), CV_LOAD_IMAGE_COLOR);
+
+ //imwrite("aaa.jpg", matTmp);
+
+ imgbufSize = matTmp.total() * matTmp.elemSize();
+ memcpy(imgbuf, matTmp.ptr(), imgbufSize);
+
+ stimgfmt = CV_PIX_FMT_BGR888;
+ }
else
{
LOG_WARN << "mb frame type not support" << LOG_ENDL;
@@ -178,6 +189,35 @@
return p_feature;
}
+float stface_compare(stface_handles& handles, const STFaceImage& image1, const STFaceImage& image2)
+{
+ cv_feature_t* f1 = stface_extract_feature(handles, image1);
+ if (f1 == nullptr)
+ {
+ LOGP(INFO, "can't find face in image1");
+ return -1.0;
+ }
+
+ cv_feature_t* f2 = stface_extract_feature(handles, image2);
+ if (f2 == nullptr)
+ {
+ cv_verify_release_feature(f1);
+ LOGP(INFO, "can't find face in image1");
+ return -1.0;
+ }
+
+ float score = -1.0;
+ cv_result_t cv_result = cv_verify_compare_feature(handles.handle_verify, f1, f2, &score);
+ if (cv_result != CV_OK) {
+ LOGP(DEBUG, "cv_verify_compare_feature failed, error code %d", cv_result);
+ score = -1.0;
+ }
+
+ cv_verify_release_feature(f1);
+ cv_verify_release_feature(f2);
+ return score;
+}
+
int stface_db_add(stface_handles& handles, const char *image_path) {
cv_feature_t *p_feature = stface_extract_feature(handles, image_path);
if (!p_feature) {
diff --git a/FaceServer/sample_face_search.h b/FaceServer/sample_face_search.h
index 8d6075a..e121b16 100644
--- a/FaceServer/sample_face_search.h
+++ b/FaceServer/sample_face_search.h
@@ -10,10 +10,10 @@
struct stface_handles
{
cv_handle_t handle_verify;
- cv_handle_t handle_db;
cv_handle_t handle_detect;
+ cv_handle_t handle_db;
- stface_handles() : handle_verify(nullptr), handle_db(nullptr), handle_detect(nullptr)
+ stface_handles() : handle_verify(nullptr), handle_detect(nullptr), handle_db(nullptr)
{}
};
@@ -41,6 +41,8 @@
cv_feature_t *stface_extract_feature(stface_handles& handles, const char *image_path);
cv_feature_t *stface_extract_feature(stface_handles& handles, const STFaceImage& image);
+float stface_compare(stface_handles& handles, const STFaceImage& image1, const STFaceImage& image2);
+
int stface_db_add(stface_handles& handles, const char *image_path);
int stface_db_add(stface_handles& handles, const STFaceImage& image);
diff --git a/FaceServer/test_client_compare.cpp b/FaceServer/test_client_compare.cpp
index 59f4633..e6a5ad9 100644
--- a/FaceServer/test_client_compare.cpp
+++ b/FaceServer/test_client_compare.cpp
@@ -67,20 +67,38 @@
FDP_Image* fdpImage2 = nullptr;
{
fdpImage2 = new (mesg + evpHeader->size) FDP_Image;
-
+
fdpImage2->db_id = 0; // -1
- fdpImage2->mb_type = MB_Frame::MBFT_RGB565; // 14
- fdpImage2->width = 52;
- fdpImage2->height = 52;
+ fdpImage2->mb_type = MB_Frame::MBFT_JPEG; // 14
+ fdpImage2->width = 198;
+ fdpImage2->height = 154;
- FILE* pFile = fopen("face-13-w52-h52.rgb565", "rb");
+ FILE* pFile = fopen("compare2.jpg", "rb");
fdpImage2->size = fread(fdpImage2->buff, 1, length, pFile);
fclose(pFile);
pFile = nullptr;
-
+
evpHeader->size += sizeof(FDP_Image) + fdpImage2->size;
fdpImage2->hton();
- }
+ }
+
+ //FDP_Image* fdpImage2 = nullptr;
+ //{
+ // fdpImage2 = new (mesg + evpHeader->size) FDP_Image;
+ //
+ // fdpImage2->db_id = 0; // -1
+ // fdpImage2->mb_type = MB_Frame::MBFT_RGB565; // 14
+ // fdpImage2->width = 52;
+ // fdpImage2->height = 52;
+ //
+ // FILE* pFile = fopen("face-13-w52-h52.rgb565", "rb");
+ // fdpImage2->size = fread(fdpImage2->buff, 1, length, pFile);
+ // fclose(pFile);
+ // pFile = nullptr;
+ //
+ // evpHeader->size += sizeof(FDP_Image) + fdpImage2->size;
+ // fdpImage2->hton();
+ //}
length = evpHeader->size;
evpHeader->hton();
--
Gitblit v1.8.0