本文主要介绍三个点:
1. 如何单独建立一个工程,使用dlib的人脸检测功能。
2. 提高人脸检测率的两个方法
3. 加速人脸检测的方法
下面围绕这几个点展开叙述。

建人脸检测工程

1 . 首先我们先使用上期说的examples里的人脸检测。
我们只要将face_detection_ex设为启动项,即可运行。效果如下:

2. 建立单独的工程。像其他正常的方法,建立一般的工程。然后
在项目 属性中选择C/C++ :
常规-》附加包含目录:填写之前准备好的dlib的include的路径,我这里是:D:\dlib_win32\include
预处理器定义:
WIN32
_WINDOWS
DLIB_PNG_SUPPORT
DLIB_JPEG_SUPPORT
NDEBUG
DLIB_HAVE_AVX
链接器-》常规-》附加库目录:填写你要加的库目录。我这里是
D:\dlib_win32\lib
输入-》附加依赖项:dlib.lib
命令行-》其它选项:/arch:AVX
最后在配置属性-》调试中添加:你要检测的图片的路径,
main.cpp可以使用dlib提供的官方示例:

// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*This example program shows how to find frontal human faces in an image.  Inparticular, this program shows how you can take a list of images from thecommand line and display each on the screen with red boxes overlaid on eachhuman face.The examples/faces folder contains some jpg images of people.  You can runthis program on them and see the detections by executing the following command:./face_detection_ex faces/*.jpgThis 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.  Therefore, if you are interested in making yourown object detectors then read the fhog_object_detector_ex.cpp exampleprogram.  It shows how to use the machine learning tools which were used tocreate dlib's face detector. Finally, note that the face detector is fastest when compiled with at leastSSE2 instructions enabled.  So if you are using a PC with an Intel or AMDchip then you should enable at least SSE2 instructions.  If you are usingcmake to compile this program you can enable them by using one of thefollowing commands when you create the build project:cmake path_to_dlib_root/examples -DUSE_SSE2_INSTRUCTIONS=ONcmake path_to_dlib_root/examples -DUSE_SSE4_INSTRUCTIONS=ONcmake path_to_dlib_root/examples -DUSE_AVX_INSTRUCTIONS=ONThis will set the appropriate compiler options for GCC, clang, VisualStudio, or the Intel compiler.  If you are using another compiler then youneed to consult your compiler's manual to determine how to enable theseinstructions.  Note that AVX is the fastest but requires a CPU from at least2011.  SSE4 is the next fastest and is supported by most current machines.
*/#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <iostream>using namespace dlib;
using namespace std;// ----------------------------------------------------------------------------------------int main(int argc, char** argv)
{  try{if (argc == 1){cout << "Give some image files as arguments to this program." << endl;return 0;}frontal_face_detector detector = get_frontal_face_detector();image_window win;// Loop over all the images provided on the command line.for (int i = 1; i < argc; ++i){cout << "processing image " << argv[i] << endl;array2d<unsigned char> img;load_image(img, argv[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<rectangle> dets = detector(img);cout << "Number of faces detected: " << dets.size() << endl;// Now we show the image on the screen and the face detections as// red overlay boxes.win.clear_overlay();win.set_image(img);win.add_overlay(dets, rgb_pixel(255,0,0));cout << "Hit enter to process the next image..." << endl;cin.get();}}catch (exception& e){cout << "\nexception thrown!" << endl;cout << e.what() << endl;}
}// ----------------------------------------------------------------------------------------

然后就可以人脸检测了。如下是我的效果。

提高人脸检测率的两个方法

  1. 确保检测图片是检测器的两倍。这第一点是十分有用的,因为脸部检测器搜寻的人脸大小是80*80或者更大。
    因此,如果你想找到比80*80小的人脸,需要将检测图片进行上采样,我们可以调用pyramid_up()函数。
    执行一次pyramid_up()我们能检测40*40大小的了,如果我们想检测更小的人脸,那还需要再次执行pyramid_up()函数。
    注意,上采样后,速度会减慢!*/
    pyramid_up(img);//对图像进行上采用,检测更小的人脸。
  2. 在程序中使用:

    array2d<rgb_pixel> img;
    取代:
    array2d<unsigned char> img;

这个我试验过了,有些图片使用’rgb_pixel‘就检测不出来,‘unsigned \ char’就可以。可能是前者使用的rgb信息而后者只使用了灰度信息。

加速人脸检测

可以参考这两篇文章。这也是为什么我们要在命令行-》其它选项:/arch:AVX 加的原因。

  • 跨平台使用Intrinsic函数范例1——使用SSE、AVX指令集 处理 单精度浮点数组求和(支持vc、gcc,兼容Windows、Linux、Mac)

  • Why is dlib slow?

参考文献:

  1. http://dlib.net/
  2. http://blog.csdn.net/sunshine_in_moon/article/details/50149339

dlib人脸检测功能介绍相关推荐

  1. python提取个十百千位数字_实现人脸识别、人脸68个特征点提取,或许这个 Python 库能帮到你!...

    之前写过一篇关于实现人脸识别的文章, Z先生点记:Pyqt5 + 百度 API 打造一个图像人脸识别.分割的小程序​zhuanlan.zhihu.com 里面用到的技术是通过调用百度 API 实现的, ...

  2. python 人脸轮廓提取_实现人脸识别、人脸68个特征点提取,或许这个 Python 库能帮到你!...

    以前写过一篇关于实现人脸识别的文章,里面用到的技术是经过调用百度 API 实现的,本次将借助于 dlib  程序包实现人脸区域检测.特征点提取等功能,html dlib 封装了许多优秀的机器学习算法, ...

  3. 做一个人脸识别相关的毕业设计

    本文旨在简单聊一下做一个与人脸识别相关的本科毕业设计,希望不是挖坑文. 背景:普通本科毕业设计大多是构建网站(购物.管理系统.论坛),相对来说老师看的也审美疲劳,当然如果买毕设的话价格会相对便宜. 本 ...

  4. C/C++ 开源库及示例代码

    C/C++ 开源库及示例代码 Table of Contents 说明 1 综合性的库 2 数据结构 & 算法 2.1 容器 2.1.1 标准容器 2.1.2 Lockfree 的容器 2.1 ...

  5. python人脸特征提取_实现人脸识别、人脸68个特征点提取,或许这个 Python 库能帮到你!...

    之前写过一篇关于实现人脸识别的文章,Z先生点记:Pyqt5 + 百度 API 打造一个图像人脸识别.分割的小程序​zhuanlan.zhihu.com 里面用到的技术是通过调用百度 API 实现的,本 ...

  6. Python换脸术,不会AI也能get有趣有料的技术!

    「2019 Python开发者日」全日程揭晓,请扫码咨询 ↑↑↑ 作者 | 雇个城管打天下,理工男一枚.南京大学软件工程系硕士,一个还在做着拥有十万读者梦的互联网新人,或许一篇文章无法获得你的关注,但 ...

  7. Python换脸术,不会AI也能get有趣又料的技术!

    接下来我将会介绍如何通过一段简短的 Python 脚本(200行左右)将一张图片中面部特征自动替换为另外一张图片中的面部特征. 具体过程分为四个步骤 检测面部标志: 旋转.缩放和平移图 2 以适应图 ...

  8. 狗脸识别python_实现人脸识别、人脸68个特征点提取,或许这个 Python 库能帮到你!...

    之前写过一篇关于实现人脸识别的文章,里面用到的技术是通过调用百度 API 实现的,本次将借助于 dlib  程序包实现人脸区域检测.特征点提取等功能, dlib 封装了许多优秀的机器学习算法, 可实现 ...

  9. Dlib库介绍(一)

    Dlib是一个包含机器学习算法的C++开源工具包.Dlib可以帮助您创建很多复杂的机器学习方面的软件来帮助解决实际问题.目前Dlib已经被广泛的用在行业和学术领域,包括机器人,嵌入式设备,移动电话和大 ...

最新文章

  1. linux 下 iscsi的简单使用
  2. ConditionedActivityGroup
  3. php fpm 调试模式,调试 – nginx php-fpm xdebug netbeans只能启动一个调试会话
  4. 移动端html搜索怎么写,移动端实现搜索功能
  5. 详解Python 3.6.x程序打包并发布至pypi的完整过程
  6. Ceph的客户端安装
  7. Oracle 函数大全(字符串函数,数学函数,日期函数,逻辑运算函数,其他函数)...
  8. php监控nginx,zabbix php nginx 监控搭建
  9. java instanceof和isInstance的关系 精析
  10. WCF中NetTCp配置
  11. UEA1224——郭恩赐 day06 作业
  12. 鸿蒙系统有哪些手机可以用,鸿蒙系统支持哪些手机型号
  13. 控制 计算机某个程序自动开关,电脑自动开关机软件(示例代码)
  14. 打开好哈录屏或者OBS直播软件黑屏问题解决,亲测有效!
  15. 电商产品经理必修课之学员招募及在线课程学习
  16. 数据分析-SQL练习
  17. 【quick-cocos2d-lua】 疯狂牛牛
  18. 产品经理职责和工作内容
  19. 接入支付宝支付 错误码4000,排查方法——开发记录
  20. 第九届《生活月刊》国家精神造就者荣誉揭晓

热门文章

  1. DropDownList实现无限级分类
  2. [转] STL中map用法详解
  3. Vue多字段下的非空判断(new Promise)
  4. bzoj 4736: 温暖会指引我们前行 (LCT 维护最大生成树)
  5. namespace 或The content of element type mapper must match EMPTY
  6. Spark启动程序:Master
  7. 【转】PB实现在通知区域添加图标
  8. 090609 T 领域建模
  9. vue --- 按钮的防重复点击事件
  10. EXCEL小技巧:如何统计非空单元格