Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QT+OpenCV issues
QtWS25 Last Chance

QT+OpenCV issues

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 750 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stevendragoes
    wrote on last edited by
    #1

    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;
        while(1)
        {
            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.data, dest.cols, dest.rows, dest.step, QImage::Format_RGB888);
            ui.display_image->setPixmap(QPixmap::fromImage(imdisplay));
            QApplication::processEvents();
        }
    
    }
    
    

    Cheers!

    beeckscheB 1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      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.

      S 1 Reply Last reply
      0
      • S Stevendragoes

        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;
            while(1)
            {
                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.data, dest.cols, dest.rows, dest.step, QImage::Format_RGB888);
                ui.display_image->setPixmap(QPixmap::fromImage(imdisplay));
                QApplication::processEvents();
            }
        
        }
        
        

        Cheers!

        beeckscheB Offline
        beeckscheB Offline
        beecksche
        wrote on last edited by
        #3

        @Stevendragoes

        Hi,
        do you need to capture the frames with OpenCV?

        If not, have a look https://doc.qt.io/qt-5/videooverview.html. Then you can capture the frames as well and build a CV matrix for image processing.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Stevendragoes
          wrote on last edited by
          #4

          @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

          1 Reply Last reply
          0
          • Kent-DorfmanK Kent-Dorfman

            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.

            S Offline
            S Offline
            Stevendragoes
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved