@@ -45,12 +45,15 @@ int main (int argc, const char * argv[])
45
45
cap >> frame;
46
46
if (frame.empty ())
47
47
break ;
48
+ int height;
49
+ height=((frame.size ().height )*800 )/frame.size ().width ;
50
+ resize (frame, frame, Size (800 , height));
48
51
frame1=detect_people (frame);
49
52
faces=detect_faces (frame);
50
53
frame2=draw_faces (frame1, faces); /* draw circle around faces*/
51
54
label=recognize_face (frame,faces);
52
55
put_label_on_face (frame,faces,label);
53
- imshow (" human_detection and face_detction " , frame);
56
+ imshow (" human_detection and face_detection " , frame);
54
57
waitKey (1 );
55
58
}
56
59
return 0 ;
@@ -60,9 +63,8 @@ Mat detect_people( Mat frame)
60
63
{
61
64
HOGDescriptor hog;
62
65
hog.setSVMDetector (HOGDescriptor::getDefaultPeopleDetector ());
63
- /* resize(frame, frame, Size(),0.5,0.5);*/
64
66
vector<Rect > detected, detected_filtered;
65
- hog.detectMultiScale (frame, detected, 0 , Size (8 ,8 ), Size (32 , 32 ), 1.05 , 2 );
67
+ hog.detectMultiScale (frame, detected, 0 , Size (8 ,8 ), Size (16 , 16 ), 1.06 , 2 );
66
68
size_t i, j;
67
69
/* checking for the distinctly detected human in a frame*/
68
70
for (i=0 ; i<detected.size (); i++)
@@ -82,7 +84,7 @@ Mat detect_people( Mat frame)
82
84
r.width = cvRound (r.width *0.8 );
83
85
r.y += cvRound (r.height *0.07 );
84
86
r.height = cvRound (r.height *0.8 );
85
- rectangle (frame, r.tl (), r.br (), Scalar (0 ,255 , 0 ), 3 );
87
+ rectangle (frame, r.tl (), r.br (), Scalar (0 ,0 , 255 ), 2 );
86
88
}
87
89
88
90
return frame;
@@ -93,11 +95,9 @@ vector<Rect> detect_faces( Mat frame)
93
95
vector<Rect > faces;
94
96
Mat frame_gray;
95
97
cvtColor ( frame, frame_gray, COLOR_BGR2GRAY ); /* converting input image in grayscale form*/
96
- equalizeHist ( frame_gray, frame_gray );
97
-
98
- /* resize(frame_gray, frame_gray, Size(),0.5,0.5);*/
98
+ // equalizeHist( frame_gray, frame_gray );
99
99
/* Detecting faces*/
100
- face_cascade1.detectMultiScale ( frame_gray, faces, 1.2 , 2 , 0 |CASCADE_SCALE_IMAGE, Size (30 , 30 ) );
100
+ face_cascade1.detectMultiScale ( frame_gray, faces, 1.1 , 2 , 0 |CASCADE_SCALE_IMAGE, Size (20 , 20 ) );
101
101
return faces;
102
102
}
103
103
@@ -106,7 +106,7 @@ Mat draw_faces(Mat frame1, vector<Rect> faces)
106
106
for ( size_t i = 0 ; i < faces.size (); i++ )
107
107
{
108
108
/* Drawing rectangle around faces*/
109
- rectangle (frame1, Point (faces[i].x , faces[i].y ), Point (faces[i].x + faces[i].width , faces[i].y + faces[i].height ), Scalar (0 , 250 , 255 ), 2 , LINE_8, 0 );
109
+ rectangle (frame1, Point (faces[i].x , faces[i].y ), Point (faces[i].x + faces[i].width , faces[i].y + faces[i].height ), Scalar (0 , 255 , 0 ), 2 , LINE_8, 0 );
110
110
}
111
111
return frame1;
112
112
@@ -121,8 +121,8 @@ int* recognize_face(Mat frame, vector<Rect> faces)
121
121
Mat frame_original_grayscale;
122
122
for ( size_t i = 0 ; i < faces.size (); i++ )
123
123
{
124
- cv:: cvtColor ( frame, frame_original_grayscale, COLOR_BGR2GRAY ); /* converting frame to grayscale*/
125
- equalizeHist (frame_original_grayscale,frame_original_grayscale);
124
+ cvtColor ( frame, frame_original_grayscale, COLOR_BGR2GRAY ); /* converting frame to grayscale*/
125
+ // equalizeHist(frame_original_grayscale,frame_original_grayscale);
126
126
127
127
/* recognizing faces to predict label and confidence factor*/
128
128
recognizer->predict (frame_original_grayscale, a,b);
@@ -144,7 +144,7 @@ Mat put_label_on_face(Mat frame,vector<Rect> faces,int* label)
144
144
string str_label = ss.str ();
145
145
/* writing label on the image frame*/
146
146
/* putText(InputOutputArray img, const String& text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=LINE_8, bool bottomLeftOrigin=false )*/
147
- putText (frame, str_label, Point (faces[j].x , faces[j].y ), FONT_HERSHEY_SIMPLEX,1 , Scalar (0 , 0 ,255 ), 2 );
147
+ putText (frame, str_label, Point (faces[j].x , faces[j].y ), FONT_HERSHEY_SIMPLEX,1 , Scalar (255 , 255 ,255 ), 2 );
148
148
}
149
149
return frame;
150
150
}
0 commit comments