From dab507e32a8760a5a5a5dc052236bf3cde395953 Mon Sep 17 00:00:00 2001 From: Gary Bradski Date: Wed, 1 Dec 2010 19:50:46 +0000 Subject: [PATCH] put in a bunch of checks, outputs and docs --- samples/c/facedetect.cpp | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/samples/c/facedetect.cpp b/samples/c/facedetect.cpp index 5b8c24a..4fbe055 100644 --- a/samples/c/facedetect.cpp +++ b/samples/c/facedetect.cpp @@ -8,6 +8,17 @@ using namespace std; 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=]\n" + " [--nested-cascade[=nested_cascade_path]]\n" + " [--scale=\n" + " [filename|camera_index]\n" << endl;; +} + void detectAndDraw( Mat& img, CascadeClassifier& cascade, CascadeClassifier& nestedCascade, double scale); @@ -29,13 +40,18 @@ int main( int argc, const char** argv ) size_t nestedCascadeOptLen = nestedCascadeOpt.length(); String inputName; + help(); CascadeClassifier cascade, nestedCascade; double scale = 1; for( int i = 1; i < argc; i++ ) { + cout << "Processing " << i << " " << argv[i] << endl; if( cascadeOpt.compare( 0, cascadeOptLen, argv[i], cascadeOptLen ) == 0 ) + { cascadeName.assign( argv[i] + cascadeOptLen ); + cout << " from which we have cascadeName= " << cascadeName << endl; + } else if( nestedCascadeOpt.compare( 0, nestedCascadeOptLen, argv[i], nestedCascadeOptLen ) == 0 ) { if( argv[i][nestedCascadeOpt.length()] == '=' ) @@ -47,6 +63,7 @@ int main( int argc, const char** argv ) { if( !sscanf( argv[i] + scaleOpt.length(), "%lf", &scale ) || scale < 1 ) scale = 1; + cout << " from which we read scale = " << scale << endl; } else if( argv[i][0] == '-' ) { @@ -59,28 +76,39 @@ int main( int argc, const char** argv ) if( !cascade.load( cascadeName ) ) { cerr << "ERROR: Could not load classifier cascade" << endl; - cerr << "Usage: facedetect [--cascade=\"\"]\n" - " [--nested-cascade[=\"nested_cascade_path\"]]\n" + cerr << "Usage: facedetect [--cascade=]\n" + " [--nested-cascade[=nested_cascade_path]]\n" " [--scale[=\n" - " [filename|camera_index]\n" ; + " [filename|camera_index]\n" << endl ; return -1; } if( inputName.empty() || (isdigit(inputName.c_str()[0]) && inputName.c_str()[1] == '\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() ) { image = imread( inputName, 1 ); if( image.empty() ) + { capture = cvCaptureFromAVI( inputName.c_str() ); - } + if(!capture) cout << "Capture from AVI didn't work" << endl; + } + } else + { image = imread( "lena.jpg", 1 ); + if(image.empty()) cout << "Couldn't read lena.jpg" << endl; + } cvNamedWindow( "result", 1 ); if( capture ) { + cout << "In capture ..." << endl; for(;;) { IplImage* iplImg = cvQueryFrame( capture ); @@ -104,6 +132,7 @@ _cleanup_: } else { + cout << "In image read" << endl; if( !image.empty() ) { detectAndDraw( image, cascade, nestedCascade, scale ); @@ -132,6 +161,10 @@ _cleanup_: if( c == 27 || c == 'q' || c == 'Q' ) break; } + else + { + cerr << "Aw snap, couldn't read image " << buf << endl; + } } fclose(f); } -- 2.7.4