简体   繁体   English

在OpenCV中捕获和显示视频

[英]Capture and display video in OpenCV

I executed a simple C++ program in Visual Studio2010 using OpencV version 2.2 to start the camera and display the video simaltaneously.But the camera gets started and only the window came as output and not the video capture simaltaneously..Here is my code.Is there any error in camera..Do we need to install any softwares..Please suggest as soon as possible. 我在Visual Studio2010中使用OpencV 2.2版执行了一个简单的C ++程序来启动摄像机并同时显示视频。相机中有任何错误。.我们需要安装任何软件吗。.请尽快提出建议。

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

int main()
{
CvCapture* capture =0;       
capture = cvCaptureFromCAM(0);
if(!capture)
    {
       printf("Capture failure\n");
       return -1;
    }
IplImage* frame=NULL;
cvNamedWindow("Video");      
cvNamedWindow ("Ball");
//iterate through each frames of the video      
while(true)
    {
            frame = cvQueryFrame(capture);      
            if(!frame) break;
            //frame=cvCloneImage(frame); 
            cvShowImage("Video", frame);    
        //Clean up used images
            cvReleaseImage(&frame);
        //Wait 50mS
            int c = cvWaitKey(10);
        //If 'ESC' is pressed, break the loop
            if((char)c==27 ) break;   
       }
cvDestroyAllWindows() ;
//cvReleaseCapture(&capture); 
return 0; 

} }

and there is a warning in the output window is as: 并且在输出窗口中有一个警告是:

OpenCV Error: Bad argument (unrecognized or unsupported array type) in unknown f unction, file ........\\ocv\\opencv\\modules\\core\\src\\array.cpp, line 995 OpenCV错误:未知功能,文件........ \\ ocv \\ opencv \\ modules \\ core \\ src \\ array.cpp,行995中的错误参数(无法识别或不受支持的数组类型)

The error is caused, because you are releasing the frame returned by cvQueryFrame . 引起该错误的原因是,您释放了cvQueryFrame返回的帧。 It is stated in the documentation that only a single image buffer is used by all the frames of the video. 文档中指出,视频的所有帧仅使用单个图像缓冲区。 So modifying the frame returned by cvQueryFrame will release that buffer and subsequent calls will fail. 因此,修改cvQueryFrame返回的帧将释放该缓冲区,并且后续调用将失败。

To fix the problem, just remove cvReleaseImage(&frame); 要解决此问题,只需删除cvReleaseImage(&frame); .

If you want to modify the frame, create a deep copy of the frame by using cvCloneImage . 如果要修改框架,请使用cvCloneImage创建框架的深层副本。

Also, don't forget to release the capture once you are done. 同样,一旦完成,别忘了释放捕获。

cvReleaseCapture(&capture); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM