1

我正在使用 opencv 来检测眨眼。我能够使用从相机捕获的流来运行我的项目,一切都很好。我试图在 *.avi 文件的数据库上测试我的算法,但我无法打开其中任何一个。我检查了这些的编解码器版本并下载了正确的编解码器,但它仍然无法正常工作。我决定尝试至少尝试加载剪辑,使用我在互联网某处找到的这段代码:

 int main( int argc, char** argv ){
 int key = 0;  

// Initialize camera and OpenCV image  
//CvCapture* capture = cvCaptureFromCAM( 0 );  
CvCapture* capture = cvCaptureFromAVI( "file.avi" );    
IplImage* frame = cvQueryFrame( capture );  

// Check   
if ( !capture )   
{  
    fprintf( stderr, "Cannot open AVI!\n" );  
    return 1;  
}  

// Get the fps, needed to set the delay  
int fps = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FPS );  

// Create a window to display the video  
cvNamedWindow( "video", CV_WINDOW_AUTOSIZE );  

while( key != 'x' )   
{  
    // get the image frame   
    frame = cvQueryFrame( capture );  

    // exit if unsuccessful  
    if( !frame ) break;  

    // display current frame   
    cvShowImage( "video", frame );  

    // exit if user presses 'x'          
    key = cvWaitKey( 1000 / fps );  
}  

// Tidy up  
cvDestroyWindow( "video" );  
cvReleaseCapture( &capture );  

return 0; 

}

但它仍然没有改变任何东西,捕获仍然是 NULL。任何想法我现在可以做什么?提前致谢!

E: 我在 x64 windows 上使用 opencv 2.4.6

4

3 回答 3

0

i had same problem, then i use class VideoCapture instead,

http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=videocapture#VideoCapture

于 2013-11-08T04:29:13.717 回答
0

代码似乎是正确的。

您将问题标记为 C++,但 IplImage 源自英特尔图像处理库,并且是本机 OpenCV C 库的一部分。在 OpenCV C++ 库中我猜没有 IplImage (或者不应该使用),你必须使用它cv::Mat

关于这个问题:你确定你编译的 OpenCV 有适当的 ffmpeg(或任何其他视频库)支持吗?确保您已安装所需的编解码器,然后使用必要的标志重新编译您的 opencv。可能有帮助。

确保 opencv 安装 cmake 的输出包含类似的文本:

found gstreamer-base-0.10
GTK+ 2.x: YES
FFMPEG: YES
GStreamer: YES
V4L/V4L2: Using libv4l

PS。FFMPEG:是的

于 2013-08-29T07:57:41.203 回答
0

我猜没有安装正确的编解码器。我们需要按照 OpenCV 在http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html的建议安装正确的编解码器。检查 VideoWriter::VideoWriter 部分。我们需要http://www.fourcc.org/codecs.php上的 FOURCC 视频编解码器。当心。安装可能会安装垃圾以及编解码器。并非所有编解码器都能被识别。至少现在我有 mpeg4 和 DivX 并且可以打开 OpenCV 自己的演示程序使用的 Megamind.avi。

于 2014-02-11T01:20:45.960 回答