1
votes

I'm using the the mmod_faces_detection example and I'm trying to get the faces rectangles coordinates with no luck, here is what I'm doing:

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

and I'm getting coords out of the image scope like this: Mat rows: 432 Mat cols: 768 Rect left: 1068 Rect right: 1914 Rect top: 480 Rect bottom: 1325 Rect width: 847 Rect height: 846

What's I'm doing wrong?

1

1 Answers

1
votes

You did pyramid_up to scale up an input image, thus all the coordinate you got are scaled up.

You may want to see original one by changing 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;
}