git-svn-id: http://192.168.1.226/svn/proxy@93 454eff88-639b-444f-9e54-f578c98de674
| | |
| | | {
|
| | | if (result != NULL)
|
| | | mysql_free_result(result);
|
| | |
|
| | | mysql_close(&myCont);
|
| | | }
|
| | |
|
| | |
| | | else
|
| | | {
|
| | | std::cout<<"mysql_real_connect failed"<<std::endl;
|
| | | std::cout<<"db_init(my_db mydb) end"<<std::endl;
|
| | | return false;
|
| | | }
|
| | | std::cout<<"db_init(my_db mydb) end"<<std::endl;
|
| | | return false;
|
| | |
|
| | | }
|
| | |
|
| | | bool DBuntil::db_search(person* per)
|
| | | {
|
| | | std::cout<<"db_search start"<<std::endl;
|
| | | //db_init()
|
| | | if(db_select(per))
|
| | | {
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | else
|
| | | return false;
|
| | | }
|
| | |
|
| | | bool DBuntil::db_select(person* per)
|
| | |
| | | std::cout<<"per->f_id="<<per->f_id<<std::endl;
|
| | | std::cout<<sql<<std::endl;
|
| | | std::cout<<"==========end=============="<<std::endl;
|
| | | if(!mysql_query(&myCont, "SET NAMES utf8"))//设置编码格式
|
| | | {
|
| | | std::cout<<"SET NAMES utf8"<<std::endl;
|
| | | }
|
| | | else
|
| | | std::cout<<"SET NAMES utf8 failed"<<std::endl;
|
| | | mysql_query(&myCont, "SET NAMES utf8");//设置编码格式
|
| | |
|
| | | res = mysql_query(&myCont,sql);//查询
|
| | | if (!res)
|
| | | {
|
| | |
| | | {
|
| | | return true;
|
| | | }
|
| | | else
|
| | | {}
|
| | | }
|
| | | else
|
| | | {}
|
| | | return false;
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | else
|
| | | return false;
|
| | | } |
| | |
| | |
|
| | | class DBuntil
|
| | | {
|
| | |
|
| | | public:
|
| | | DBuntil();
|
| | | ~DBuntil();
|
| | |
| | | bool db_search(person *p);
|
| | | bool db_register(person *p);
|
| | | bool db_init(my_db mydb);
|
| | | |
| | |
|
| | | MYSQL myCont;
|
| | | MYSQL_RES *result;
|
| | | MYSQL_ROW sql_row;
|
| | | private:
|
| | |
|
| | | bool db_add(person *per);
|
| | | int db_update();
|
| | | bool db_select(person *per);
|
| | | char sql[1024];
|
| | | int res;
|
| | |
|
| | | };
|
| | |
|
| | | #endif |
| | |
| | | #include "faceAPI.h"
|
| | | #include <iostream>
|
| | |
|
| | | FaceDB *fdb;
|
| | |
|
| | | FaceAPI::FaceAPI()
|
| | | {
|
| | | //创建静态人脸识别句柄,同时创建状态标量
|
| | |
| | |
|
| | | }
|
| | |
|
| | | int FaceAPI::do_init(char* db_path)
|
| | | {
|
| | | return fdb->init(db_path);
|
| | | }
|
| | |
|
| | | //@brief 搜索功能
|
| | | //@param 图片
|
| | | //@return 人脸id
|
| | |
| | | public:
|
| | | FaceAPI();
|
| | | ~FaceAPI();
|
| | | int do_init(char* db_path);
|
| | | //查询 前台调用
|
| | | int do_reasch(char* s_feature);
|
| | | int do_reasch(cv::Mat image);
|
| | |
| | | //转换函数
|
| | | int get_char(cv_feature_t *p_feature,char* feature_str);
|
| | | int get_feature(char *feature_str,cv_feature_t *p_feature);
|
| | |
|
| | | FaceDB *fdb;
|
| | | cv_feature_t* p_f;
|
| | | };
|
| | |
|
| | |
| | | #include <stdio.h>
|
| | |
|
| | | #include "faceAPI.h"
|
| | | #include "tools.h"
|
| | |
|
| | | using namespace std;
|
| | |
|
| | |
| | | char *db_path = "./out.db";
|
| | | char *image_path = argv[1];
|
| | | char *image_list = "../test_image/imglist";
|
| | | |
| | | |
| | | my_db mydb= {"root","Basic@2017","localhost","demo",3306};
|
| | |
|
| | | // person p={0,"axsdcc",1};
|
| | | |
| | |
|
| | | cv::Mat bgr_image = cv::imread(image_path);
|
| | | if(bgr_image.data != NULL) {
|
| | | if(bgr_image.data != NULL)
|
| | | {
|
| | | cout<<image_path<<endl;
|
| | | } else {
|
| | | }
|
| | | else
|
| | | {
|
| | | cout<<"image is null"<<endl;
|
| | | cout<<image_path<<endl;
|
| | | }
|
| | | |
| | | FaceDB db =FaceDB();
|
| | | db.init(db_path);
|
| | | int id = db.search_db(db.extract_feature(bgr_image));
|
| | | // int idx = -11;
|
| | | // tools tool=tools();
|
| | | // tool.init();
|
| | | // cout<<"======tools init ==========="<<endl;
|
| | |
|
| | | // FaceDB db =FaceDB();
|
| | | // db.init(db_path);
|
| | | // int id = db.search_db(db.extract_feature(bgr_image));
|
| | | int idx = -11;
|
| | | tools tool=tools();
|
| | | tool.init(mydb,db_path);
|
| | | cout<<"======tools init ==========="<<endl;
|
| | | //idx=tool.reg(bgr_image,&p);
|
| | | // tool.search(bgr_image,&p);
|
| | | tool.search(bgr_image,&p);
|
| | | cout<<"id="<<id<<endl;
|
| | | cout<<"============================================"<<endl;
|
| | | // cout<<"p_id="<<p.p_id<<endl;
|
| | | // cout<<"name="<<p.name<<endl;
|
| | | // cout<<"f_id="<<p.f_id<<endl;
|
| | | |
| | | |
| | | cout<<"p_id="<<p.p_id<<endl;
|
| | | cout<<"name="<<p.name<<endl;
|
| | | cout<<"f_id="<<p.f_id<<endl;
|
| | |
|
| | |
|
| | | return 0;
|
| | | }
|
| | |
| | | |
| | | tools::~tools() {} |
| | | |
| | | bool tools::init(){ |
| | | my_db mydb= {"root","Basic@2017","localhost","demo",3306}; |
| | | //DBuntil dbu =DBuntil(); |
| | | return dbu.db_init(mydb); |
| | | bool tools::init(my_db mydb,char* db_path_t) |
| | | { |
| | | |
| | | //my_db mydb= {"root","Basic@2017","localhost","demo",3306}; |
| | | if(dbu.db_init(mydb)) |
| | | { |
| | | db_path = db_path_t; |
| | | return true; |
| | | } |
| | | else |
| | | return false; |
| | | } |
| | | |
| | | int tools::search(cv::Mat image,person *p) |
| | | { |
| | | //p={}; |
| | | int temp = f_api.do_reasch(image); |
| | | std::cout<<"temp="<<temp<<std::endl; |
| | | p->f_id = temp; |
| | | std::cout<<"p->f_id"<<p->f_id<<std::endl; |
| | | |
| | | if(p->f_id > 0) |
| | | { |
| | | if(do_search(p) == 0) |
| | |
| | | |
| | | int tools::do_search(person *p) |
| | | { |
| | | //if(dbu.myCont == NULL){ |
| | | // std::cout<<"myCont is null"<<std::endl; |
| | | //} |
| | | |
| | | dbu.db_search(p); |
| | | if(p->p_id != NULL) |
| | | { |
| | |
| | | public: |
| | | tools(); |
| | | ~tools(); |
| | | bool init(my_db mydb,char* db_path); |
| | | int search(cv::Mat image,person *p); |
| | | int search(char* s_feature,person *p); |
| | | int reg(cv::Mat image,person *p); |
| | |
| | | private: |
| | | int do_register(cv::Mat image,person *p); |
| | | int do_search(person *p); |
| | | |
| | | char* db_path; |
| | | person per; |
| | | DBuntil dbu; |
| | | faceAPI f_api; |