Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

detectMultiscale fails when weights are requested

Hello,

When weights and rejection levels are requested, detectMultiscale always returns a square at the center of the image, regardless of the image.

Minimal working example: (the image I used is available here

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

using namespace std;
using namespace cv;

const string opencvDir = "/usr/share/opencv/haarcascades/";
const string WindowName = "Oscars";

int main() {
    CascadeClassifier faceCascade;
    if (!faceCascade.load(opencvDir + "/haarcascade_frontalface_alt2.xml")) {
        cerr << "failed to load cascade features" << endl;
        return -1;
    }

    Mat im = imread("oscar.jpg");
    Mat gray(im.cols, im.rows, CV_8U);
    cvtColor(im, gray, cv::COLOR_BGR2GRAY);

    double scaleFactor = 1.2;
    int minNeighbors = 2;
    int flags = 0;
    Size minSize = Size(50, 50);
    Size maxSize = Size(150, 150);
    bool outputRejectLevels = true;
    vector<Rect> objects;
    vector<int> rejectLevels;
    std::vector<double> levelWeights;

    // Broken version
    faceCascade.detectMultiScale(gray, objects, rejectLevels, levelWeights,
        scaleFactor, minNeighbors, flags,
        minSize, maxSize, outputRejectLevels);

    Mat preview = im.clone();
    for (Rect obj : objects)
            rectangle(preview, obj, Scalar(255, 0, 0));

    namedWindow(WindowName, WINDOW_AUTOSIZE);   
    imshow(WindowName, preview);
    waitKey(0);

    objects.clear();
    rejectLevels.clear();
    levelWeights.clear();

    // Working version
    faceCascade.detectMultiScale(gray, objects, scaleFactor, minNeighbors, 
        flags, minSize, maxSize);

    preview = im.clone();
    for (Rect obj : objects)
            rectangle(preview, obj, Scalar(255, 0, 0));
    namedWindow(WindowName, WINDOW_AUTOSIZE);   
    imshow(WindowName, preview);
    waitKey(0);

    return 0;    
}

detectMultiscale fails when weights are requested

Hello,

When weights and rejection levels are requested, detectMultiscale always returns a square at the center of the image, regardless of the image.

Minimal working example: (the image I used is available here

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

using namespace std;
using namespace cv;

const string opencvDir = "/usr/share/opencv/haarcascades/";
const string WindowName = "Oscars";

int main() {
    CascadeClassifier faceCascade;
    if (!faceCascade.load(opencvDir + "/haarcascade_frontalface_alt2.xml")) {
        cerr << "failed to load cascade features" << endl;
        return -1;
    }

    Mat im = imread("oscar.jpg");
    Mat gray(im.cols, im.rows, CV_8U);
    cvtColor(im, gray, cv::COLOR_BGR2GRAY);

    double scaleFactor = 1.2;
    int minNeighbors = 2;
    int flags = 0;
    Size minSize = Size(50, 50);
    Size maxSize = Size(150, 150);
    bool outputRejectLevels = true;
    vector<Rect> objects;
    vector<int> rejectLevels;
    std::vector<double> levelWeights;

    // Broken version
    faceCascade.detectMultiScale(gray, objects, rejectLevels, levelWeights,
        scaleFactor, minNeighbors, flags,
        minSize, maxSize, outputRejectLevels);

    Mat preview = im.clone();
    for (Rect obj : objects)
            rectangle(preview, obj, Scalar(255, 0, 0));

    namedWindow(WindowName, WINDOW_AUTOSIZE);   
    imshow(WindowName, preview);
    waitKey(0);

    objects.clear();
    rejectLevels.clear();
    levelWeights.clear();

    // Working version
    faceCascade.detectMultiScale(gray, objects, scaleFactor, minNeighbors, 
        flags, minSize, maxSize);

    preview = im.clone();
    for (Rect obj : objects)
            rectangle(preview, obj, Scalar(255, 0, 0));
    namedWindow(WindowName, WINDOW_AUTOSIZE);   
    imshow(WindowName, preview);
    waitKey(0);

    return 0;    
}

detectMultiscale fails when weights are requested

Hello,

When weights and rejection levels are requested, detectMultiscale always returns a square at the center of the image, regardless of the image.

Minimal working example: (the image I used is available here)

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

using namespace std;
using namespace cv;

const string opencvDir = "/usr/share/opencv/haarcascades/";
const string WindowName = "Oscars";

int main() {
    CascadeClassifier faceCascade;
    if (!faceCascade.load(opencvDir + "/haarcascade_frontalface_alt2.xml")) {
        cerr << "failed to load cascade features" << endl;
        return -1;
    }

    Mat im = imread("oscar.jpg");
    Mat gray(im.cols, im.rows, CV_8U);
    cvtColor(im, gray, cv::COLOR_BGR2GRAY);

    double scaleFactor = 1.2;
    int minNeighbors = 2;
    int flags = 0;
    Size minSize = Size(50, 50);
    Size maxSize = Size(150, 150);
    bool outputRejectLevels = true;
    vector<Rect> objects;
    vector<int> rejectLevels;
    std::vector<double> levelWeights;

    // Broken version
    faceCascade.detectMultiScale(gray, objects, rejectLevels, levelWeights,
        scaleFactor, minNeighbors, flags,
        minSize, maxSize, outputRejectLevels);

    Mat preview = im.clone();
    for (Rect obj : objects)
            rectangle(preview, obj, Scalar(255, 0, 0));

    namedWindow(WindowName, WINDOW_AUTOSIZE);   
    imshow(WindowName, preview);
    waitKey(0);

    objects.clear();
    rejectLevels.clear();
    levelWeights.clear();

    // Working version
    faceCascade.detectMultiScale(gray, objects, scaleFactor, minNeighbors, 
        flags, minSize, maxSize);

    preview = im.clone();
    for (Rect obj : objects)
            rectangle(preview, obj, Scalar(255, 0, 0));
    namedWindow(WindowName, WINDOW_AUTOSIZE);   
    imshow(WindowName, preview);
    waitKey(0);

    return 0;    
}

The version of opencv I use is 3.1.0.r107.g1cd3c6f. It also failed with one of the earlier revisions. Could anyone just run the test above and confirm that there is indeed a bug?

detectMultiscale fails when weights are requested

Hello,

When weights and rejection levels are requested, detectMultiscale always returns a square at the center of the image, regardless of the image.

Minimal working example: (the image I used is available here)

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

using namespace std;
using namespace cv;

const string opencvDir = "/usr/share/opencv/haarcascades/";
const string WindowName = "Oscars";

int main() {
    CascadeClassifier faceCascade;
    if (!faceCascade.load(opencvDir + "/haarcascade_frontalface_alt2.xml")) {
        cerr << "failed to load cascade features" << endl;
        return -1;
    }

    Mat im = imread("oscar.jpg");
    Mat gray(im.cols, im.rows, CV_8U);
    cvtColor(im, gray, cv::COLOR_BGR2GRAY);

    double scaleFactor = 1.2;
    int minNeighbors = 2;
    int flags = 0;
    Size minSize = Size(50, 50);
    Size maxSize = Size(150, 150);
    bool outputRejectLevels = true;
    vector<Rect> objects;
    vector<int> rejectLevels;
    std::vector<double> levelWeights;

    // Broken version
    faceCascade.detectMultiScale(gray, objects, rejectLevels, levelWeights,
        scaleFactor, minNeighbors, flags,
        minSize, maxSize, outputRejectLevels);

    Mat preview = im.clone();
    for (Rect obj : objects)
            rectangle(preview, obj, Scalar(255, 0, 0));

    namedWindow(WindowName, WINDOW_AUTOSIZE);   
    imshow(WindowName, preview);
    waitKey(0);

    objects.clear();
    rejectLevels.clear();
    levelWeights.clear();

    // Working version
    faceCascade.detectMultiScale(gray, objects, scaleFactor, minNeighbors, 
        flags, minSize, maxSize);

    preview = im.clone();
    for (Rect obj : objects)
            rectangle(preview, obj, Scalar(255, 0, 0));
    namedWindow(WindowName, WINDOW_AUTOSIZE);   
    imshow(WindowName, preview);
    waitKey(0);

    return 0;    
}

The version of opencv I use is 3.1.0.r107.g1cd3c6f. It also failed with one of the earlier revisions. Could anyone just run the test above and confirm that there is indeed a bug?


EDIT: bug report opened here