Commit dab507e3 authored by Gary Bradski's avatar Gary Bradski

put in a bunch of checks, outputs and docs

parent cc537741
...@@ -8,6 +8,17 @@ ...@@ -8,6 +8,17 @@
using namespace std; using namespace std;
using namespace cv; using namespace cv;
void help()
{
cout << "\n This program demonstrates the haar cascade recognizer\n"
"this classifier can recognize many ~rigid objects, it's most known use is for faces.\n"
"Usage:\n"
"./facedetect [--cascade=<cascade_path>]\n"
" [--nested-cascade[=nested_cascade_path]]\n"
" [--scale=<image scale greater or equal to 1>\n"
" [filename|camera_index]\n" << endl;;
}
void detectAndDraw( Mat& img, void detectAndDraw( Mat& img,
CascadeClassifier& cascade, CascadeClassifier& nestedCascade, CascadeClassifier& cascade, CascadeClassifier& nestedCascade,
double scale); double scale);
...@@ -29,13 +40,18 @@ int main( int argc, const char** argv ) ...@@ -29,13 +40,18 @@ int main( int argc, const char** argv )
size_t nestedCascadeOptLen = nestedCascadeOpt.length(); size_t nestedCascadeOptLen = nestedCascadeOpt.length();
String inputName; String inputName;
help();
CascadeClassifier cascade, nestedCascade; CascadeClassifier cascade, nestedCascade;
double scale = 1; double scale = 1;
for( int i = 1; i < argc; i++ ) for( int i = 1; i < argc; i++ )
{ {
cout << "Processing " << i << " " << argv[i] << endl;
if( cascadeOpt.compare( 0, cascadeOptLen, argv[i], cascadeOptLen ) == 0 ) if( cascadeOpt.compare( 0, cascadeOptLen, argv[i], cascadeOptLen ) == 0 )
{
cascadeName.assign( argv[i] + cascadeOptLen ); cascadeName.assign( argv[i] + cascadeOptLen );
cout << " from which we have cascadeName= " << cascadeName << endl;
}
else if( nestedCascadeOpt.compare( 0, nestedCascadeOptLen, argv[i], nestedCascadeOptLen ) == 0 ) else if( nestedCascadeOpt.compare( 0, nestedCascadeOptLen, argv[i], nestedCascadeOptLen ) == 0 )
{ {
if( argv[i][nestedCascadeOpt.length()] == '=' ) if( argv[i][nestedCascadeOpt.length()] == '=' )
...@@ -47,6 +63,7 @@ int main( int argc, const char** argv ) ...@@ -47,6 +63,7 @@ int main( int argc, const char** argv )
{ {
if( !sscanf( argv[i] + scaleOpt.length(), "%lf", &scale ) || scale < 1 ) if( !sscanf( argv[i] + scaleOpt.length(), "%lf", &scale ) || scale < 1 )
scale = 1; scale = 1;
cout << " from which we read scale = " << scale << endl;
} }
else if( argv[i][0] == '-' ) else if( argv[i][0] == '-' )
{ {
...@@ -59,28 +76,39 @@ int main( int argc, const char** argv ) ...@@ -59,28 +76,39 @@ int main( int argc, const char** argv )
if( !cascade.load( cascadeName ) ) if( !cascade.load( cascadeName ) )
{ {
cerr << "ERROR: Could not load classifier cascade" << endl; cerr << "ERROR: Could not load classifier cascade" << endl;
cerr << "Usage: facedetect [--cascade=\"<cascade_path>\"]\n" cerr << "Usage: facedetect [--cascade=<cascade_path>]\n"
" [--nested-cascade[=\"nested_cascade_path\"]]\n" " [--nested-cascade[=nested_cascade_path]]\n"
" [--scale[=<image scale>\n" " [--scale[=<image scale>\n"
" [filename|camera_index]\n" ; " [filename|camera_index]\n" << endl ;
return -1; return -1;
} }
if( inputName.empty() || (isdigit(inputName.c_str()[0]) && inputName.c_str()[1] == '\0') ) if( inputName.empty() || (isdigit(inputName.c_str()[0]) && inputName.c_str()[1] == '\0') )
{
capture = cvCaptureFromCAM( inputName.empty() ? 0 : inputName.c_str()[0] - '0' ); capture = cvCaptureFromCAM( inputName.empty() ? 0 : inputName.c_str()[0] - '0' );
int c = inputName.empty() ? 0 : inputName.c_str()[0] - '0' ;
if(!capture) cout << "Capture from CAM " << c << " didn't work" << endl;
}
else if( inputName.size() ) else if( inputName.size() )
{ {
image = imread( inputName, 1 ); image = imread( inputName, 1 );
if( image.empty() ) if( image.empty() )
{
capture = cvCaptureFromAVI( inputName.c_str() ); capture = cvCaptureFromAVI( inputName.c_str() );
} if(!capture) cout << "Capture from AVI didn't work" << endl;
}
}
else else
{
image = imread( "lena.jpg", 1 ); image = imread( "lena.jpg", 1 );
if(image.empty()) cout << "Couldn't read lena.jpg" << endl;
}
cvNamedWindow( "result", 1 ); cvNamedWindow( "result", 1 );
if( capture ) if( capture )
{ {
cout << "In capture ..." << endl;
for(;;) for(;;)
{ {
IplImage* iplImg = cvQueryFrame( capture ); IplImage* iplImg = cvQueryFrame( capture );
...@@ -104,6 +132,7 @@ _cleanup_: ...@@ -104,6 +132,7 @@ _cleanup_:
} }
else else
{ {
cout << "In image read" << endl;
if( !image.empty() ) if( !image.empty() )
{ {
detectAndDraw( image, cascade, nestedCascade, scale ); detectAndDraw( image, cascade, nestedCascade, scale );
...@@ -132,6 +161,10 @@ _cleanup_: ...@@ -132,6 +161,10 @@ _cleanup_:
if( c == 27 || c == 'q' || c == 'Q' ) if( c == 27 || c == 'q' || c == 'Q' )
break; break;
} }
else
{
cerr << "Aw snap, couldn't read image " << buf << endl;
}
} }
fclose(f); fclose(f);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment