Dlib库中提供了正脸人脸检测的接口,这里参考dlib/examples/face_detection_ex.cpp中的代码,通过调用Dlib中的接口,实现正脸人脸检测的测试代码,测试代码如下:

#include "funset.hpp"
#include <string>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <opencv2/opencv.hpp>/* reference: dlib/examples/face_detection_ex.cppThis face detector is made using the now classic Histogram of OrientedGradients (HOG) feature combined with a linear classifier, an image pyramid,and sliding window detection scheme.  This type of object detector is fairlygeneral and capable of detecting many types of semi-rigid objects inaddition to human faces.
*/
int test_face_detect()
{dlib::frontal_face_detector detector = dlib::get_frontal_face_detector();dlib::image_window win;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;}for (int i = 0; i < images.size(); i++) {dlib::array2d<unsigned char> img;dlib::load_image(img, path_images + images[i]);// Make the image bigger by a factor of two.  This is useful since// the face detector looks for faces that are about 80 by 80 pixels// or larger.  Therefore, if you want to find faces that are smaller// than that then you need to upsample the image as we do here by// calling pyramid_up().  So this will allow it to detect faces that// are at least 40 by 40 pixels in size.  We could call pyramid_up()// again to find even smaller faces, but note that every time we// upsample the image we make the detector run slower since it must// process a larger image.pyramid_up(img);// Now tell the face detector to give us a list of bounding boxes// around all the faces it can find in the image.std::vector<dlib::rectangle> dets = detector(img);fprintf(stderr, "detect face count: %d, actual face count: %d\n", dets.size(), count_faces[i]);cv::Mat matSrc = cv::imread(path_images + images[i], 1);if (matSrc.empty()) {fprintf(stderr, "read image error: %s\n", images[i].c_str());return -1;}for (auto faces : dets) {int x = faces.left() / 2;int y = faces.top() / 2;int w = faces.width() / 2;int h = faces.height() / 2;cv::rectangle(matSrc, cv::Rect(x, y, w, h), cv::Scalar(0, 255, 0), 2);}std::string save_result = path_images + "_" + images[i];cv::imwrite(save_result, matSrc);}int width = 200;int 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 + "_" + 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;
}

执行结果如下图:

人脸检测结果如下:

GitHub:https://github.com/fengbingchun/Face_Test

Dlib库中实现正脸人脸检测的测试代码相关推荐

  1. OpenFace库(Tadas Baltrusaitis)中基于HOG进行正脸人脸检测的测试代码

    Tadas Baltrusaitis的OpenFace是一个开源的面部行为分析工具,它的源码可以从https://github.com/TadasBaltrusaitis/OpenFace下载.Ope ...

  2. Dlib库中实现正脸人脸关键点(landmark)检测的测试代码

    Dlib库中提供了正脸人脸关键点检测的接口,这里参考dlib/examples/face_landmark_detection_ex.cpp中的代码,通过调用Dlib中的接口,实现正脸人脸关键点检测的 ...

  3. OpenFace库(Tadas Baltrusaitis)中基于Haar Cascade Classifiers进行人脸检测的测试代码

    Tadas Baltrusaitis的OpenFace是一个开源的面部行为分析工具,它的源码可以从 https://github.com/TadasBaltrusaitis/OpenFace 下载.O ...

  4. OpenCV与图像处理学习十七——OpenCV人脸检测(含代码)

    OpenCV与图像处理学习十七--OpenCV人脸检测(含代码) 一.人脸识别概要 1.1 人脸检测 1.2 人脸对齐(Face Alignment) 1.3 人脸特征提取(Face Feature ...

  5. opencv入门基础(七)基于dlib进行本地图片、实时人脸检测

    opencv入门基础(七)基于dlib进行本地图片.实时人脸检测 一.背景知识 1.Dlib是一个深度学习开源工具,基于C++开发,也支持Python开发接口. 2.由于Dlib对于人脸特征提取效果很 ...

  6. YOLOv5Face YOLO5Face人脸检测论文及代码简析

    YOLO5face人脸检测模型论文和代码简析 YOLO5Face模型分析 论文及源码下载 论文创新点 实验结果 下载代码跑起来 调整数据集 训练完成之后检验结果 一点点代码简析 文件结构 data m ...

  7. 人脸检测数据集评价代码FDDB evaluation运行方法

    人脸检测数据集评价代码运行方法: FDDB evaluation安装及使用 基本参考http://blog.csdn.net/u011783201/article/details/52119313,但 ...

  8. python dlib学习(一):人脸检测

    前言 dlib毕竟是一个很有名的库了,有c++.Python的接口.使用dlib可以大大简化开发,比如人脸识别,特征点检测之类的工作都可以很轻松实现.同时也有很多基于dlib开发的应用和开源库,比如f ...

  9. Opencv中的深度学习(人脸检测、车牌检测、DNN)

    首先,无论是做检测还是DNN图像分类,所有的模型或配置文件都需要从以下三个网站中下载IT大牛们帮我们创建的各种分类器: # 人脸检测 ''' https://github.com/opencv/ope ...

最新文章

  1. 揭秘|超乎想象!未来50年将出现的九大黑科技……
  2. tomcat服务器介绍之二 、session服务器实现方法
  3. Apple开发者账号申请学习方式
  4. nullnulle-人事管理系统-人事档案-变更管理-人员合同变更
  5. 脸书令牌怎么使用_网工知识角|QOS技术令牌桶算法一分钟速记,考试无忧
  6. python读取大文件内存不够_大型CSV文件(numpy)上的Python内存不足
  7. CompactExifLib:访问JPEG文件中的EXIF标签
  8. 5.1(统计正数和负数的个数然后计算这些数的平均值)
  9. mysql vc运行库,VC运行库版本 - robslove的个人页面 - OSCHINA - 中文开源技术交流社区...
  10. vm虚拟机的安装使用装系统有序列号
  11. 100个Python实战项目(一)使用 Python 生成二维码
  12. Firefox XPI插件安装方法
  13. 怎样用捷速PDF编辑器修改PDF文档
  14. php?what=chinese,推荐4-ChineseUtil v1.1.2 发布,PHP 中文工具包
  15. dtools: error while loading shared libraries: libicui18n.so.55: cannot open shared object file
  16. java.util.ConcurrentModificationException: null 报错解决
  17. BaseFX 实习小记(一)
  18. 鸿蒙os正式版推送时间,鸿蒙OS正式版推送时间确定,游戏性能更强,流畅度稳定性均提升...
  19. 未来教育计算机三级数据库演示大题,2019年计算机三级数据库考试强化试题及答案003...
  20. [转]签了工作之后才发现,自己太草率了!(很长很真实!但会对你有所帮助的!)

热门文章

  1. python升级知识整理 第四节: 面向对象
  2. Python Qt GUI设计:QComboBox下拉列表框类(基础篇—14)
  3. 基于U-Net系列算法的医学图像分割(课程设计)
  4. xubuntu 19.10安装tensorflow-gpu-2.0(本文很乱,供自己参考)
  5. 树莓派的Raspbian Stretch with desktop和Ubuntu Mate(废弃)
  6. 计算机专业英语2008影印版第四章翻译,计算机专业英语2008影印版选择题的翻译加答案(14页)-原创力文档...
  7. 如何查看OpenCV自带函数的源代码
  8. 华数机器人码垛_冲压机器人研究现状与发展方向
  9. ipa解包打包工具_7步!教你轻松搞定ios重签ipa包
  10. Python可以调用Gpu吗_加快Python算法的四个方法:Numba篇