1 | #include "opencv2/objdetect/objdetect.hpp"
|
2 | #include "opencv2/highgui/highgui.hpp"
|
3 | #include "opencv2/imgproc/imgproc.hpp"
|
4 |
|
5 | #include <iostream>
|
6 | #include <stdio.h>
|
7 |
|
8 | using namespace std;
|
9 | using namespace cv;
|
10 |
|
11 |
|
12 | String cascadeName = "haarcascade_frontalface_alt.xml";
|
13 |
|
14 | int main( int argc, const char** argv ) {
|
15 | CvCapture* capture = 0;
|
16 | CascadeClassifier cascade;
|
17 |
|
18 | String inputName;
|
19 | inputName.assign( argv[1] );
|
20 |
|
21 | if ( !cascade.load( cascadeName ) ) {
|
22 | cerr << "Could not load cascade." << endl;
|
23 | return -1;
|
24 | }
|
25 |
|
26 | Mat image = imread( inputName, 1 );
|
27 | Mat gray;
|
28 |
|
29 | cvtColor( image, image, CV_BGR2GRAY );
|
30 | equalizeHist( image, image );
|
31 |
|
32 | vector<Rect> faces;
|
33 | vector<int> levels;
|
34 | vector<double> weights;
|
35 |
|
36 | cascade.detectMultiScale( image, faces, levels, weights, 1.1,
|
37 | 3, CV_HAAR_SCALE_IMAGE, Size(30,30), Size(0,0), true);
|
38 |
|
39 | vector<double>::const_iterator w = weights.begin();
|
40 | vector<int>::const_iterator l = levels.begin();
|
41 | vector<Rect>::const_iterator r = faces.begin();
|
42 |
|
43 | for( ; r != faces.end(); r++, w++, l++ ) {
|
44 | int x1 = r->x, y1 = r->y;
|
45 | int x2 = x1 + r->width-1, y2 = y1 + r->height - 1;
|
46 |
|
47 | cout << x1 << " " << y1 << " " << x2 << " " << y2;
|
48 | cout << " " << (*w) << " " << (*l);
|
49 | cout << endl;
|
50 | }
|
51 |
|
52 | return 0;
|
53 | }
|
54 |
|