using temp vars to make code more readable in main drawing loop.
authorozzloy <ozzloy+github_com@gmail.com>
Mon, 9 Feb 2009 01:11:10 +0000 (17:11 -0800)
committerozzloy <ozzloy+github_com@gmail.com>
Mon, 9 Feb 2009 01:11:10 +0000 (17:11 -0800)
making code more readable in general, removing unnecessary spaces.

hello-world.cpp

index 8135cb4e4b5cbbdba8217a1675fd1e47611a8f3e..62f59fa2a662fffb3a09193c689893676b839684 100644 (file)
@@ -23,7 +23,7 @@
 
 CvHaarClassifierCascade* load_object_detector(const char* cascade_path)
 {
-       return (CvHaarClassifierCascade*)cvLoad( cascade_path );
+       return (CvHaarClassifierCascade*)cvLoad(cascade_path);
 }
 
 void detect_and_draw_objects(IplImage* image,
@@ -37,74 +37,73 @@ void detect_and_draw_objects(IplImage* image,
 
        /* if the flag is specified, down-scale the input image to get a
                 performance boost w/o loosing quality (perhaps) */
-       if( do_pyramids )
+       if(do_pyramids)
        {
-               small_image = cvCreateImage( cvSize(image->width/2,image->height/2), IPL_DEPTH_8U, 3 );
-               cvPyrDown( image, small_image, CV_GAUSSIAN_5x5 );
+               small_image = cvCreateImage(cvSize(image->width/2,image->height/2),
+                               IPL_DEPTH_8U, 3);
+               cvPyrDown(image, small_image, CV_GAUSSIAN_5x5);
                scale = 2;
        }
 
        /* use the fastest variant */
-       faces = cvHaarDetectObjects( small_image, cascade, storage, 1.2, 2, CV_HAAR_DO_CANNY_PRUNING );
+       faces = cvHaarDetectObjects(small_image, cascade, storage, 1.2, 2,
+                       CV_HAAR_DO_CANNY_PRUNING);
 
        /* draw all the rectangles */
-       for( i = 0; i < faces->total; i++ )
+       for(i = 0; i < faces->total; i++)
        {
                /* extract the rectangles only */
-               //CvRect face_rect = *(CvRect*)cvGetSeqElem( faces, i, 0 );
-               CvRect face_rect = *(CvRect*)cvGetSeqElem( faces, i);
-               cvRectangle( image, cvPoint(face_rect.x*scale,face_rect.y*scale),
-                               cvPoint((face_rect.x+face_rect.width)*scale,
-                                       (face_rect.y+face_rect.height)*scale),
-                               CV_RGB(255,0,0), 3 );
+               CvRect face = *(CvRect*)cvGetSeqElem(faces, i);
+               CvPoint upperLeft = cvPoint(face.x*scale,face.y*scale);
+               CvPoint bottomRight = cvPoint((face.x+face.width)*scale,
+                               (face.y+face.height)*scale);
+               cvRectangle(image, upperLeft, bottomRight, CV_RGB(255,0,0), 3);
        }
 
-       if( small_image != image )
-               cvReleaseImage( &small_image );
-       cvReleaseMemStorage( &storage );
+       if(small_image != image)
+               cvReleaseImage(&small_image);
+       cvReleaseMemStorage(&storage);
 }
 
 // A Simple Camera Capture Framework.
->>>>>>> experimental:hello-world.cpp
-int main( int argc, char** argv )
+int main(int argc, char** argv)
 {
        CvHaarClassifierCascade* cascade = load_object_detector(argv[1]);
 
-       CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
-       if( !capture ) {
-               fprintf( stderr, "ERROR: capture is NULL \n" );
+       CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);
+       if(!capture) {
+               fprintf(stderr, "ERROR: capture is NULL \n");
                getchar();
                return -1;
        }
 
        // Create a window in which the captured images will be presented
-       cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
+       cvNamedWindow("mywindow", CV_WINDOW_AUTOSIZE);
 
        // Show the image captured from the camera in the window and repeat
-       while( 1 ) {
+       while(1) {
                // Get one frame
                IplImage* frame = cvQueryFrame(capture);
-               IplImage* flipped = cvCreateImage(cvSize(frame->width, frame->height),
-                               frame->depth, frame->nChannels);
-               if( !frame ) {
-                       fprintf( stderr, "ERROR: frame is null...\n" );
+               if(!frame) {
+                       fprintf(stderr, "ERROR: frame is null...\n");
                        getchar();
                        break;
                }
 
-               cvFlip(frame, flipped, 1);
+               //flip the image so displayed right/left corresponds to physical right/left
+               cvFlip(frame, frame, 1);
 
-               detect_and_draw_objects(flipped, cascade, 1);
-               cvShowImage( "mywindow", flipped);
+               detect_and_draw_objects(frame, cascade, 1);
+               cvShowImage("mywindow", frame);
                // Do not release the frame!
 
                //If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
                //remove higher bits using AND operator
-               if( (cvWaitKey(10) & 255) == 27 ) break;
+               if((cvWaitKey(10) & 255) == 27) break;
        }
 
        // Release the capture device housekeeping
-       cvReleaseCapture( &capture );
-       cvDestroyWindow( "mywindow" );
+       cvReleaseCapture(&capture);
+       cvDestroyWindow("mywindow");
        return 0;
 }