Ask Your Question

Revision history [back]

Can't read a video file with Qt

Hi all, I'm new in OpenCV and Qt. I've seen that a lot of people have this problem, but any of their solutions work for me.

I have this class:

#include "playvideo.h"
#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdio.h>
#include <iostream> 

using namespace cv;
using namespace std;

playVideo::playVideo()
{
}

int playVideo::displayVideo() {
    VideoCapture cap("../dataset/people1.mp4");

    try {
        if(!cap.isOpened()) {
            cout << "error" << endl;

        }
    } catch (int e) {
        cout << "An exception occurred. Exception Nr. " << e << '\n';
    }

    namedWindow("w", 1);
    Mat frame;
    cap >> frame;
    imshow("w", frame);
    return 0;
}

And when I execute this program, the output of the exception is this:

OpenCV Error: Assertion failed (size.width>0 && size.height>0) in imshow, file /home/.../opencv-2.4.9/modules/highgui/src/window.cpp, line 261 terminate called after throwing an instance of 'cv::Exception'

what(): /home/.../opencv-2.4.9/modules/highgui/src/window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow

Thank you in advance :)