人脸检测库libfacedetection介绍

分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

 libfacedetection是于仕琪老师放到GitHub上的二进制库,没有源码,它的License是MIT,可以商用。目前只提供了windows 32和64位的release动态库,主页为https://github.com/ShiqiYu/libfacedetection,采用的算法好像是Multi-BlockLBP,提供了四套接口,分别为frontal、frontal_surveillance、multiview、multiview_reinforce,其中multiview_reinforce效果最好,速度比其它稍慢,四套接口的参数类型完全一致,可以根据需要对参数min_neighbors和min_object_width进行调整。

 新建一个控制台工程,用来测试libfacedetection,测试代码如下:

#include <iostream>#include <string>#include <vector>#include <facedetect-dll.h>#include <opencv2/opencv.hpp>int main()std::vector<std::string> images{ "1.jpg", "2.jpg", "3.jpg", "4.jpeg", "5.jpeg", "6.jpg", "7.jpg", "8.jpg", "9.jpg", "10.jpg",  "11.jpeg", "12.jpg", "13.jpeg", "14.jpg", "15.jpeg", "16.jpg", "17.jpg", "18.jpg", "19.jpg", "20.jpg" }; std::vector<int> count_faces{1, 2, 6, 0, 1, 1, 1, 2, 1, 1,  1, 1, 1, 1, 1, 1, 1, 0, 8, 2}; std::string path_images{ "E:/GitCode/Face_Test/testdata/" }; if (images.size() != count_faces.size()) {  fprintf(stderr, "their size that images and count_faces are mismatch\n");  return -1; } typedef int* (*detect_face)(unsigned char * gray_image_data, int width, int height, int step,  float scale, int min_neighbors, int min_object_width, int max_object_width); detect_face detect_methods[]{  &facedetect_frontal,  &facedetect_multiview,  &facedetect_multiview_reinforce,  &facedetect_frontal_surveillance }; std::string detect_type[4] {"face frontal", "face multiview", "face multiview reinforce", "face surveillance"}; for (int method = 0; method < 4; method++) {  detect_face detect = detect_methods[method];  fprintf(stderr, "detect type: %s\n", detect_type[method].c_str());  for (int i = 0; i < images.size(); i++) {   cv::Mat src_ = cv::imread(path_images + images[i], 1);   if (src_.empty()) {    fprintf(stderr, "read image error: %s\n", images[i].c_str());    return -1;   }   cv::Mat src;   cv::cvtColor(src_, src, CV_BGR2GRAY);   int* results = nullptr;   results = detect(src.data, src.cols, src.rows, src.step, 1.2f, 2, 10, 0);   std::string save_result = path_images + std::to_string(method) + "_" + images[i];   //fprintf(stderr, "save result: %s\n", save_result.c_str());   for (int faces = 0; faces < (results ? *results : 0); faces++) {    short* p = ((short*)(results + 1)) + 6 * faces;    int x = p[0];    int y = p[1];    int w = p[2];    int h = p[3];    int neighbors = p[4];    int angle = p[5];    fprintf(stderr, "image_name: %s, faces_num: %d, face_rect=[%d, %d, %d, %d], neighbors=%d, angle=%d\n",     images[i].c_str(), *results, x, y, w, h, neighbors, angle);    cv::rectangle(src_, cv::Rect(x, y, w, h), cv::Scalar(0, 255, 0), 2);   }   cv::imwrite(save_result, src_);  } } int width = 200int height = 200; cv::Mat dst(height * 5, width * 4, CV_8UC3)for (int i = 0; i < images.size(); i++) {  std::string input_image = path_images + "2_" + images[i];  cv::Mat src = cv::imread(input_image, 1);  if (src.empty()) {   fprintf(stderr, "read image error: %s\n", images[i].c_str());   return -1;  }  cv::resize(src, src, cv::Size(width, height), 0, 0, 4);  int x = (i * width) % (width * 4);  int y = (i / 4) * height;  cv::Mat part = dst(cv::Rect(x, y, width, height));  src.copyTo(part); } std::string output_image = path_images + "result.png"; cv::imwrite(output_image, dst); fprintf(stderr, "ok\n"); return 0;}

 从网上找了20张图像,验证此库的检测率,下图是采用multiview_reinforce接口的检测结果:



 GitHubhttps://github.com/fengbingchun/Face_Test

           

给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
这里写图片描述
  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Dlib是一款强大的机器学习,它包含许多预训练的神经网络模型,可以用于人脸检测。Dlib人脸检测算法基于深度学习技术,通过训练大量的图像数据集(如LFW数据集),学习到人脸的特征表示,从而实现对人脸的准确识别和定位。 在Dlib中,人脸检测的实现主要依赖于其内置的HOG特征描述器和支持向量机(SVM)分类器。HOG特征描述器能够捕捉图像中的局部特征,包括边缘、纹理等,而SVM分类器则可以对这些特征进行分类,从而实现人脸检测。 具体来说,Dlib人脸检测算法主要包括以下几个步骤: 1. 预处理:对输入图像进行灰度化和归一化处理,以减少计算复杂度和提高检测精度。 2. 特征提取:使用HOG特征描述器从图像中提取局部特征,这些特征可以捕捉到人脸的形状、纹理等信息。 3. 训练模型:将提取的特征输入到SVM分类器中进行训练,学习到人脸的特征表示。 4. 检测人脸:将待检测图像的特征输入到训练好的SVM分类器中,根据分类器的输出结果,确定人脸的位置和大小。 在检测精度方面,Dlib人脸检测算法在各种人脸数据集上已经取得了较高的准确率,并具有较高的鲁棒性和稳定性。此外,Dlib人脸检测算法还可以与其他算法结合使用,如面部识别、面部动画等,进一步拓展其在人机交互、安全、娱乐等领域的应用。 总的来说,Dlib人脸检测算法是基于深度学习技术的强大机器学习,具有较高的准确率和稳定性,能够广泛应用于各种实际场景中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值