int main(int argc, char** argv){ IplImage* motion = 0; CvCapture* capture = 0; short frameCount = 0; // Info del clasificador CvNormalBayesClassifier *nbayes; char default_data_filename[] = "./train-data.txt"; char* data_filename = default_data_filename; build_nbayes_classifier(data_filename, &nbayes); if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 ); else if( argc == 2 ) capture = cvCaptureFromFile( argv[1] ); if( capture ){ double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS); std::cout << "FPS : " << fps << std::endl; cvNamedWindow( "Original", 1 ); cvNamedWindow( "Motion", 1 ); for(;;){ IplImage* image = cvQueryFrame( capture ); if( !image ){ break; } if( !motion ){ motion = cvCreateImage( cvSize(image->width,image->height), 8, 3 ); cvZero( motion ); motion->origin = image->origin; } ++frameCount; if(frameCount > 7 || 1){ frameCount = 0; initMatrix(relevanceVector,51); update_mhi( image, motion, MOTION_HISTORY_SENSITIVITY, frameCount); computeVectors(image, motion, 128, 96); classify(nbayes); } cvShowImage( "Original", image); cvShowImage( "Motion", motion ); if( cvWaitKey(10) >= 0 ) break; } cvReleaseCapture( &capture ); cvDestroyWindow( "Original" ); cvDestroyWindow( "Motion" ); } return 0; }
int main( int argc, char *argv[] ) { char* filename_to_save = 0; char* filename_to_load = 0; char default_data_filename[] = "./letter-recognition.data"; char* data_filename = default_data_filename; int method = 0; int i; for( i = 1; i < argc; i++ ) { if( strcmp(argv[i],"-data") == 0 ) // flag "-data letter_recognition.xml" { i++; data_filename = argv[i]; } else if( strcmp(argv[i],"-save") == 0 ) // flag "-save filename.xml" { i++; filename_to_save = argv[i]; } else if( strcmp(argv[i],"-load") == 0) // flag "-load filename.xml" { i++; filename_to_load = argv[i]; } else if( strcmp(argv[i],"-boost") == 0) { method = 1; } else if( strcmp(argv[i],"-mlp") == 0 ) { method = 2; } else if ( strcmp(argv[i], "-knearest") == 0) { method = 3; } else if ( strcmp(argv[i], "-nbayes") == 0) { method = 4; } else if ( strcmp(argv[i], "-svm") == 0) { method = 5; } else break; } if( i < argc || (method == 0 ? build_rtrees_classifier( data_filename, filename_to_save, filename_to_load ) : method == 1 ? build_boost_classifier( data_filename, filename_to_save, filename_to_load ) : method == 2 ? build_mlp_classifier( data_filename, filename_to_save, filename_to_load ) : method == 3 ? build_knearest_classifier( data_filename, 10 ) : method == 4 ? build_nbayes_classifier( data_filename) : method == 5 ? build_svm_classifier( data_filename ): -1) < 0) { help(); } return 0; }