简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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