DLIB库example中face_detection_ex学习与实现

上源码

#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]);
            
            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;
    }
}

frontal_face_detector:

是object_detector一样的,该类的对象是用于检测图像中的对象的位置的工具。特别是,它是一个简单的容器,用于聚合图像扫描仪对象的实例(scan_fhog_pyramidscan_image_pyramidscan_image_boxes或 scan_image_custom

 typedef object_detector<scan_fhog_pyramid<pyramid_down<6> > > frontal_face_detector;

get_frontal_face_detector():

返回一个能够识别人脸的并且为 frontal_face_detector类型的容器

array2d

此对象表示二维对象数组。 灰度图

 pyramid_up(img)

向上采样,放大一倍

std::vector<rectangle> dets = detector(img)

这个运算符重载是在object_detector里面的。返回一个图像的vector<rectangle>。

效果

程序要用cmd来运行

猜你喜欢

转载自blog.csdn.net/weixin_40500230/article/details/83587164
今日推荐