git-svn-id: http://192.168.1.226/svn/proxy@76 454eff88-639b-444f-9e54-f578c98de674
| | |
| | | mysql_close(&myCont);
|
| | | }
|
| | |
|
| | | *person DBuntil::db_rearch(int f_id)
|
| | | bool DBuntil::db_search(person* per)
|
| | | {
|
| | | person p= {0,""};
|
| | | db_select(f_id,&p);
|
| | | //对结构体赋值
|
| | | return &p;
|
| | | std::cout<<"db_search start"<<std::endl;
|
| | | if(db_select(per))
|
| | | {
|
| | |
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | bool DBuntil::db_select(int f_id,person* per)
|
| | | bool DBuntil::db_select(person* per)
|
| | | {
|
| | |
|
| | | sprintf( sql, "select a.p_id,b.`name`,b.img from face_person a,user_info b where a.face_id = %d AND a.p_id = b.pid " , f_id );
|
| | | std::cout<<"db_select start"<<std::endl;
|
| | | sprintf( sql, "select a.p_id,b.`name`,b.img from face_person a,user_info b where a.face_id = %d AND a.p_id = b.pid " ,per->f_id );
|
| | |
|
| | | mysql_query(&myCont, "SET NAMES utf8"); //设置编码格式
|
| | | res = mysql_query(&myCont,sql);//查询
|
| | |
| | | return true;
|
| | | }
|
| | |
|
| | | bool DBuntil::db_add(int f_id,person *per)
|
| | | bool DBuntil::db_add(person *per)
|
| | | {
|
| | | //
|
| | | sprintf( sql, "INSERT INTO user_info(NAME, img) VALUES('%s', NULL)" , per->name );
|
| | | res = mysql_query(&myCont,sql);
|
| | | if(!res)
|
| | | {
|
| | | sprintf( sql, "INSERT INTO face_person(p_id, face_id) VALUES (LAST_INSERT_ID(), %d)" , f_id );
|
| | | sprintf( sql, "INSERT INTO face_person(p_id, face_id) VALUES (LAST_INSERT_ID(), %d)" , per->f_id );
|
| | | res = mysql_query(&myCont,sql);
|
| | | if(!res)
|
| | | {
|
| | |
| | | return false;
|
| | | }
|
| | |
|
| | | bool DBuntil::db_register(int f_id,person *per)
|
| | | bool DBuntil::db_register(person *per)
|
| | | {
|
| | | if(db_add(f_id,per)){
|
| | | if(db_add(per))
|
| | | {
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | |
| | | DBuntil();
|
| | | DBuntil(my_db mydb);
|
| | | ~DBuntil();
|
| | | *person db_rearch(int f_id);
|
| | |
|
| | | bool db_register(int f_id,person *p);
|
| | | bool db_search(person *p);
|
| | | bool db_register(person *p);
|
| | |
|
| | | private:
|
| | |
|
| | | bool db_add(int f_id,person *per);
|
| | | bool db_add(person *per);
|
| | | int db_update();
|
| | | bool db_select(int f_id,person *per);
|
| | | bool db_select(person *per);
|
| | |
|
| | | char sql[1024];
|
| | | int res;
|
| | | };
|
| | |
|
| | |
|
| | | #endif |
| | |
| | | #!/bin/bash |
| | | LD_LIBRARY_PATH=../libs/lib_dummy ./demo |
| | | LD_LIBRARY_PATH=../libs/lib_dummy ./demo ../test_img/face_01.jpg |
| | |
| | |
|
| | | int idx = -11;
|
| | | tools tool=tools();
|
| | | idx=tool->reg(bgr_image,p);
|
| | | cout<<"idx="<<idx<<endl;
|
| | | //idx=tool.reg(bgr_image,&p);
|
| | | tool.search(bgr_image,&p);
|
| | | cout<<"p_id="<<p.p_id<<endl;
|
| | | cout<<"name="<<p.name<<endl;
|
| | | cout<<"f_id="<<p.f_id<<endl;
|
| | |
|
| | |
|
| | | return 0;
|
| | |
| | | #include "tools.h" |
| | | |
| | | tools::tools() { |
| | | tools::tools() |
| | | { |
| | | my_db mydb={"root","Basic@2017","localhost","demo",3306}; |
| | | |
| | | dbu = DBuntil(mydb); |
| | |
| | | |
| | | int tools::search(cv::Mat image,person *p) |
| | | { |
| | | idx = f_api.do_reasch(image); |
| | | if(idx<0) |
| | | p={}; |
| | | p->f_id = f_api.do_reasch(image); |
| | | if(p->f_id < 0) |
| | | { |
| | | p = dbu.db_rearch(idx); |
| | | if(p != NULL) |
| | | if(do_search(p) == 0) |
| | | { |
| | | return 0; |
| | | } |
| | |
| | | |
| | | int tools::search(char* s_feature,person *p) |
| | | { |
| | | idx = f_api.do_reasch(s_feature); |
| | | if(idx<0) |
| | | p={}; |
| | | p->f_id = f_api.do_reasch(s_feature); |
| | | if(p->f_id < 0) |
| | | { |
| | | p = dbu.db_rearch(idx); |
| | | if(p != NULL) |
| | | if(do_search(p) == 0) |
| | | { |
| | | return 0; |
| | | } |
| | |
| | | |
| | | int tools::reg(cv::Mat image,person *p) |
| | | { |
| | | if(do_register(image,p) == 0){ |
| | | if(do_register(image,p) == 0) |
| | | { |
| | | return 0; |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | person tools::do_search(int idx) |
| | | int tools::do_search(person *p) |
| | | { |
| | | person p; |
| | | p = dbu.db_rearch(idx); |
| | | return p; |
| | | dbu.db_search(p); |
| | | if(p->p_id != NULL) |
| | | { |
| | | return 0; |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | int tools::do_register(cv::Mat image,person *p) |
| | | { |
| | | idx = f_api.do_register(image); |
| | | if(idx<0) |
| | | p={}; |
| | | p->f_id = f_api.do_register(image); |
| | | if(p->f_id < 0) |
| | | { |
| | | p->f_id = idx; |
| | | if(dbu.db_register(idx,p)) |
| | | if(dbu.db_register(p)) |
| | | { |
| | | return 0; |
| | | } |
| | |
| | | int reg(cv::Mat image,person *p); |
| | | private: |
| | | int do_register(cv::Mat image,person *p); |
| | | person do_search(int idx); |
| | | int idx; |
| | | int do_search(person *p); |
| | | person per; |
| | | DBuntil dbu; |
| | | faceAPI f_api; |
| | | }; |