Video playback application exits instantly

asked 2013-12-25 02:50:08 -0500

pudelhund gravatar image

updated 2013-12-25 03:18:01 -0500

berak gravatar image

Hi, I am just beginning to work with OpenCV. I am using OpenCV 2.4.7 with Qt 5.2.0 on Windows 7. As far as I can see I set up everything correctly, the code I used before (all related to "still" images, no videos) compiled and executed as intended. But now I am trying to display a video. Nothing fancy. It compiles, yet when I execute it, no video is displayed and the program exits. After adding cv::waitKey(0) to the end of the application I could only see a black window... Of course I have checked the video file itself. It is not damaged. The path is correct as well. So, why is this happening?

Code and screenshot:


#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

int main() {
    cv::namedWindow( "Example3", cv::WINDOW_AUTOSIZE );
    cv::VideoCapture cap;"vid.avi");
    cv::Mat frame;
    while( 1 ) {
        cap >> frame;
        if( ! ) break;
        cv::imshow( "Example3", frame );
        if( cv::waitKey(33) >= 0 ) break;
    return 0;

Edit: So apparently the file can't be opened. I tried cap.isOpened() and the response was 'false'. But like I said before, the path is correct and the video is not damaged either...

edit retag flag offensive close merge delete