• SeetaFaceEngine系列3:Face Identification编译和使用


    前面两篇介绍了怎样编译SeetaFace的前两部分,现在就来讲下第三部分Face Identification的编译和使用。

    其实,步骤基本上是一直的,如下:

    1、新建一个空的DLL工程;

    2、修改配置器;

    3、添加include

    4、添加lib文件路径和依赖项

    5、修改预处理器

    6、打开OpenMP

    7、添加源文件到工程中

    这里,将FaceIdentificationsrc文件夹下的所有文件(test除外)添加到工程中:

    8、编译工程得到lib文件和dll文件(Release的步骤也是一样的)

    9、使用Face Identification进行人脸匹配

    FaceIdentificationsrc est文件夹下有两个测试文件test_face_recognizer.cpp和test_face_verification.cpp,其中test_face_recognizer.cpp是测试各项功能的,包括人脸剪切、特征提取和匹配,后者是直接输入两幅图,计算匹配度,这里我测试了第二个的功能。

    代码如下:

    int testFaceRecognizer(std::string src_Path1, std::string src_Path2)    
    {
    	seeta::FaceDetection detector("D:/SeetaFaceEngine/include_lib/model/FaceDetection/seeta_fd_frontal_v1.0.bin");
    	detector.SetMinFaceSize(40);
    	detector.SetScoreThresh(2.f);
    	detector.SetImagePyramidScaleFactor(0.8f);
    	detector.SetWindowStep(4, 4);
    
    	// Initialize face alignment model 
    	seeta::FaceAlignment point_detector("D:/SeetaFaceEngine/include_lib/model/FaceAlignment/seeta_fa_v1.1.bin");
    
    	// Initialize face Identification model 
    	seeta::FaceIdentification face_recognizer((MODEL_DIR + "seeta_fr_v1.0.bin").c_str());
    	std::string test_dir = DATA_DIR + "test_face_recognizer/";
    
    	//load image
    	cv::Mat gallery_img_color = cv::imread(src_Path1, 1);
    	cv::Mat gallery_img_gray;
    	cv::cvtColor(gallery_img_color, gallery_img_gray, CV_BGR2GRAY);
    
    	cv::Mat probe_img_color = cv::imread(src_Path2, 1);
    	cv::Mat probe_img_gray;
    	cv::cvtColor(probe_img_color, probe_img_gray, CV_BGR2GRAY);
    
    	seeta::ImageData gallery_img_data_color(gallery_img_color.cols, gallery_img_color.rows, gallery_img_color.channels());
    	gallery_img_data_color.data = gallery_img_color.data;
    
    	seeta::ImageData gallery_img_data_gray(gallery_img_gray.cols, gallery_img_gray.rows, gallery_img_gray.channels());
    	gallery_img_data_gray.data = gallery_img_gray.data;
    
    	seeta::ImageData probe_img_data_color(probe_img_color.cols, probe_img_color.rows, probe_img_color.channels());
    	probe_img_data_color.data = probe_img_color.data;
    
    	seeta::ImageData probe_img_data_gray(probe_img_gray.cols, probe_img_gray.rows, probe_img_gray.channels());
    	probe_img_data_gray.data = probe_img_gray.data;
    
    	// Detect faces
    	std::vector<seeta::FaceInfo> gallery_faces = detector.Detect(gallery_img_data_gray);
    	int32_t gallery_face_num = static_cast<int32_t>(gallery_faces.size());
    
    	std::vector<seeta::FaceInfo> probe_faces = detector.Detect(probe_img_data_gray);
    	int32_t probe_face_num = static_cast<int32_t>(probe_faces.size());
    
    	if (gallery_face_num == 0 || probe_face_num == 0)
    	{
    	    std::cout << "Faces are not detected.";
    	    return 0;
    	}
    
    	// Detect 5 facial landmarks
    	seeta::FacialLandmark gallery_points[5];
    	point_detector.PointDetectLandmarks(gallery_img_data_gray, gallery_faces[0], gallery_points);
    
    	seeta::FacialLandmark probe_points[5];
    	point_detector.PointDetectLandmarks(probe_img_data_gray, probe_faces[0], probe_points);
    
    	for (int i = 0; i < 5; i++)
    	{
    		cv::circle(gallery_img_color, cv::Point(gallery_points[i].x, gallery_points[i].y), 2,CV_RGB(0, 255, 0));
    		cv::circle(probe_img_color, cv::Point(probe_points[i].x, probe_points[i].y), 2, CV_RGB(0, 255, 0));
    	}
    	cv::imshow("gallery_point_result.jpg", gallery_img_color);
    	cv::imshow("probe_point_result.jpg", probe_img_color);
    
    	// Extract face identity feature
    	float gallery_fea[2048];
    	float probe_fea[2048];
    	face_recognizer.ExtractFeatureWithCrop(gallery_img_data_color, gallery_points, gallery_fea);
    	face_recognizer.ExtractFeatureWithCrop(probe_img_data_color, probe_points, probe_fea);
    
    	// Caculate similarity of two faces
    	float sim = face_recognizer.CalcSimilarity(gallery_fea, probe_fea);
    	std::cout << sim << std::endl;
    	cv::waitKey(0);
    }

    匹配的结果如下:

    两幅人脸的相似度是0.6850。

    OK,至此,SeetaFace的三个功能基本就介绍完了。那人脸检测和识别的库有很多很多很多很多...很多,然后我之所以要用下这个,原因也很简单,其他开源库要依赖的东西稍微多一些,这个库相对就少,唯一一个依赖的也是OpenCV,配置真的也挺简单的,速度也勉强可以接受,所以如果不是要求多高的话,还是可以用这个库玩一下的。

    你可以重复着初恋 

    却不能重复热情  

    你可以重复那些后悔

    却重复不了 最爱  

      --旖旎 《永远的夏娃·断章》

    上善若水,为而不争。
  • 相关阅读:
    推荐两款好用的反编译工具(Luyten,Jadx)
    在windows上运行linux
    Spring IOC的理解
    Django 13 admin和auth系统、权限问题
    Django 12 中间件、上下文处理器和admin后台
    Django 11 form表单(状态保持session、form表单及注册实现)
    Django 10 GET和POST(HttpRequest对象,GET和POST请求,文件上传,HttpResponse对象的cookie)
    Django 09 博客小案例
    Django 解答 01 (pycharm创建项目)
    Django 08 Django模型基础3(关系表的数据操作、表关联对象的访问、多表查询、聚合、分组、F、Q查询)
  • 原文地址:https://www.cnblogs.com/Bearoom/p/11721773.html
Copyright © 2020-2023  润新知