Important: Please read the Qt Code of Conduct -

QT+OpenCV issues

  • Hello, I was trying to display a video file obtained from QFileDialog and put into path in the code displayed below. And I converted each frame to QImage so that It can be displayed in the Qlabel created in the UI. Reason: I want to do something with the Matrix obtained by OpenCV.

    However, the video is too big and I tried CV::Resize but I can't seem to resize at all (not because I commented it out LoL)
    It gives me this error:

    "OpenCV: terminate handler is called! The last OpenCV error is:
    OpenCV(4.0.1) Error: Assertion failed (!ssize.empty()) in resize, file C:\QTOpenCV\OpenCV\opencv401\opencv\sources\modules\imgproc\src\resize.cpp, line 3784"

    Moreover, the video is playing too fast. Could be because of while(1) is there a way to slow down the video with a Timer or something? Any help is appreciated. :)

    void MainWindow::DisplayVideo(Ui::MainWindow& ui, std::string& path, MainWindow &parent){
        cv::VideoCapture cap(path);
        cv::Mat frame;
            cap >> frame;
            cv::Mat dest;
            //cv::resize(frame,dest, cv::Size(100,100), 0, 0, cv::INTER_AREA);
            cv::cvtColor(frame,  dest, cv::COLOR_BGR2RGB);
            QImage imdisplay((uchar*), dest.cols, dest.rows, dest.step, QImage::Format_RGB888);


  • ssize.empty() obviously means that your input frame is empty. Check its content before attempting to resize it. The problems you are experiencing are CV specific, so you have some API reading to do in CV.

  • @Stevendragoes

    do you need to capture the frames with OpenCV?

    If not, have a look Then you can capture the frames as well and build a CV matrix for image processing.

  • @beecksche said in QT+OpenCV issues:

    ture the fram

    Hi, yes I do need to capture the frame so that I can do some analysis

  • @Kent-Dorfman Yes I solved it by swapping the cvtColor and resize code. and changing the destination frames. However, it is still playing very fast.

Log in to reply