c++ - 如何在 dlib 正面面部检测器中拆分级联级别?

标签 c++ dlib

跟进:openface/issue/157

我正在尝试将 dlib 正面面部检测器中的五级级联拆分为三级(正面,正面但向左旋转,正面但向右旋转)

Evgeniy建议在 C++ 中拆分检测器。我不熟悉 C++。当我查看 frontal_face_detector.h 时, get_serialized_frontal_faces 返回一个base64编码的对象。

我学会了如何将现有检测器保存到 .svm 文件中:

#include <dlib/image_processing/frontal_face_detector.h>
#include <iostream>

using namespace dlib;
using namespace std;

int main()
{   
    frontal_face_detector detector = get_frontal_face_detector(); 

    dlib::serialize("new_detector.svm") << detector;  

    std::cout<<"End of the Program"<<endl;
    return 0;   
}

那么如何拆分级联并将新检测器保存到.svm文件中呢?

通过将金字塔级别从 <6> 降低到 frontal_face_detector.h 中的较低值,检测器性能也会提高?

最佳答案

刚刚阅读object detector documentation你会找到解释。 下面是将检测器拆分为多个部分、重建原始文件并限制金字塔级别的代码:

#include <dlib/image_processing/frontal_face_detector.h>
#include <iostream>
#include <string>

using namespace dlib;
using namespace std;

int main()
{   
    frontal_face_detector detector = get_frontal_face_detector(); 

    dlib::serialize("current.svm") << detector;

    std::vector<frontal_face_detector> parts;
    // Split into parts and serialize to disk
    for (unsigned long i = 0; i < detector.num_detectors(); ++i)
    {
        dlib::frontal_face_detector part(detector.get_scanner(), detector.get_overlap_tester(), detector.get_w(i));
        dlib::serialize("part" + std::to_string(i) + ".svm") << part;
        parts.push_back(part);
    }

    // Reconstruct original detector
    frontal_face_detector reconstructed(parts);
    dlib::serialize("reconstructed.svm") << reconstructed;

    // Create detector that will work only on one level of pyramid
    typedef dlib::scan_fhog_pyramid<dlib::pyramid_down<6> > image_scanner_type;
    image_scanner_type scanner;
    scanner.copy_configuration(detector.get_scanner());
    scanner.set_max_pyramid_levels(1); //try setting to 2, 3...
    frontal_face_detector one_level_detector = dlib::object_detector<image_scanner_type>(scanner, detector.get_overlap_tester(), detector.get_w());

    std::cout<<"End of the Program"<<endl;
    return 0;   
}

并且不,将金字塔级别从 <6> 更改为任何其他值不会有太大帮助,因为 6 不是金字塔级别的限制,而是它在金字塔中的比例:

6 = 5/6

5 = 4/5

...

关于c++ - 如何在 dlib 正面面部检测器中拆分级联级别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38525007/

相关文章:

python - 编译 DLIB 时出错 - 找不到 Boost

用于复制文件 : : confused about relative address (tilde) 的 C++ 代码

c++ - DLIB:具有 halen 数据集的 194 个地标的 train_shape_predictor_ex.exe 给出运行时错误:错误分配

c++ - 编译器切换到禁用 c 风格转换中的 const_cast 语义?

c++ - 数组中的默认值

c++ - 在 dlib 窗口中打印文本

c++ - 将额外数据传递给函数

c++ - dlib 从物体检测器中提取芯片

c++ - C++:在成员变量的指针传递到其他地方的情况下,如何使编译器优化内存访问

c++ - 从字符串中删除前导和尾随空格