making separate IplImage to hold mirrored image. this avoids flickering
authorozzloy <ozzloy+github_com@gmail.com>
Mon, 9 Feb 2009 09:09:37 +0000 (01:09 -0800)
committerozzloy <ozzloy+github_com@gmail.com>
Mon, 9 Feb 2009 09:09:37 +0000 (01:09 -0800)
hello-world.cpp

index 62f59fa2a662fffb3a09193c689893676b839684..f72a54794ea3459eabd8484a439bef71d1f8507d 100644 (file)
@@ -21,6 +21,9 @@
 #include <highgui.h>
 #include <stdio.h>
 
+// argument for cvFlip(src, dest, FLIP_TYPE)
+#define VERTICAL_FLIP 1
+
 CvHaarClassifierCascade* load_object_detector(const char* cascade_path)
 {
        return (CvHaarClassifierCascade*)cvLoad(cascade_path);
@@ -80,10 +83,18 @@ int main(int argc, char** argv)
        // Create a window in which the captured images will be presented
        cvNamedWindow("mywindow", CV_WINDOW_AUTOSIZE);
 
+       IplImage* frame = cvQueryFrame(capture);
+       if(!frame) {
+               fprintf(stderr, "ERROR: frame is null...\n");
+               getchar();
+               return -1;
+       }
+       IplImage* flipped =
+               cvCreateImage(cvGetSize(frame), frame->depth, frame->nChannels);
        // Show the image captured from the camera in the window and repeat
        while(1) {
                // Get one frame
-               IplImage* frame = cvQueryFrame(capture);
+               frame = cvQueryFrame(capture);
                if(!frame) {
                        fprintf(stderr, "ERROR: frame is null...\n");
                        getchar();
@@ -91,10 +102,10 @@ int main(int argc, char** argv)
                }
 
                //flip the image so displayed right/left corresponds to physical right/left
-               cvFlip(frame, frame, 1);
+               cvFlip(frame, flipped, VERTICAL_FLIP);
 
-               detect_and_draw_objects(frame, cascade, 1);
-               cvShowImage("mywindow", frame);
+               detect_and_draw_objects(flipped, cascade, 1);
+               cvShowImage("mywindow", flipped);
                // Do not release the frame!
 
                //If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
@@ -105,5 +116,6 @@ int main(int argc, char** argv)
        // Release the capture device housekeeping
        cvReleaseCapture(&capture);
        cvDestroyWindow("mywindow");
+       cvReleaseImage(&flipped);
        return 0;
 }