简体   繁体   English

用opencv播放视频

[英]Playing video with opencv

I have this code here to play a video. 我在这里有这段代码来播放视频。 When I compile it, it does so fine but when I run, it just does nothing. 当我编译它时,它做的很好,但是当我运行时,它什么也没做。 What could be the problem? 可能是什么问题呢? Is it the code? 是代码吗? Or are my video dependencies not installed properly? 还是我的视频依赖项未正确安装?

#include <highgui.h>

int main(int argc, char** argv) {
     /* Create a window */
     cvNamedWindow("Example2", CV_WINDOW_AUTOSIZE);
     /* capture frame from video file */
     CvCapture* capture = cvCreateFileCapture( argv[1]);
     /* Create IplImage to point to each frame */
     IplImage* frame;
     /* Loop until frame ended or ESC is pressed */
     while(1)
     {
        /* grab frame image, and retrieve */
        frame = cvQueryFrame(capture);
        /* exit loop if fram is null / movie end */
        if(!frame) break;
        /* display frame into window */
        cvShowImage("Example2", frame);
        /* if ESC is pressed then exit loop */
        char c = cvWaitKey(33);
        if(c==27) break;
     }

     /* destroy pointer to video */
     cvReleaseCapture(&capture);
     /* delete window */
     cvDestroyWindow("Example2");

     return EXIT_SUCCESS;
}

Instead of directly giving the name of the file through command line, try passing the file name in the parameter and see if the video gets displayed or not,provide full path of the file in parameters. 尝试通过在参数中传递文件名,然后查看是否显示视频,而不是通过命令行直接提供文件名,在参数中提供文件的完整路径。 If it doesn't then we'll try figuring out if there is something wrong with the OS or with the video dependencies. 如果不是,那么我们将尝试确定操作系统或视频依赖项是否有问题。

Currently it seems to me as if you are not providing a proper path for the file. 目前,在我看来,好像您没有为文件提供正确的路径。

what is the format of the video that you are using?? 您正在使用的视频格式是什么?

Also check if the video file is getting loaded or not. 还要检查视频文件是否正在加载。

if(!capture)

{

//Just to check if the video gets loaded or not

printf("Video Can't be loaded"); getch();

System.exit(0);

}

Hope that helps. 希望能有所帮助。

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

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