Wanting to live-mirror video in OpenCV on OSX, not sure where to start

爱⌒轻易说出口 提交于 2019-12-23 13:05:08

问题


If it isn't already obvious, this is my first day playing around with OpenCV. What I am hoping to do is mirror frame2, and then upsample it.

I am not sure how to use a matrix operation on these frames which are of type IplImage. How could I mirror my frame2, and then upsample it to the Webcam2 window? Below is my code:

 #include "cv.h" 
 #include "highgui.h" 
 #include <stdio.h>  



 // A Simple Camera Capture Framework 
 int main() {
   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( "Webcam", CV_WINDOW_AUTOSIZE );
   cvNamedWindow( "Webcam2", CV_WINDOW_AUTOSIZE );
   // Show the image captured from the camera in the window and repeat
   while ( 1 ) {
     // Get one frame
     IplImage* frame = cvQueryFrame( capture );
     IplImage* frame2 = cvCreateImage(cvSize (frame->width*2, frame->height*2), 
     frame->depth, frame->nChannels);
     cvPyrUp (frame, frame2);



        if ( !frame ) {
       fprintf( stderr, "ERROR: frame is null...\n" );
       getchar();
       break;
     }

     cvShowImage( "Webcam", frame );
     cvShowImage( "Webcam2", frame2 );
     // 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;
   }
   // Release the capture device housekeeping
   cvReleaseCapture( &capture );
   cvDestroyWindow( "Webcam" );
   cvDestroyWindow( "Webcam2" );
   return 0;
 }

回答1:


There is a neat function in OpenCV, called flip(). The C counterpart is named cvFlip(). And I am sure it will help you.

And I will also give you the advice I always give: Move from the C interface to C++! Much cleaner, much safer, much easier!

You can check this answer to see the differences between the two.



来源:https://stackoverflow.com/questions/8613881/wanting-to-live-mirror-video-in-opencv-on-osx-not-sure-where-to-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!