@@ -75,19 +75,26 @@ int main(int argc,char** argv){
75
75
resize (img,img,Size (460 ,460 ), 0 , 0 , INTER_LINEAR_EXACT);
76
76
facemark->getFaces (img,faces);
77
77
vector< vector<Point2f> > shapes;
78
- if (facemark->fit (img,faces,shapes))
79
- {
80
- for ( size_t i = 0 ; i < faces.size (); i++ )
78
+
79
+ // Check if faces detected or not
80
+ // Helps in proper exception handling when writing images to the directories.
81
+ if (faces.size () != 0 ) {
82
+ if (facemark->fit (img,faces,shapes))
81
83
{
82
- cv::rectangle (img,faces[i],Scalar ( 255 , 0 , 0 ));
83
- }
84
- for (unsigned long i=0 ;i<faces.size ();i++){
85
- for (unsigned long k=0 ;k<shapes[i].size ();k++)
86
- cv::circle (img,shapes[i][k],5 ,cv::Scalar (0 ,0 ,255 ),FILLED);
84
+ for ( size_t i = 0 ; i < faces.size (); i++ )
85
+ {
86
+ cv::rectangle (img,faces[i],Scalar ( 255 , 0 , 0 ));
87
+ }
88
+ for (unsigned long i=0 ;i<faces.size ();i++){
89
+ for (unsigned long k=0 ;k<shapes[i].size ();k++)
90
+ cv::circle (img,shapes[i][k],5 ,cv::Scalar (0 ,0 ,255 ),FILLED);
91
+ }
92
+ namedWindow (" Detected_shape" );
93
+ imshow (" Detected_shape" ,img);
94
+ waitKey (0 );
87
95
}
88
- namedWindow (" Detected_shape" );
89
- imshow (" Detected_shape" ,img);
90
- waitKey (0 );
96
+ } else {
97
+ cout << " Faces not detected." << endl;
91
98
}
92
99
return 0 ;
93
- }
100
+ }
0 commit comments