-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhaar_test.cpp
43 lines (33 loc) · 1.13 KB
/
haar_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <cstdio>
using namespace std;
using namespace cv;
int main(int argc, char ** argv)
{
Mat image;
if (argc < 2) {
cerr << "No image provided." << endl;
return -1;
}
image = imread(argv[1], CV_LOAD_IMAGE_COLOR);
namedWindow("window1", 1);
imshow("window1", image);
// Load Face cascade (.xml file)
CascadeClassifier face_cascade;
face_cascade.load("./haarcascade_frontalface_alt2.xml");
// Detect faces
std::vector<Rect> faces;
face_cascade.detectMultiScale(image, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30));
// Draw circles on the detected faces
for(int i = 0; i < faces.size(); i++)
{
Point center(faces[i].x + faces[i].width * 0.5, faces[i].y + faces[i].height * 0.5);
ellipse(image, center, Size(faces[i].width * 0.5, faces[i].height * 0.5), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);
}
imshow("Detected Face", image);
waitKey(0);
return 0;
}