git-svn-id: http://192.168.1.226/svn/proxy@40 454eff88-639b-444f-9e54-f578c98de674
| | |
| | | |
| | | main.o : test.cpp |
| | | $(CXX) $(CXXFLAGS) $(LDFLAGS) -c test.cpp -o main.o |
| | | faceAPI.o : faceAPI.cpp |
| | | faceAPI.o : faceAPI.h |
| | | $(CXX) $(CXXFLAGS) $(LDFLAGS) -c faceAPI.cpp -o faceAPI.o |
| | | faceDB.o : faceDB.cpp |
| | | $(CXX) $(CXXFLAGS) $(LDFLAGS) -c faceDB.cpp -o faceDB.o |
| | |
| | | #include "faceAPI.h"
|
| | | #include "faceAPI.h"
|
| | | #include "faceDB.h"
|
| | |
|
| | | faceDB fdb = faceDB();
|
| | | faceDB *fdb;
|
| | | faceAPI::faceAPI(){
|
| | | //创建静态人脸识别句柄,同时创建状态标量
|
| | | //创建静态人脸识别句柄,同时创建状态标量
|
| | | cv_result_t cv_result = 0;
|
| | | cv_face_create_detector(&handle_detect, NULL, CV_DETECT_ENABLE_ALIGN_21);
|
| | | cv_verify_create_handle(&handle_verify1, "verify.model");
|
| | | |
| | | //cv_verify_create_handle(&handle_verify1, "verify.model");
|
| | | //faceDB* f_db = faceDB.GetInstance();
|
| | | fdb=new faceDB();
|
| | | }
|
| | |
|
| | | faceAPI::~faceAPI(){
|
| | |
| | | }
|
| | |
|
| | | int faceAPI::do_reasch(cv::Mat image){
|
| | | if (!image.data) { |
| | | fprintf(stderr, "fail to read img\n"); |
| | | return -1; |
| | | if (!image.data) {
|
| | | fprintf(stderr, "fail to read img\n");
|
| | | return -1;
|
| | | }else
|
| | | fprintf(stderr, "read img\n");
|
| | | p_f = extract_feature(image);
|
| | | p_f = fdb->extract_feature(image);
|
| | | if (!p_f)
|
| | | {
|
| | | fprintf(stderr, "p_f is null\n");
|
| | |
| | | }
|
| | |
|
| | | int faceAPI::do_register(cv::Mat image){
|
| | | p_f = extract_feature(image);
|
| | | p_f = fdb->extract_feature(image);
|
| | | //db add
|
| | | int indx = 1;
|
| | | return indx;
|
| | |
| | | int faceAPI::p_img_search(cv_feature_t *p_feature){
|
| | | std::cout<<"p img search"<<std::endl;
|
| | |
|
| | | return fdb.search_db(p_feature);
|
| | | return fdb->search_db(p_feature);
|
| | | }
|
| | |
|
| | | cv_feature_t* faceAPI::extract_feature(const cv::Mat image_color) { |
| | | |
| | | if (handle_verify1 != NULL)
|
| | | {
|
| | | fprintf(stderr, "handle_verify1 is not null!\n");
|
| | | } |
| | | else
|
| | | {
|
| | | fprintf(stderr, "handle_verify1 is null!\n");
|
| | | } |
| | | |
| | | 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) { |
| | | st_result = cv_verify_get_feature(handle_verify1, |
| | | (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) { |
| | | fprintf(stderr, "cv_verify_get_feature failed, error code %d\n", st_result); |
| | | } |
| | | } else { |
| | | fprintf(stderr, "can't find face in "); |
| | | } |
| | | // release the memory of face |
| | | cv_face_release_detector_result(p_face, face_count); |
| | | return p_feature; |
| | | }
|
| | |
|
| | |
|
| | | //@brief 特征值转换为字符串
|
| | | //@param 特征值
|
| | | //@return 字符串格式的特征值
|
| | | //@brief 特征值转换为字符串
|
| | | //@param 特征值
|
| | | //@return 字符串格式的特征值
|
| | | int faceAPI::get_char(cv_feature_t *p_feature,char* feature_str){
|
| | |
|
| | | return cv_verify_serialize_feature(p_feature,feature_str);
|
| | | }
|
| | |
|
| | | //@brief 字符串转换为特征值
|
| | | //@param 字符串格式的特征值
|
| | | //@return 特征值
|
| | | //@brief 字符串转换为特征值
|
| | | //@param 字符串格式的特征值
|
| | | //@return 特征值
|
| | | int faceAPI::get_feature(char *feature_str,cv_feature_t *p_feature){
|
| | |
|
| | | p_feature = cv_verify_deserialize_feature(feature_str);
|
| | |
| | | #include <cv_face.h>
|
| | | #include "time_helper.h"
|
| | |
|
| | | //静态人脸识别
|
| | | static cv_handle_t handle_detect = NULL;
|
| | | //人脸验证
|
| | | static cv_handle_t handle_verify1 = NULL;
|
| | |
|
| | |
|
| | | class faceAPI
|
| | | {
|
| | |
| | | //调用搜索
|
| | | int p_img_search(cv_feature_t *p_feature);
|
| | |
|
| | | //提取特征值
|
| | | cv_feature_t *extract_feature(cv::Mat image_color);
|
| | | |
| | |
|
| | | //转换函数
|
| | | int get_char(cv_feature_t *p_feature,char* feature_str);
|
| | |
| | | // 创建人脸数据库句柄
|
| | | cv_verify_create_db(&handle_db);
|
| | | cv_verify_create_handle(&handle_verify, "verify.model");
|
| | | cv_face_create_detector(&handle_detect, NULL, CV_DETECT_ENABLE_ALIGN_21);
|
| | | db_load();
|
| | | }
|
| | |
|
| | |
| | | }*/
|
| | |
|
| | | //数据库添加数据,并返回记录得id
|
| | | int faceDB::db_add(cv_feature_t* p_feature) { |
| | | int idx; |
| | | cv_result_t cv_result = cv_verify_add_face(handle_db, p_feature, &idx); |
| | | if (cv_result != CV_OK) { |
| | | fprintf(stderr, "cv_verify_add_face failed, error code %d\n", cv_result); |
| | | } |
| | | cv_verify_release_feature(p_feature); |
| | | int faceDB::db_add(cv_feature_t* p_feature) {
|
| | | int idx;
|
| | | cv_result_t cv_result = cv_verify_add_face(handle_db, p_feature, &idx);
|
| | | if (cv_result != CV_OK) {
|
| | | fprintf(stderr, "cv_verify_add_face failed, error code %d\n", cv_result);
|
| | | }
|
| | | cv_verify_release_feature(p_feature);
|
| | | return idx;
|
| | | }
|
| | |
|
| | |
|
| | | //数据库保存
|
| | | bool faceDB::db_save() {
|
| | | cv_result = cv_verify_save_db(handle_db, db_path); |
| | | if (cv_result != CV_OK) { |
| | | fprintf(stderr, "cv_verify_save_db failed, error code %d\n", cv_result); |
| | | return false; |
| | | } |
| | | else { |
| | | fprintf(stderr, "save done!\n"); |
| | | } |
| | | |
| | | cv_result = cv_verify_save_db(handle_db, db_path);
|
| | | if (cv_result != CV_OK) {
|
| | | fprintf(stderr, "cv_verify_save_db failed, error code %d\n", cv_result);
|
| | | return false;
|
| | | }
|
| | | else {
|
| | | fprintf(stderr, "save done!\n");
|
| | | }
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | 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) { |
| | | fprintf(stderr, "cv_verify_load_db failed, error code %d\n", cv_result); |
| | | return false; |
| | | } |
| | | else { |
| | | fprintf(stderr, "load done!\n"); |
| | | } |
| | | |
| | | cv_result = cv_verify_load_db(handle_db, db_path);
|
| | | if (cv_result != CV_OK) {
|
| | | fprintf(stderr, "cv_verify_load_db failed, error code %d\n", cv_result);
|
| | | return false;
|
| | | }
|
| | | else {
|
| | | fprintf(stderr, "load done!\n");
|
| | | }
|
| | |
|
| | | return true;
|
| | | }
|
| | |
|
| | |
| | | } else {
|
| | | fprintf(stderr, "cv_verify_search_face failed, error code %d\n", cv_result);
|
| | | }
|
| | | indx=top_idxs[0];
|
| | | if (top_scores[0] != 0)
|
| | | {
|
| | | indx=top_idxs[0];
|
| | | }
|
| | | if (top_idxs) {
|
| | | delete[]top_idxs;
|
| | | }
|
| | |
| | | }
|
| | | cv_verify_release_feature(p_feature);
|
| | | return indx;
|
| | | }
|
| | |
|
| | | cv_feature_t* faceDB::extract_feature(cv::Mat image_color) {
|
| | |
|
| | | if (handle_verify != NULL)
|
| | | {
|
| | | fprintf(stderr, "fdb.handle_verify is not null!\n");
|
| | | } |
| | | else
|
| | | {
|
| | | fprintf(stderr, "fdb.handle_verify is null!\n");
|
| | | }
|
| | |
|
| | | 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) {
|
| | | 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) {
|
| | | fprintf(stderr, "cv_verify_get_feature failed, error code %d\n", st_result);
|
| | | }
|
| | | } else {
|
| | | fprintf(stderr, "can't find face in ");
|
| | | }
|
| | | // release the memory of face
|
| | | cv_face_release_detector_result(p_face, face_count);
|
| | | return p_feature;
|
| | | } |
| | |
| | |
|
| | | #include <cv_face.h>
|
| | | #include "time_helper.h"
|
| | | #include <opencv2/opencv.hpp>
|
| | |
|
| | | //人脸验证
|
| | | static cv_handle_t handle_verify = NULL;
|
| | | static cv_handle_t handle_verify;
|
| | | //数据库操作
|
| | | static cv_handle_t handle_db = NULL;
|
| | | static cv_handle_t handle_db;
|
| | | //静态人脸识别
|
| | | static cv_handle_t handle_detect;
|
| | |
|
| | | class faceDB{
|
| | | public:
|
| | |
| | |
|
| | | faceDB();
|
| | | virtual ~faceDB();
|
| | | //提取特征值
|
| | | cv_feature_t *extract_feature(cv::Mat image_color);
|
| | |
|
| | | |
| | | private:
|
| | |
|
| | | cv_result_t cv_result;
|