5 CvHaarClassifierCascade
* load_object_detector(const char* cascade_path
)
7 return (CvHaarClassifierCascade
*)cvLoad( cascade_path
);
10 void detect_and_draw_objects(IplImage
* image
,
11 CvHaarClassifierCascade
* cascade
,
14 IplImage
* small_image
= image
;
15 CvMemStorage
* storage
= cvCreateMemStorage(0);
19 /* if the flag is specified, down-scale the input image to get a
20 performance boost w/o loosing quality (perhaps) */
23 small_image
= cvCreateImage( cvSize(image
->width
/2,image
->height
/2), IPL_DEPTH_8U
, 3 );
24 cvPyrDown( image
, small_image
, CV_GAUSSIAN_5x5
);
28 /* use the fastest variant */
29 faces
= cvHaarDetectObjects( small_image
, cascade
, storage
, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING
);
31 /* draw all the rectangles */
32 for( i
= 0; i
< faces
->total
; i
++ )
34 /* extract the rectangles only */
35 //CvRect face_rect = *(CvRect*)cvGetSeqElem( faces, i, 0 );
36 CvRect face_rect
= *(CvRect
*)cvGetSeqElem( faces
, i
);
37 cvRectangle( image
, cvPoint(face_rect
.x
*scale
,face_rect
.y
*scale
),
38 cvPoint((face_rect
.x
+face_rect
.width
)*scale
,
39 (face_rect
.y
+face_rect
.height
)*scale
),
43 if( small_image
!= image
)
44 cvReleaseImage( &small_image
);
45 cvReleaseMemStorage( &storage
);
48 // A Simple Camera Capture Framework.
49 >>>>>>> experimental
:hello
-world
.cpp
50 int main( int argc
, char** argv
)
52 CvHaarClassifierCascade
* cascade
= load_object_detector(argv
[1]);
54 CvCapture
* capture
= cvCaptureFromCAM( CV_CAP_ANY
);
56 fprintf( stderr
, "ERROR: capture is NULL \n" );
61 // Create a window in which the captured images will be presented
62 cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE
);
64 // Show the image captured from the camera in the window and repeat
67 IplImage
* frame
= cvQueryFrame(capture
);
68 IplImage
* flipped
= cvCreateImage(cvSize(frame
->width
, frame
->height
),
69 frame
->depth
, frame
->nChannels
);
71 fprintf( stderr
, "ERROR: frame is null...\n" );
76 cvFlip(frame
, flipped
, 1);
78 detect_and_draw_objects(flipped
, cascade
, 1);
79 cvShowImage( "mywindow", flipped
);
80 // Do not release the frame!
82 //If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
83 //remove higher bits using AND operator
84 if( (cvWaitKey(10) & 255) == 27 ) break;
87 // Release the capture device housekeeping
88 cvReleaseCapture( &capture
);
89 cvDestroyWindow( "mywindow" );