git-svn-id: http://192.168.1.226/svn/proxy@55 454eff88-639b-444f-9e54-f578c98de674
| | |
| | | int do_register(cv::Mat image);
|
| | |
|
| | | private:
|
| | | |
| | |
|
| | | //调用搜索
|
| | | int p_img_search(cv_feature_t *p_feature);
|
| | |
|
| | |
| | | //"./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);
|
| | | }
|
| | |
| | | //静态人脸识别
|
| | | static cv_handle_t handle_detect;
|
| | |
|
| | | class faceDB{
|
| | | class faceDB
|
| | | {
|
| | | public:
|
| | | //static faceDB* GetInstance();
|
| | | |
| | |
|
| | | //搜索SDK数据库
|
| | | int search_db(cv_feature_t* p_feature );
|
| | | //添加记录
|
| | |
| | | cv_feature_t *extract_feature(cv::Mat image_color);
|
| | |
|
| | | private:
|
| | | |
| | |
|
| | | cv_result_t cv_result;
|
| | | //static faceDB* db;
|
| | | //faceDB(const faceDB & );
|
| | |
| | | using namespace std; |
| | | using namespace cv; |
| | | |
| | | int main(int argc, char *argv[]) { |
| | | int main(int argc, char *argv[]) |
| | | { |
| | | if (argc < 2) { |
| | | fprintf(stderr, "test_sample_face_track [alignment point size(21 or 106)] [detect face cont limit]\n"); |
| | | fprintf(stderr, "for example: \"test_sample_face_track 21 1\"\n"); |
| | |
| | | int config; |
| | | if (point_size == 21) { |
| | | config = CV_DETECT_ENABLE_ALIGN_21; |
| | | } |
| | | else if (point_size == 106) { |
| | | } else if (point_size == 106) { |
| | | config = CV_DETECT_ENABLE_ALIGN_106; |
| | | } |
| | | else { |
| | | } else { |
| | | fprintf(stderr, "alignment point size must be 21 or 106\n"); |
| | | return -1; |
| | | } |
| | |
| | | int face_count = 0; |
| | | while (capture.read(bgr_frame)) { // CV_PIX_FMT_BGR888 |
| | | resize(bgr_frame, bgr_frame, Size(frame_width, frame_height), 0, 0, |
| | | INTER_LINEAR); |
| | | INTER_LINEAR); |
| | | // realtime track |
| | | face_count = 0; |
| | | cv_result = cv_face_track(handle_track, bgr_frame.data, CV_PIX_FMT_BGR888, |
| | | bgr_frame.cols, bgr_frame.rows, bgr_frame.step, |
| | | CV_FACE_UP, &p_face, &face_count); |
| | | bgr_frame.cols, bgr_frame.rows, bgr_frame.step, |
| | | CV_FACE_UP, &p_face, &face_count); |
| | | if (cv_result != CV_OK) { |
| | | fprintf(stderr, "cv_face_track failed, error : %d\n", cv_result); |
| | | cv_face_release_tracker_result(p_face, face_count); |
| | |
| | | |
| | | for (int i = 0; i < face_count; i++) { |
| | | fprintf(stderr, "face: %d-----[%d, %d, %d, %d]-----id: %d\n", i, |
| | | p_face[i].rect.left, p_face[i].rect.top, |
| | | p_face[i].rect.right, p_face[i].rect.bottom, p_face[i].ID); |
| | | p_face[i].rect.left, p_face[i].rect.top, |
| | | p_face[i].rect.right, p_face[i].rect.bottom, p_face[i].ID); |
| | | fprintf(stderr, "face pose: [yaw: %.2f, pitch: %.2f, roll: %.2f, eye distance: %.2f]\n", |
| | | p_face[i].yaw, |
| | | p_face[i].pitch, p_face[i].roll, p_face[i].eye_dist); |
| | | p_face[i].yaw, |
| | | p_face[i].pitch, p_face[i].roll, p_face[i].eye_dist); |
| | | |
| | | // draw the video |
| | | Scalar scalar_color = CV_RGB(p_face[i].ID * 53 % 256, |
| | | p_face[i].ID * 93 % 256, |
| | | p_face[i].ID * 143 % 256); |
| | | p_face[i].ID * 93 % 256, |
| | | p_face[i].ID * 143 % 256); |
| | | rectangle(bgr_frame, Point2f(static_cast<float>(p_face[i].rect.left), |
| | | static_cast<float>(p_face[i].rect.top)), |
| | | Point2f(static_cast<float>(p_face[i].rect.right), |
| | | static_cast<float>(p_face[i].rect.bottom)), scalar_color, 2); |
| | | static_cast<float>(p_face[i].rect.top)), |
| | | Point2f(static_cast<float>(p_face[i].rect.right), |
| | | static_cast<float>(p_face[i].rect.bottom)), scalar_color, 2); |
| | | for (int j = 0; j < p_face[i].points_count; j++) { |
| | | circle(bgr_frame, Point2f(p_face[i].points_array[j].x, |
| | | p_face[i].points_array[j].y), 1, Scalar(0, 255, 0)); |
| | | p_face[i].points_array[j].y), 1, Scalar(0, 255, 0)); |
| | | } |
| | | } |
| | | |
| | |
| | |
|
| | | using namespace std;
|
| | |
|
| | | int main(int argc, char *argv[] ) {
|
| | | int main(int argc, char *argv[] )
|
| | | {
|
| | |
|
| | | //文件路径
|
| | | char *db_path = "./out.db";
|
| | | char *image_path = argv[1];
|
| | | char *image_list = "../test_image/imglist";
|
| | | 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;
|
| | | }
|
| | | int idx = -11;
|
| | | faceAPI face;
|
| | | idx = face.do_reasch(bgr_image);
|
| | | cout<<"idx="<<idx<<endl;
|
| | | cout<<"idx="<<idx<<endl;
|
| | |
|
| | | return 0;
|
| | | }
|