Why OpenCV's `cvCreateCameraCapture` and `cvCreateFileCapture` do not work?

人盡茶涼 提交于 2019-12-06 12:27:20

问题


Have an AVI videofile, and a webcam. cvQueryFrame returns null in both cases. Code is applied(only for cam):

#include "highgui.h"
#include <iostream>

using namespace std;

int main( int argc, char** argv )
{   
    cvNamedWindow( "KillCam", CV_WINDOW_AUTOSIZE );
    cvWaitKey(0);
    CvCapture* capture = cvCreateCameraCapture(-1);
    assert(capture != NULL);
    IplImage* frame;

    while(1){
        frame = cvQueryFrame( capture ); 
        if( !frame ) break;
        cvShowImage( "KillCam", frame );
        char c = cvWaitKey(33);
        if( c == 30 ) break;
    }
    cvReleaseCapture( &capture );
    cvDestroyWindow( "KillCam" );
}

回答1:


I found, by stepping into the openCV code, that I needed to ensure the fmpeg dll was present in the current working directory at runtime:

opencv_ffmpeg200d.dll

OpenCV doesn't shed any warning if this dll is not found, instead the capture create call just returns NULL.

hth

Si




回答2:


Check the video format. OpenCV can be picky in which codecs it supports; it doesn't work with Xvid, for example. You can find a list of supported codecs on the OpenCV wiki



来源:https://stackoverflow.com/questions/1987782/why-opencvs-cvcreatecameracapture-and-cvcreatefilecapture-do-not-work

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