无法从mmod人脸检测器获取dlib矩形坐标

时间:2018-12-10 17:14:40

标签: c++ dlib

我正在使用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

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

您做了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;
}