From 1668865343c3069a65c241e167618be31a1a0549 Mon Sep 17 00:00:00 2001
From: pans <pans@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期五, 13 一月 2017 14:32:30 +0800
Subject: [PATCH] 

---
 RtspFace/SensetimeFaceAPIWrapper/src/faceAPI.cpp |   99 ++++++++++++++++++++++++++++++++-----------------
 1 files changed, 64 insertions(+), 35 deletions(-)

diff --git a/RtspFace/SensetimeFaceAPIWrapper/src/faceAPI.cpp b/RtspFace/SensetimeFaceAPIWrapper/src/faceAPI.cpp
index 2c61cff..bd26a51 100644
--- a/RtspFace/SensetimeFaceAPIWrapper/src/faceAPI.cpp
+++ b/RtspFace/SensetimeFaceAPIWrapper/src/faceAPI.cpp
@@ -21,14 +21,17 @@
 //@return 浜鸿劯id
 int FaceAPI::do_reasch(cv::Mat image)
 {
-	if (!image.data) {
+	if (!image.data)
+	{
 		fprintf(stderr, "fail to read img\n");
 		return -1;
-	} else
+	}
+	else
 		fprintf(stderr, "read img\n");
 	p_f = fdb->extract_feature(image);
 	fprintf(stderr, "fdb->extract_feature(image)\n");
-	if (!p_f) {
+	if (!p_f)
+	{
 		fprintf(stderr, "p_f is null\n");
 		return -2;
 	}
@@ -51,7 +54,7 @@
 {
 	p_f = fdb->extract_feature(image);
 	int indx = fdb->db_add(p_f);
-	if(fdb->db_save())
+	if(fdb->finally())
 		return indx;
 	return -2;
 }
@@ -84,9 +87,11 @@
 {
 
 	p_feature = cv_verify_deserialize_feature(feature_str);
-	if(p_feature != NULL) {
+	if(p_feature != NULL)
+	{
 		return 0;
-	} else
+	}
+	else
 		return -1;
 }
 
@@ -95,7 +100,7 @@
 //char *db_path = "out.db";
 FaceDB::FaceDB()
 {
-	
+
 }
 
 FaceDB::~FaceDB() {}
@@ -103,21 +108,21 @@
 //鍒濆鍖栬缃�
 bool FaceDB::init(char* db_path_t)
 {
-	
+
 	db_path = db_path_t;
-	
+
 	//鍔犺浇涓�娆″彲澶氭浣跨敤銆�
 	cv_verify_create_handle(&handle_verify, "../models/verify.model");
 	fprintf(stderr, "create cv_verify_create_handle\n");
 	cv_face_create_detector(&handle_detect, NULL, CV_DETECT_ENABLE_ALIGN_21);
 	fprintf(stderr, "create cv_face_create_detector\n");
-	
-	
+
+
 	// 鍒涘缓浜鸿劯鏁版嵁搴撳彞鏌勶紝鍦╠b_save()涓紝鏁版嵁搴撲繚瀛樻垚鍔燂紝浼氶噴鏀捐鍙ユ焺
 	cv_verify_create_db(&handle_db);
 	fprintf(stderr, "create cv_verify_create_db\n");
-	
-	
+
+
 	if(db_load())
 	{
 		fprintf(stderr, "db load\n");
@@ -134,11 +139,11 @@
 	{
 		return true;
 	}
-	
+
 	return false;
-	
+
 }
-	
+
 //@brief 鏁版嵁搴撴坊鍔犳暟鎹�
 //@param 鐗瑰緛鍊�
 //@return 浜鸿劯id锛屾坊鍔犲け璐ヨ繑鍥�-1
@@ -146,7 +151,8 @@
 {
 	int idx;
 	cv_result_t cv_result = cv_verify_add_face(handle_db, p_feature, &idx);
-	if (cv_result != CV_OK) {
+	if (cv_result != CV_OK)
+	{
 		fprintf(stderr, "cv_verify_add_face failed, error code %d\n", cv_result);
 		return -1;
 	}
@@ -160,10 +166,13 @@
 bool FaceDB::db_save()
 {
 	cv_result = cv_verify_save_db(handle_db, db_path);
-	if (cv_result != CV_OK) {
+	if (cv_result != CV_OK)
+	{
 		fprintf(stderr, "cv_verify_save_db failed, error code %d\n", cv_result);
 		return false;
-	} else {
+	}
+	else
+	{
 		fprintf(stderr, "save done!\n");
 	}
 	cv_verify_destroy_db(handle_db);
@@ -174,16 +183,22 @@
 //@return 鐘舵�侀噺
 bool FaceDB::db_load()
 {
-	if (handle_db != NULL) {
+	if (handle_db != NULL)
+	{
 		fprintf(stderr, "handle_db is not null!%s\n",db_path);
-	} else {
+	}
+	else
+	{
 		fprintf(stderr, "handle_db is null!%s\n",db_path);
 	}
 	cv_result = cv_verify_load_db(handle_db, db_path);
-	if (cv_result != CV_OK) {
+	if (cv_result != CV_OK)
+	{
 		fprintf(stderr, "cv_verify_load_db failed, error code %d\n", cv_result);
 		return false;
-	} else {
+	}
+	else
+	{
 		fprintf(stderr, "load done!\n");
 	}
 
@@ -206,25 +221,32 @@
 	                                  top_idxs, top_scores, &result_length);
 
 
-	if (cv_result == CV_OK) {
+	if (cv_result == CV_OK)
+	{
 		//杈撳嚭妫�鏌ョ粨鏋�
-		for (unsigned int t = 0; t < result_length; t++) {
+		for (unsigned int t = 0; t < result_length; t++)
+		{
 			// const cv_feature_t item = result[t].item;
 			fprintf(stderr, "%d\t", top_idxs[t]);
 			fprintf(stderr, "%0.2f\n", top_scores[t]);
 		}
-	} else {
+	}
+	else
+	{
 		fprintf(stderr, "cv_verify_search_face failed, error code %d\n", cv_result);
 	}
 	std::cout<<"this is hits"<<std::endl;
-	if (top_scores[0] != 0) {
+	if (top_scores[0] != 0)
+	{
 		indx=top_idxs[0];
 		std::cout<<"indx="<<indx<<std::endl;
 	}
-	if (top_idxs) {
+	if (top_idxs)
+	{
 		delete[]top_idxs;
 	}
-	if (top_scores) {
+	if (top_scores)
+	{
 		delete[]top_scores;
 	}
 	cv_verify_release_feature(p_feature);
@@ -237,30 +259,37 @@
 //@return 鐗瑰緛鍊�
 cv_feature_t* FaceDB::extract_feature(cv::Mat image_color)
 {
-	if (handle_verify != NULL) {
+	if (handle_verify != NULL)
+	{
 		fprintf(stderr, "fdb.handle_verify is not null!\n");
-	} else {
+	}
+	else
+	{
 		fprintf(stderr, "fdb.handle_verify is null!\n");
 	}
 
 	//璇ュ彉閲忓唴瀛樹細鍦╠b_add()涓紝娣诲姞鎴愬姛鍚庨噴鏀俱��
 	cv_feature_t *p_feature = NULL;
-	
+
 	cv_face_t *p_face = NULL;
 	int face_count = 0;
 	cv_result_t st_result = CV_OK;
 	st_result = cv_face_detect(handle_detect, image_color.data, CV_PIX_FMT_BGR888,
 	                           image_color.cols, image_color.rows, image_color.step,
 	                           CV_FACE_UP, &p_face, &face_count);
-	if (face_count >= 1) {
+	if (face_count >= 1)
+	{
 		st_result = cv_verify_get_feature(handle_verify,
 		                                  (unsigned char *)image_color.data, CV_PIX_FMT_BGR888,
 		                                  image_color.cols, image_color.rows, image_color.step,
 		                                  p_face, &p_feature, NULL);
-		if (st_result != CV_OK) {
+		if (st_result != CV_OK)
+		{
 			fprintf(stderr, "cv_verify_get_feature failed, error code %d\n", st_result);
 		}
-	} else {
+	}
+	else
+	{
 		fprintf(stderr, "can't find face in ");
 	}
 	// release the memory of face

--
Gitblit v1.8.0