| | |
| | | //"./out1.db"
|
| | | char *db_path = "out.db";
|
| | |
|
| | | faceDB::faceDB(){
|
| | | faceDB::faceDB()
|
| | | {
|
| | | // 创建人脸数据库句柄
|
| | | cv_verify_create_db(&handle_db);
|
| | | fprintf(stderr, "create cv_verify_create_db\n");
|
| | |
| | | fprintf(stderr, "db load\n");
|
| | | }
|
| | |
|
| | | faceDB::~faceDB(){}
|
| | | faceDB::~faceDB() {}
|
| | |
|
| | | /*
|
| | | faceDB* faceDB::GetInstance(){
|
| | | if (db == NULL)
|
| | | {
|
| | | db = new faceDB();
|
| | | } |
| | | }
|
| | |
|
| | | return db;
|
| | | }*/
|
| | |
|
| | | //数据库添加数据,并返回记录得id
|
| | | int faceDB::db_add(cv_feature_t* 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) {
|
| | |
| | |
|
| | |
|
| | | //数据库保存
|
| | | bool faceDB::db_save() {
|
| | | 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 {
|
| | | } else {
|
| | | fprintf(stderr, "save done!\n");
|
| | | }
|
| | |
|
| | |
| | | }
|
| | |
|
| | | //数据库加载
|
| | | bool faceDB::db_load() {
|
| | | if (handle_db != NULL)
|
| | | {
|
| | | bool faceDB::db_load()
|
| | | {
|
| | | 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) {
|
| | | fprintf(stderr, "cv_verify_load_db failed, error code %d\n", cv_result);
|
| | | return false;
|
| | | }
|
| | | else {
|
| | | } else {
|
| | | fprintf(stderr, "load done!\n");
|
| | | }
|
| | |
|
| | |
| | | }
|
| | |
|
| | | //搜索数据库
|
| | | int faceDB::search_db(cv_feature_t *p_feature) {
|
| | | int faceDB::search_db(cv_feature_t *p_feature)
|
| | | {
|
| | |
|
| | | |
| | |
|
| | | int indx=-1;
|
| | | //查询前10条
|
| | | int top_k = 3;
|
| | |
| | | float *top_scores = new float[top_k];
|
| | | unsigned int result_length = 0;
|
| | | cv_result = cv_verify_search_face(handle_verify, handle_db,
|
| | | p_feature, top_k,
|
| | | top_idxs, top_scores, &result_length);
|
| | | p_feature, top_k,
|
| | | top_idxs, top_scores, &result_length);
|
| | |
|
| | |
|
| | | if (cv_result == CV_OK) {
|
| | |
| | | } else {
|
| | | fprintf(stderr, "cv_verify_search_face failed, error code %d\n", cv_result);
|
| | | }
|
| | | if (top_scores[0] != 0)
|
| | | {
|
| | | if (top_scores[0] != 0) {
|
| | | indx=top_idxs[0];
|
| | | }
|
| | | if (top_idxs) {
|
| | |
| | | return indx;
|
| | | }
|
| | |
|
| | | cv_feature_t* faceDB::extract_feature(cv::Mat image_color) {
|
| | | 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");
|
| | | }
|
| | |
|
| | |
| | | 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);
|
| | | 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);
|
| | | (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);
|
| | | }
|