-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_classifier.cpp
More file actions
68 lines (56 loc) · 1.59 KB
/
test_classifier.cpp
File metadata and controls
68 lines (56 loc) · 1.59 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
/** Function Headers */
void detectAndDisplay(Mat frame);
/** Global variables */
String human_cascade_name = "human_cascade.xml";
CascadeClassifier human_cascade;
String window_name = "ImageAnnotation";
int main(int argc, char const *argv[])
{
// Check for image to be read
if(argc < 2)
{
cout << "USAGE:" << endl;
cout << argv[0] << " <input_image>" << endl;
return -1;
}
// Load the cascades
if(!human_cascade.load(human_cascade_name))
{
cout << "Error loading human cascade" << endl;
return -1;
}
// Read the image
Mat frame = imread(argv[1]);
namedWindow(window_name);
// Apply the classifiers to the image
detectAndDisplay(frame);
return 0;
}
void detectAndDisplay(Mat frame)
{
std::vector<Rect> humans;
Mat frame_gray;
cvtColor( frame, frame_gray, COLOR_BGR2GRAY );
equalizeHist( frame_gray, frame_gray );
cout << "before detect\n";
// Detect humans
human_cascade.detectMultiScale(frame_gray, humans, 1.1, 2, 0, Size(40, 80));
cout << "after detect " << humans.size() << endl;
for(size_t i = 0; i < humans.size(); i++)
{
Rect r(humans[i].x, humans[i].y, humans[i].width, humans[i].height);
cout << "Human Detected! At..." << endl;
cout << "x - " << humans[i].x << endl;
cout << "y - " << humans[i].y << endl;
cout << "width - " << humans[i].width << endl;
cout << "height - " << humans[i].height << endl;
rectangle(frame, r, Scalar(0, 255, 255), 5);
}
imshow(window_name, frame);
waitKey(0);
}