问题
I'm working on objects detection with cascade classifier on OpenCV 3.1 and VC++ 2015. I want to force the cascade to detect only one object for each image and I want to get its accuracy score. For that, I tried to use the undocumented prototype of the method CascadeClassifier::detectMultiScale with reject levels. The documented version works good. But the version with reject levels still executing for a long time without giving any result. this is my source code below.
#include "stdafx.h"
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
String plate_cascade_name = "eu.xml";
int main(int argc, char **argv) {
CascadeClassifier cascade;
const float scale_factor(1.2f);
const int min_neighbors(3);
if (cascade.load(plate_cascade_name)) {
Mat img = imread("c:/users/anis/desktop/voituretn/voiture1.jpg", CV_LOAD_IMAGE_GRAYSCALE);
equalizeHist(img, img);
vector<Rect> objs;
vector<int> reject_levels;
vector<double> level_weights;
cascade.detectMultiScale(img, objs, reject_levels, level_weights, scale_factor, min_neighbors, 0, Size(60, 13), img.size(), true);
//cascade.detectMultiScale(img, objs, scale_factor, min_neighbors, 0, Size(60, 13), img.size());
Mat img_color = imread("c:/users/anis/desktop/voituretn/voiture1.jpg", CV_LOAD_IMAGE_COLOR);
for (int n = 0; n < objs.size(); n++) {
rectangle(img_color, objs[n], Scalar(255, 0, 0), 8);
// putText(img_color, std::to_string(level_weights[n]),Point(objs[n].x, objs[n].y), 1, 1, Scalar(0, 0, 255));
}
imshow("VJ Face Detector", img_color);
waitKey(0);
}
return 0;
}
来源:https://stackoverflow.com/questions/36260899/cascade-classifier-detectmultiscale-with-reject-levels