Ask Your Question
0

detectMultiScale with outputRejectLevels true doesn't return anything?

asked 2016-06-04 11:06:06 -0600

nonlin gravatar image

updated 2016-06-05 10:54:35 -0600

with min_neighbours to 2 and output reject levels to true the detectMultiScale doesn't seem to return any faces. Left it running for 20 min and it never finished.

However, if I change min_neighbours to 0 then it will return a crazy amount of faces, I let it run till 150000 but I stopped it at that point.

I read only that a bug was found relating to this? Not sure if it got fixed or if I'm doing something wrong? I have the latest opencv source compiled 3.1.

On a slightly separate note, the reason for me wanting to use the override is so that I can try and find the best image out of multiple images.

Extra Details:

Windows 10 x64

Opencv 3.1 x64 dlls.

Preview of the code.

const double scale_factor = 1.1;
const int min_neighbours = 2;
const int flags = CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_CANNY_PRUNING | CV_HAAR_SCALE_IMAGE;
const Size min_size = Size(48, 48);
const Size max_size = Size();
std::vector<int> rejectLevels;
std::vector<double> levelWeights;
bool outputRejectLevels = true;
cv::Mat crop;
cv::Mat res;
cv::Mat largestFile;
if (cascade.empty() || image.empty()) {
    return Rect();
}

std::vector<Rect> faces;
    //old working code, now commented out
//cascade.detectMultiScale(image, faces, scale_factor, min_neighbours, flags, min_size, max_size);
//current attempt at getting weights and reject levels. 
    cascade.detectMultiScale(image, faces, rejectLevels, levelWeights, scale_factor, min_neighbours, flags, min_size, max_size, outputRejectLevels);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-06-05 02:21:44 -0600

berak gravatar image

updated 2016-06-05 02:32:49 -0600

if you want to use the overload with rejectLevels and weights, take care to get all other default args right, like minSize and maxSize. (you don't show your code, but i rather guess, some problem with the params is the reason for your failure)

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main()
{
    Mat im = imread("c:/p/data/img/people.jpg");
    // resize(im,im,Size(), 4,4); // my demo img is very small

    cv::imshow("src", im);
    cv::waitKey(1);

    String face_cascade_name = "c:/p/opencv/data/haarcascades/haarcascade_frontalface_alt.xml";
    CascadeClassifier face_cascade(face_cascade_name);

    std::vector<Rect> faces;
    Mat frame_gray;

    cvtColor( im, frame_gray, COLOR_BGR2GRAY );
    equalizeHist( frame_gray, frame_gray );

    //-- Detect faces
    face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CASCADE_SCALE_IMAGE, Size(30, 30) );
    cerr << faces.size() << " objects detected." << endl;

    for ( size_t i = 0; i < faces.size(); i++ )
    {
        rectangle( im, faces[i], Scalar( 255, 0, 255 ), 4, 8, 0 );
    }

    cv::imshow("dst", im);
    cv::waitKey(1);

    //-- Detect faces, now with weights
    vector<int> rejectLevels;
    vector<double> rejectWeights;
    face_cascade.detectMultiScale( frame_gray, faces, rejectLevels, rejectWeights,  1.1, 2, 0|CASCADE_SCALE_IMAGE, Size(30, 30), Size(90, 90), true );
    cerr << faces.size() << " objects detected." << endl;

    for ( size_t i = 0; i < faces.size(); i++ )
    {
        rectangle( im, faces[i], Scalar( 0, 255, 0 ), 2, 8, 0 );
        cerr << rejectLevels[i] << " " << rejectWeights[i] << "\t" << faces[i] << endl;
    }

    cv::imshow("dst_weights", im);
    cv::waitKey();
    return 0;
}
35 objects detected.
35 objects detected.
22 108.387      [67 x 67 from (39, 163)]
22 108.109      [60 x 60 from (36, 300)]
22 108.413      [61 x 61 from (568, 29)]
22 107.246      [48 x 48 from (766, 37)]
22 108.523      [54 x 54 from (858, 154)]
22 108.57       [68 x 68 from (705, 161)]
22 107.547      [65 x 65 from (563, 155)]
22 107.765      [65 x 65 from (315, 161)]
22 107.261      [66 x 66 from (179, 297)]
22 107.699      [66 x 66 from (426, 310)]
22 108.767      [72 x 72 from (292, 299)]
22 106.998      [72 x 72 from (829, 303)]
22 107.397      [74 x 74 from (24, 24)]
22 108.513      [71 x 71 from (159, 23)]
22 108.235      [72 x 72 from (433, 25)]
22 108.465      [74 x 74 from (699, 25)]
22 108.23       [74 x 74 from (305, 31)]
22 107.797      [84 x 84 from (698, 299)]
22 107.872      [58 x 58 from (156, 429)]
22 107.958      [63 x 63 from (638, 412)]
22 106.754      [64 x 64 from (345, 418)]
22 108.119      [63 x 63 from (298, 432)]
22 107.301      [59 x 59 from (299, 560)]
22 106.449      [66 x 66 from (724, 432)]
22 108.637      [68 x 68 from (566, 564)]
22 107.188      [68 x 68 from (838, 441)]
22 108.433      [69 x 69 from (700, 561)]
22 109.369      [68 x 68 from (572, 425)]
22 108.901      [67 x 67 from (164, 564)]
22 108.015      [74 ...
(more)
edit flag offensive delete link more

Comments

Edit main post to show some code.

nonlin gravatar imagenonlin ( 2016-06-05 10:48:27 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-06-04 11:06:06 -0600

Seen: 1,724 times

Last updated: Jun 05 '16