git-svn-id: http://192.168.1.226/svn/proxy@73 454eff88-639b-444f-9e54-f578c98de674
New file |
| | |
| | | #include "DBuntil.h"
|
| | | #include <mysql.h>
|
| | | #include <cstdio>
|
| | | #include <iostream>
|
| | |
|
| | |
|
| | | MYSQL myCont;
|
| | | MYSQL_RES *result;
|
| | | MYSQL_ROW sql_row;
|
| | |
|
| | | DBuntil::DBuntil(){}
|
| | |
|
| | | DBuntil::DBuntil(my_db mydb)
|
| | | {
|
| | | if(mysql_init(&myCont)!=NULL)
|
| | | {
|
| | | std::cout<<"init succeed"<<std::endl;
|
| | | }
|
| | | else
|
| | | std::cout<<"init failed"<<std::endl;
|
| | |
|
| | | if(mysql_real_connect(&myCont, mydb.host, mydb.user, mydb.pswd, mydb.db, mydb.port, NULL, 0) != NULL)
|
| | | {
|
| | | std::cout<<"mysql_real_connect succeed"<<std::endl;
|
| | | }
|
| | | else
|
| | | std::cout<<"mysql_real_connect failed"<<std::endl;
|
| | | }
|
| | |
|
| | | DBuntil::~DBuntil()
|
| | | {
|
| | | if (result != NULL)
|
| | | mysql_free_result(result);
|
| | |
|
| | | mysql_close(&myCont);
|
| | | }
|
| | |
|
| | | person DBuntil::db_rearch(int f_id)
|
| | | {
|
| | | person p= {0,""};
|
| | | db_select(f_id,&p);
|
| | | //对结构体赋值
|
| | | return p;
|
| | | }
|
| | |
|
| | | bool DBuntil::db_select(int f_id,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 );
|
| | |
|
| | | mysql_query(&myCont, "SET NAMES utf8"); //设置编码格式
|
| | | res = mysql_query(&myCont,sql);//查询
|
| | | if (!res)
|
| | | {
|
| | | result = mysql_store_result(&myCont);
|
| | | if (result)
|
| | | {
|
| | | while (sql_row = mysql_fetch_row(result))
|
| | | {
|
| | | //获取具体的数据
|
| | | per->p_id = atoi( sql_row[0]);
|
| | | per->name = sql_row[1];
|
| | | }
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | std::cout<<"query sql failed!"<<std::endl;
|
| | | return false;
|
| | | }
|
| | | return true;
|
| | | }
|
| | |
|
| | | bool DBuntil::db_add(int f_id,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 );
|
| | | res = mysql_query(&myCont,sql);
|
| | | if(!res)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | bool DBuntil::db_register(int f_id,person *per)
|
| | | {
|
| | | if(db_add(f_id,per)){
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | } |
New file |
| | |
| | | #ifndef _DBUNTIL_H_
|
| | | #define _DBUNTIL_H_
|
| | |
|
| | | struct person {
|
| | | int p_id;
|
| | | char *name;
|
| | | int f_id;
|
| | | //ͼƬ
|
| | | };
|
| | |
|
| | | struct my_db {
|
| | | char user[25];
|
| | | char pswd[25];
|
| | | char host[25];
|
| | | char db[25];
|
| | | unsigned int port;
|
| | | };
|
| | |
|
| | | class DBuntil
|
| | | {
|
| | |
|
| | | public:
|
| | | DBuntil();
|
| | | DBuntil(my_db mydb);
|
| | | ~DBuntil();
|
| | | person db_rearch(int f_id);
|
| | |
|
| | | bool db_register(int f_id,person *p);
|
| | |
|
| | | private:
|
| | |
|
| | | bool db_add(int f_id,person *per);
|
| | | int db_update();
|
| | | bool db_select(int f_id,person *per);
|
| | |
|
| | | char sql[1024];
|
| | | int res;
|
| | | };
|
| | |
|
| | |
|
| | | #endif |
| | |
| | | CXX=g++ |
| | | CXXFLAGS:=-I../include |
| | | CXXFLAGS+=/usr/include/mysql |
| | | CXXFLAGS+=$(shell pkg-config --cflags opencv) |
| | | |
| | | LDFLAGS+=-L../libs/lib_dummy |
| | | LDFLAGS+=-L../libs/lib_dummy /usr/lib64/mysql |
| | | |
| | | LIBS:=-lcvface_api -lpthread |
| | | LIBS:=-lcvface_api -lpthread -lmysqlclient |
| | | LIBS+=$(shell pkg-config --libs opencv) |
| | | |
| | | OBJ = faceDB.o faceAPI.o main.o |
| | | OBJ = faceAPI.o db.o tools.o main.o |
| | | |
| | | demo: $(OBJ) |
| | | $(CXX) $(CXXFLAGS) $(LDFLAGS) -o demo $(OBJ) $(LIBS) |
| | | main.o : test.cpp |
| | | $(CXX) $(CXXFLAGS) $(LDFLAGS) -c test.cpp -o main.o |
| | | tools.o : tools.h |
| | | $(CXX) $(CXXFLAGS) $(LDFLAGS) -c tools.cpp -o tools.o |
| | | db.o : DBuntil.h |
| | | $(CXX) $(CXXFLAGS) -o db.o -c DBuntil.cpp $(LDFLAGS) $(LIBS) |
| | | faceAPI.o : faceAPI.h |
| | | $(CXX) $(CXXFLAGS) $(LDFLAGS) -c faceAPI.cpp -o faceAPI.o |
| | | #faceDB.o : faceDB.cpp |
| | |
| | | return p;
|
| | | }
|
| | |
|
| | | int DBuntil::db_select(int f_id,person* per)
|
| | | bool DBuntil::db_select(int f_id,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 );
|
| | |
| | | #include <vector>
|
| | | #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";
|
| | | |
| | | |
| | | person p={0,"axsdcc"};
|
| | | |
| | | cv::Mat bgr_image = cv::imread(image_path);
|
| | | if(bgr_image.data != NULL) {
|
| | | cout<<image_path<<endl;
|
| | |
| | | cout<<"image is null"<<endl;
|
| | | cout<<image_path<<endl;
|
| | | }
|
| | | |
| | | int idx = -11;
|
| | | faceAPI face;
|
| | | idx = face.do_reasch(bgr_image);
|
| | | tools tool=tools();
|
| | | idx=tool->register(bgr_image,p);
|
| | | cout<<"idx="<<idx<<endl;
|
| | |
|
| | | |
| | | |
| | | return 0;
|
| | | }
|
| | |
| | | #include "tools.h" |
| | | |
| | | tools::tools() {} |
| | | tools::tools() { |
| | | my_db mydb={"root","Basic@2017","localhost","demo",3306}; |
| | | |
| | | dbu = DBuntil(mydb); |
| | | } |
| | | |
| | | tools::~tools() {} |
| | | |
| | |
| | | idx = f_api->do_reasch(image); |
| | | if(idx<0) |
| | | { |
| | | p = f_db->db_rearch(int); |
| | | p = dbu->db_rearch(int); |
| | | if(p != NULL) |
| | | { |
| | | return 0; |
| | |
| | | |
| | | int tools::register(cv::Mat image,person *p) |
| | | { |
| | | do_register(image,p); |
| | | if(do_register(image,p) == 0){ |
| | | return 0; |
| | | } |
| | | return -1; |
| | | } |
| | | |
| | | person tools::do_search(int idx) |
| | | { |
| | | person p; |
| | | p = f_db->db_rearch(int); |
| | | p = dbu->db_rearch(int); |
| | | return p; |
| | | } |
| | | |
| | |
| | | idx = f_api->do_register(image); |
| | | if(idx<0) |
| | | { |
| | | idx = f_db->do_register(idx,p); |
| | | p->f_id = idx; |
| | | idx = dbu->do_register(idx,p); |
| | | if(idx) |
| | | { |
| | | return 0; |
| | |
| | | #include "DBuntil.h" |
| | | #include "faceAPI.h" |
| | | |
| | | class faceAPI f_api; |
| | | class DButil f_db; |
| | | |
| | | class tools |
| | | { |
| | | public: |
| | |
| | | int do_register(cv::Mat image,person *p); |
| | | person do_search(int idx); |
| | | int idx; |
| | | DBuntil dbu; |
| | | faceAPI f_api; |
| | | } |
| | | |
| | | #endif |