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
I was running the tests last week, and noticed very strange behaviour, but havent got the time for the moment to dig in. This behaviour was NOT there before, because I have used the functionality succesfully in the past. By the end of the week I might be able to do more tests and I will keep you up to date!
Thank you for your feedback. Just for the sake of clarity: by revision I meant earlier commit of the 3.1.0 version, not older version.