dlib 05 dlib自带demo 人脸检测

01 dlib的人脸检测资源

dlib提供了fhog的人脸图片及对应的数据文件。
代码:dlib\examples\face_detection_ex.cpp
工程名:face_detection_ex
检测图像文件:dlib\examples\faces
dlib\examples\faces\2007_007763.jpg

02 项目设置

把examples解决方案中的face_detection_ex工程设置为启动项。

配置属性==>调试==>命令参数==>..\..\..\examples\faces
配置属性==>调试==>工作目录==>$(OutDir)

这里写图片描述

03 检测结果

processing image ..\..\..\examples\faces\2007_007763.jpg
Number of faces detected: 7
Hit enter to process the next image...

这里写图片描述

04 代码

本地代码:dlib\examples\face_detection_ex.cpp
官网:http://dlib.net/face_detection_ex.cpp.html

#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;  // 黑白,检测速度快
            dlib::array2d<dlib::rgb_pixel> img;  // 彩色
            load_image(img, argv[i]);
            // 如果需要查找小于80*80的脸,需要上采样,执行一次pyramid_up()能检测40*40像素的量
            // 上采样速度很慢
            pyramid_up(img);  // 上采样1次,能够检测到40*40-80*80的脸,如果注释掉这句上采样,检测不到2007_007763.jpg的脸

            // 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;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值