-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
53 lines (41 loc) · 1.21 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
#include<iostream>
#include<stdlib.h>
#include<opencv2\\objdetect\\objdetect.hpp>
#include<opencv2\\imgproc\\imgproc.hpp>
#include<opencv2\\highgui\\highgui.hpp>
#include<string>
using namespace cv;
int main()
{
CascadeClassifier faceDetection;
if (!faceDetection.load("C:\\Users\\Scientist\\Downloads\\Programs\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_default.xml"))
{
std::cout << "\n File is not loaded Properly";
exit(0); // stdlib.h
}
std :: string path;
std::cout << "\nEnter the path to the image for face detection: ";
cin.getline(path, 100);
Mat img = imread(path, CV_LOAD_IMAGE_UNCHANGED);
if (img.empty())
{
std::cout << "Image is not loaded properly";
}
else
{
std::cout << "\nGot the Image!\n";
std::cout << "Image in Making !!!! \n";
vector<Rect> faces; //Creating a Vector
faceDetection.detectMultiScale(img, faces); //detecting Here
for (int i = 0; i < faces.size(); i++)
{
Point pt1(faces[i].x, faces[i].y);
Point pt2((faces[i].x + faces[i].height), (faces[i].y + faces[i].width));
rectangle(img, pt1, pt2, Scalar(0, 0, 255), 2, 8, 0);
imwrite("C:\\gs\\output.jpg", img);
std::cout << "\nFace Detected Master!\n";
system("pause");
}
} // Else closed
return 0;
}