dlib人脸检测功能介绍

标签: 人脸识别-dlib
16552人阅读 评论(4) 收藏 举报
分类:

本文主要介绍三个点:
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.  In
    particular, this program shows how you can take a list of images from the
    command line and display each on the screen with red boxes overlaid on each
    human face.

    The examples/faces folder contains some jpg images of people.  You can run
    this program on them and see the detections by executing the following command:
        ./face_detection_ex faces/*.jpg


    This face detector is made using the now classic Histogram of Oriented
    Gradients (HOG) feature combined with a linear classifier, an image pyramid,
    and sliding window detection scheme.  This type of object detector is fairly
    general and capable of detecting many types of semi-rigid objects in
    addition to human faces.  Therefore, if you are interested in making your
    own object detectors then read the fhog_object_detector_ex.cpp example
    program.  It shows how to use the machine learning tools which were used to
    create dlib's face detector. 


    Finally, note that the face detector is fastest when compiled with at least
    SSE2 instructions enabled.  So if you are using a PC with an Intel or AMD
    chip then you should enable at least SSE2 instructions.  If you are using
    cmake to compile this program you can enable them by using one of the
    following commands when you create the build project:
        cmake path_to_dlib_root/examples -DUSE_SSE2_INSTRUCTIONS=ON
        cmake path_to_dlib_root/examples -DUSE_SSE4_INSTRUCTIONS=ON
        cmake path_to_dlib_root/examples -DUSE_AVX_INSTRUCTIONS=ON
    This will set the appropriate compiler options for GCC, clang, Visual
    Studio, or the Intel compiler.  If you are using another compiler then you
    need to consult your compiler's manual to determine how to enable these
    instructions.  Note that AVX is the fastest but requires a CPU from at least
    2011.  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 加的原因。

参考文献:

  1. http://dlib.net/
  2. http://blog.csdn.net/sunshine_in_moon/article/details/50149339
查看评论

Dlib提取人脸特征点(68点,opencv画图)

Dlib+opencv 68点特征点的使用以及绘图。
  • zmdsjtu
  • zmdsjtu
  • 2016-12-04 14:31:13
  • 28022

使用Dlib库进行人脸检测,人脸对齐和人脸识别

简介在之前的博客中,我已经介绍了如何使用dlib-18.17进行人脸检测和人脸对齐。 Windows10+VS2013环境下Dlib库的编译与使用-邬小阳 使用Dlib库进行人脸检测与对齐-邬小阳...
  • u013078356
  • u013078356
  • 2017-04-20 09:12:19
  • 9122

人脸检测、提取特征点(dlib下的三个例子)

转载请注明出处: 本文章主要进行dlib中....\dlib-18.18\examples下的三个例子的实现。 本小白用的是:VS2013 + dlib18.18 + opencv2.4.11 ...
  • ouyangying123
  • ouyangying123
  • 2017-04-27 15:05:50
  • 2242

Dlib人脸特征点检测(速度优化)

Dlib
  • Leo_812
  • Leo_812
  • 2016-07-18 21:25:54
  • 19332

【dlib代码解读】人脸检测器的训练

基于dlib训练自己的人脸检测器
  • elaine_bao
  • elaine_bao
  • 2016-11-05 20:22:32
  • 9416

dlib人脸检测

一、dlib Dlib是一个机器学习的C++库,包含了许多机器学习常用的算法。下载:http://www.dlib.net/ml.html         二、安转qt,设置环境变量,用qt自带的...
  • qq_18854309
  • qq_18854309
  • 2017-09-26 13:28:09
  • 670

人脸特征检测--基于DLIB库

Dlib是一个C++编写的工具包,它包含了机器学习算法以及一些用来解决现实复杂问题的工具,可以广泛应用于机器人、嵌入式设备、手机,甚至高性能计算中,可以在其官网了解更多。这里下载它来试用一下,下载后解...
  • Linjingke32
  • Linjingke32
  • 2017-06-08 10:47:27
  • 771

Opencv与dlib联合进行人脸关键点检测与识别

前言 依赖库:opencv 2.4.9 /dlib 19.0/libfacedetection 本篇不记录如何配置,重点在实现上。使用libfacedetection实现人脸区域检测,联合dlib...
  • Mr_Curry
  • Mr_Curry
  • 2016-07-22 14:28:03
  • 23356

结合dlib与OpenCV的视频流人脸检测

dlib的人脸检测精度比OpenCV自带的高很多。因此本文采用dlib的人脸检测器,结合OpenCV视频流的读取方法,演示如何进行视频流的人脸检测。...
  • jinxueliu31
  • jinxueliu31
  • 2016-09-08 18:28:50
  • 3846

基于深度学习的人脸识别系统(Caffe+OpenCV+Dlib)【二】人脸预处理

前言 基于深度学习的人脸识别系统,一共用到了5个开源库:OpenCV(计算机视觉库)、Caffe(深度学习库)、Dlib(机器学习库)、libfacedetection(人脸检测库)、cudnn(g...
  • Mr_Curry
  • Mr_Curry
  • 2016-09-06 20:53:27
  • 16277
    个人资料
    持之以恒
    等级:
    访问量: 34万+
    积分: 4749
    排名: 7682
    个人网站
    最新评论