1 | initial version |
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);
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 x 74 from (428, 562)]
22 107.957 [75 x 75 from (32, 434)]
22 107.812 [64 x 64 from (580, 696)]
22 108.041 [65 x 65 from (39, 697)]
22 107.611 [62 x 62 from (437, 701)]
22 109.317 [60 x 60 from (311, 708)]
2 | No.2 Revision |
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);
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 x 74 from (428, 562)]
22 107.957 [75 x 75 from (32, 434)]
22 107.812 [64 x 64 from (580, 696)]
22 108.041 [65 x 65 from (39, 697)]
22 107.611 [62 x 62 from (437, 701)]
22 109.317 [60 x 60 from (311, 708)]