【问题标题】:How to use multiple object detector of Dlib?如何使用 Dlib 的多目标检测器?
【发布时间】:2018-06-22 16:02:49
【问题描述】:

我已经使用 Dlib 训练了两个人脸检测器。所以,我正在尝试使用那个(两个)人脸检测器来增加检测人脸。

object_detector1.svm
object_detector2.svm

但是,我不明白,如何使用它。请有人帮助我。

我看到this堆栈溢出问题并尝试使用它,但我得到一个错误。

我的努力:

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

        typedef scan_fhog_pyramid<pyramid_down<6> > image_scanner_type; 
        image_scanner_type scanner;

        object_detector<image_scanner_type> face_detector(2);
        dlib::deserialize(detectors[0], "object_detector1.svm");
        deserialize(face_detector[0],"object_detector2.svm");
        deserialize(face_detector[1],"face_detector1.svm");
        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);

            std::vector<rectangle> dets = face_detector(img);

            cout << "Number of faces detected: " << dets.size() << endl;

            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;
    }
}

提前致谢。

【问题讨论】:

    标签: c++ c++11 training-data dlib


    【解决方案1】:

    您可以将以下代码用于多个分类器。

    object_detector<image_scanner_type> face_detector, face_detector2;
    deserialize("object_detector1.svm")>>face_detector;
    deserialize("object_detector2.svm")>>face_detector2;
    
    std::vector<object_detector<image_scanner_type> > my_detectors;
    my_detectors.push_back(face_detector);
    my_detectors.push_back(face_detector2);
    
    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);
    
        std::vector<rectangle> dets = evaluate_detectors(my_detectors, img);
    
        cout << "Number of faces detected: " << dets.size() << endl;
    
        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();
    }
    

    【讨论】:

      猜你喜欢
      • 2017-09-21
      • 2019-04-20
      • 2016-07-18
      • 2016-12-28
      • 2019-03-23
      • 2017-06-01
      • 2016-07-09
      • 2016-10-27
      • 2021-03-22
      相关资源
      最近更新 更多