dlib人脸检测功能介绍

本文主要介绍三个点:
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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/259004.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ios网络开发 网络状态检查

http://www.cnblogs.com/hanjun/archive/2012/12/01/2797622.html 网络连接中用到的类&#xff1a; 一.Reachability 1.添加 Reachability 的.h和.m文件&#xff0c;再添加SystemConfiguration.framework。 2.Reachability中定义了三种网络状态&#xff1a; typedef Num{ NotR…

delphi xe4 ini文件不能读取的解决方法

今天发现用inifiles下 tinifile.readstring方法突然不能读数据了&#xff0c;结果把ini文件格式由utf-8改成unicode后就能正常读取了。转载于:https://www.cnblogs.com/liqiao/p/3503985.html

《众妙之门——网页排版设计制胜秘诀》——3.4 展现品牌视觉的同时保持网页的可读性...

本节书摘来自异步社区《众妙之门——网页排版设计制胜秘诀》一书中的第3章&#xff0c;第3.4节&#xff0c;作者&#xff1a; 【德】Smashing Magazine 译者&#xff1a; 侯景艳 , 范辰 更多章节内容可以访问云栖社区“异步社区”公众号查看。 3.4 展现品牌视觉的同时保持网页的…

vs2013创建及使用DLL

这几天看了许多关于生成Dll的博文&#xff0c;很有感触&#xff0c;遂整理在此&#xff0c;以供自己后续参考。 VS2013创建DLL 我们使用vs2013来生成Dll&#xff0c;其实使用其他的版本也是同理如此。步骤如下&#xff1a; 单击“新建项目”&#xff0c;选择“Win32 项目”&a…

python的作用域分别有几种_python中作用域与函数嵌套

知识回顾&#xff1a; 拆解传参。 1.字典传参。使用** 2.列表传参。使用* 实际上我们在定义函数的时候&#xff0c;如果省略了星号&#xff0c;那么在调用函数的时候必须要省略星号&#xff0c;除非我们拆解后的参数个数刚好相等。 视频内容 本节知识视频教程 文字讲解开始&…

这个博客的由来

笔者从事电信行业大型商业智能系统工作多年&#xff0c;日前从事B2C电商网站类数据分析工作&#xff0c;特开设此微博&#xff0c;在发表好文同时&#xff0c;研究网站分析技术。转载于:https://www.cnblogs.com/sambazhu/p/3508633.html

《Axure RP8 网站和APP原型制作 从入门到精通》一2.7 交付

本节书摘来自异步社区《Axure RP8 网站和APP原型制作 从入门到精通》一书中的第2章&#xff0c;第2.7节&#xff0c;作者 金乌&#xff0c;更多章节内容可以访问云栖社区“异步社区”公众号查看 2.7 交付 模型一旦经过批准&#xff0c;我们就可以进入切图和优化图像环节了。我…

iOS UISegmentedControl 的使用

当用户输入不仅仅是布尔值时&#xff0c;可使用分段控件&#xff08;UISegmentedControl&#xff09;。分段控件提供一栏按钮&#xff08;有时称为按钮栏&#xff09;&#xff0c;但只能激活其中一个按钮。分段控件会导致用户在屏幕上看到的内容发生变化。它们常用于在不同类别…

js粘贴板为什么获取不到图片信息_【第1829期】复制黏贴上传图片和跨浏览器自动化测试...

前言这个操作体验倒是不错。今日早读文章由丁香园蒋璇投稿分享。蒋璇, 前端开发攻城狮, 现任职于丁香园. 英语爱好者, 测试驱动开发(TDD)&行为驱动开发(BDD)推崇者. 先专注于 https://github.com/Jiang-Xuan/tuchuang.space 项目的测试驱动开发探索正文从这开始~~在网页中上…

在C++中调用DLL中的函数

&#xfeff;转载自&#xff1a;http://blog.sina.com.cn/s/blog_53004b4901009h3b.html   应用程序使用DLL可以采用两种方式&#xff1a;一种是隐式链接&#xff0c;另一种是显式链接。在使用DLL之前首先要知道DLL中函数的结构信息。Visual C6.0&#xff08;或者更先进的版…

CentOS LVS安装配置

目录(?)[] 一般2.6.10以上内核版本都已经自带了ipvsadm,故不需要安装。 Ipvs 1.25编译 ipvsadm-1.25编译不过 去掉netlink库的依赖&#xff1a;去掉libipvs/Makefile的CFLAGS -DLIBIPVS_USE_NL&#xff0c;去掉Makefile的LIBS -lnl。需要popt库解析命令行&#xff0c;在这里…

《淘宝网开店 拍摄 修图 设计 装修 实战150招》一一2.7 横式构图和竖式构图...

本节书摘来自异步社区出版社《淘宝网开店 拍摄 修图 设计 装修 实战150招》一书中的第2章&#xff0c;第2.7节&#xff0c;作者&#xff1a; 葛存山&#xff0c;更多章节内容可以访问云栖社区“异步社区”公众号查看。 2.7 横式构图和竖式构图 横幅画面&#xff0c;即画面底边…

Node.js初接触(一)

本来还在纠结着到底要学哪一种后台语言呢&#xff0c;突然发现node.js很火&#xff0c;既然能被这么多人推崇&#xff0c;自然是有他的优势的。去百度百科看了一眼&#xff0c;或许是我理解能力太差&#xff0c;并没有了解到很多关于node.js的东西&#xff0c;大概就是知道了No…

python request file upload_Python基于requests实现模拟上传文件

方法1&#xff1a; 1.安装requests_toolbelt依赖库 #代码实现 def upload(self): login_token self.token.loadTokenList() for token in login_token: tempPassword_url self.config[crm_test_api]/document/upload tempPassword_data self.data_to_str.strToDict(title:1.…

MATLAB中的randi函数

randi Pseudorandom integers from a uniform discrete distribution.来自一个均匀离散分布的伪随机整数 R randi(IMAX,N) returns an N-by-N matrix containing pseudorandom integer values drawn from the discrete uniform distribution on 1:IMAX.返回一个NN的包含伪随机…

C++ dll的隐式与显式调用

&#xfeff;&#xfeff;&#xfeff;转载自&#xff1a;http://blog.sina.com.cn/s/blog_53004b4901009h3b.html   应用程序使用DLL可以采用两种方式&#xff1a;一种是隐式链接&#xff0c;另一种是显式链接。在使用DLL之前首先要知道DLL中函数的结构信息。Visual C6.0&…

《OpenGL ES 2.0游戏开发(上卷):基础技术和典型案例》——6.5节光照的每顶点计算与每片元计算...

本节书摘来自异步社区《OpenGL ES 2.0游戏开发&#xff08;上卷&#xff09;&#xff1a;基础技术和典型案例》一书中的第6章&#xff0c;第6.5节光照的每顶点计算与每片元计算&#xff0c;作者 吴亚峰&#xff0c;更多章节内容可以访问云栖社区“异步社区”公众号查看 6.5 光照…

毛笔笔锋算法IOS版

http://www.merowing.info/2012/04/drawing-smooth-lines-with-cocos2d-ios-inspired-by-paper/#.VUln2_mqpBe转载于:https://www.cnblogs.com/wangjinming/p/4481145.html

USE PDFCREATE TO CREATE A PDF FILE

来源&#xff1a;http://www.pdfforge.org/files/old_forum/1002.html a working sample with C & COM 2007-08-15 22:56:18 by eckart hi, here is a working sample of how to use PDFCreator in Visual C (after searching on internet for something similar I guess t…

python将一行作为字段_关于python:Django admin在同一行显示多个字段

我已经创建了一个模型&#xff0c;它将自动显示模型中的所有字段&#xff0c;并将其显示在管理页面上。 现在&#xff0c;我有一个问题&#xff0c;我希望在同一行中有两个字段&#xff0c;为此&#xff0c;我必须在modeladmin中指定字段集&#xff1a; 1 2 3 4 5fieldsets ( …