【问题标题】:Can't get dlib rectangle coords from mmod face detector无法从 mmod 人脸检测器获取 dlib 矩形坐标
【发布时间】:2019-05-11 15:19:18
【问题描述】:

我正在使用 mmod_faces_detection 示例,我正在尝试获取面部矩形坐标但没有运气,这就是我正在做的事情:

std::vector<rectangle> getFacesVec(matrix<rgb_pixel> img)
{
    net_type net;
    deserialize("mmod_human_face_detector.dat") >> net; 

    std::vector<rectangle> r; 
    while(img.size() < 1800*1800)
        pyramid_up(img);

    auto dets = net(img);
    for (auto&& d : dets) {
        r.push_back(d.rect);
    }
    return r;
}

    ....
faces = getFacesVec(img);
for (auto f : faces) {
    cout << "Rect left: " << f.left() << endl;
    cout << "Rect right: " << f.right() << endl;
    cout << "Rect top: " << f.top() << endl;
    cout << "Rect bottom: " << f.bottom() << endl;
    cout << "Rect width: " << f.width() << endl;
    cout << "Rect height: " << f.height() << endl;

    cv::Rect roi(f.left(), f.top() , f.right(), f.bottom());

    cout << "Trying to print cropped face" << endl;
    cout << "X = " << roi.x << " Y = " << roi.y << " Width = " << roi.width << " Height = " << roi.height << endl;
    cv::Mat crop = m(roi);

    sprintf(s, "%d.jpg", i++);
    cv::imwrite(s, crop);
}

而且我的坐标超出了图像范围 像这样: 垫子行数:432 垫子列数:768 左矩形:1068 右方:1914 矩形顶部:480 矩形底部:1325 矩形宽度:847 矩形高度:846

我做错了什么?

【问题讨论】:

    标签: c++ dlib


    【解决方案1】:

    你做了 pyramid_up 来放大输入图像,因此你得到的所有坐标都被放大了。

    您可能希望通过更改 getFacesVec 来查看原始文件

    std::vector<rectangle> getFacesVec(matrix<rgb_pixel> img)
    {
        net_type net;
        deserialize("mmod_human_face_detector.dat") >> net; 
    
        std::vector<rectangle> r; 
        //while(img.size() < 1800*1800)
        //    pyramid_up(img);
    
        auto dets = net(img);
        for (auto&& d : dets) {
            r.push_back(d.rect);
        }
        return r;
    }
    

    【讨论】:

    • 谢谢这是问题所在。
    猜你喜欢
    • 2019-06-18
    • 2017-02-09
    • 2013-05-15
    • 1970-01-01
    • 2017-07-19
    • 2017-05-22
    • 1970-01-01
    • 2013-08-22
    • 2017-01-18
    相关资源
    最近更新 更多