想要在 OSX 上的 OpenCV 中实时镜像视频,不知道从哪里开始

2024-04-09

如果还不是很明显的话,这是我第一天使用 OpenCV。 我希望做的是镜像frame2,然后对其进行上采样。

我不确定如何在这些 IplImage 类型的帧上使用矩阵运算。我如何镜像我的frame2,然后将其上采样到Webcam2 窗口?下面是我的代码:

 #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;
 }

OpenCV中有一个简洁的函数,叫做flip()。 C 对应物被命名为cvFlip()。我相信它会对你有所帮助。

我还将向您提供我一直给出的建议:从 C 接口转向 C++!更清洁、更安全、更轻松!

你可以检查this https://stackoverflow.com/questions/8585852/in-an-opencv-application-how-do-i-identify-the-source-of-memory-leak-and-fix-it/8591335#8591335回答看看两者的区别。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

想要在 OSX 上的 OpenCV 中实时镜像视频,不知道从哪里开始 的相关文章

随机推荐