#include "opencv2/objdetect/objdetect.hpp" #include "opencv2/highgui/highgui.hpp" #include using namespace cv; void help() { printf( "This program demonstrated the use of the latentSVM detector.\n" "It reads in a trained object model and then uses that to detect the object in an image\n" "Call:\n" "./latentsvmdetect [ total; i++ ) { CvObjectDetection detection = *(CvObjectDetection*)cvGetSeqElem( detections, i ); CvRect bounding_box = detection.rect; cvRectangle( image, cvPoint(bounding_box.x, bounding_box.y), cvPoint(bounding_box.x + bounding_box.width, bounding_box.y + bounding_box.height), CV_RGB(255,0,0), 3 ); } cvReleaseMemStorage( &storage ); } int main(int argc, char* argv[]) { help(); if (argc > 2) { image_filename = argv[1]; model_filename = argv[2]; } IplImage* image = cvLoadImage(image_filename); if (!image) { printf( "Unable to load the image\n" "Pass it as the first parameter: latentsvmdetect \n" ); return -1; } CvLatentSvmDetector* detector = cvLoadLatentSvmDetector(model_filename); if (!detector) { printf( "Unable to load the model\n" "Pass it as the second parameter: latentsvmdetect \n" ); cvReleaseImage( &image ); return -1; } detect_and_draw_objects( image, detector ); cvNamedWindow( "test", 0 ); cvShowImage( "test", image ); cvWaitKey(0); cvReleaseLatentSvmDetector( &detector ); cvReleaseImage( &image ); cvDestroyAllWindows(); return 0; }