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. Qlabel not updated when using opencv + QT to play video on Qlabel,
Forum Updated to NodeBB v4.3 + New Features

Qlabel not updated when using opencv + QT to play video on Qlabel,

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 913 Views 2 Watching
  • 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.
  • H Offline
    H Offline
    hitbuyi
    wrote on last edited by hitbuyi
    #1

    I use opencv to capture one frame from a video, dispay it on qt lable, code is below

    void camView::showVideo_1Frm(std::string filePath, int iFrm)
    {
    cv::Mat frame, result_frame;
    cv::VideoCapture capture(filePath); // read local vedio
    if (capture.isOpened())
    {
    capture.set(cv::CAP_PROP_FRAME_COUNT, iFrm);
    capture >> frame;
    int num_totalVedio_frm = capture.get(cv::CAP_PROP_FRAME_COUNT); //test
    double length = int(capture.get(cv::CAP_PROP_FRAME_COUNT)); // test
    double frm_fps = capture.get(cv::CAP_PROP_FPS); // test
    if (!frame.empty())
    {
    ui->LVideo->clear();
    cvtColor(frame, result_frame, CV_BGR2RGB);
    cv::resize(result_frame, result_frame, cv::Size(640, 480));
    QImage image((const uchar*)result_frame.data, result_frame.cols, result_frame.rows, QImage::Format_RGB888);
    ui->LVideo->setPixmap(QPixmap::fromImage(image));
    ui->LVideo->resize(ui->LVideo->pixmap()->size());
    }
    }
    else
    std::cout << "loading error,please check the path" << std::endl;
    }

    Now the code just show the first frame of picture , why? iFrm is increased from 1 to 2000 normally,ui->LVideo is QLabel type

    J.HilkJ 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Its hardly something with QLabel.
      So check you do read new frames etc.
      Maybe just save image to file for 10 images and check they are different.

      1 Reply Last reply
      0
      • H hitbuyi

        I use opencv to capture one frame from a video, dispay it on qt lable, code is below

        void camView::showVideo_1Frm(std::string filePath, int iFrm)
        {
        cv::Mat frame, result_frame;
        cv::VideoCapture capture(filePath); // read local vedio
        if (capture.isOpened())
        {
        capture.set(cv::CAP_PROP_FRAME_COUNT, iFrm);
        capture >> frame;
        int num_totalVedio_frm = capture.get(cv::CAP_PROP_FRAME_COUNT); //test
        double length = int(capture.get(cv::CAP_PROP_FRAME_COUNT)); // test
        double frm_fps = capture.get(cv::CAP_PROP_FPS); // test
        if (!frame.empty())
        {
        ui->LVideo->clear();
        cvtColor(frame, result_frame, CV_BGR2RGB);
        cv::resize(result_frame, result_frame, cv::Size(640, 480));
        QImage image((const uchar*)result_frame.data, result_frame.cols, result_frame.rows, QImage::Format_RGB888);
        ui->LVideo->setPixmap(QPixmap::fromImage(image));
        ui->LVideo->resize(ui->LVideo->pixmap()->size());
        }
        }
        else
        std::cout << "loading error,please check the path" << std::endl;
        }

        Now the code just show the first frame of picture , why? iFrm is increased from 1 to 2000 normally,ui->LVideo is QLabel type

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @hitbuyi said in Qlabel not updated when using opencv + QT to play video on Qlabel,:

        showVideo_1Frm

        how do you call showVideo_1Frm ? with a timer or something?


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        H 1 Reply Last reply
        0
        • J.HilkJ J.Hilk

          @hitbuyi said in Qlabel not updated when using opencv + QT to play video on Qlabel,:

          showVideo_1Frm

          how do you call showVideo_1Frm ? with a timer or something?

          H Offline
          H Offline
          hitbuyi
          wrote on last edited by
          #4

          @J-Hilk with a timer,every 100ms, my opencv is 4.10, below code works for opencv 2.4,
          void camView::showVideo_1Frm(std::string filePath, int iFrm) {
          cv::Mat frame;
          cv::VideoCapture capture(filePath); // read video indicated by filePath
          cv::VideoCapture *pV = NULL;
          if (capture.isOpened()) {
          pV = &capture;
          (*pV).set(cv::CAP_PROP_FRAME_COUNT, iFrm);
          (*pV) >> frame;
          if (!frame.empty()) {
          cvtColor(frame, frame, CV_BGR2RGB);
          cv::resize(frame, frame, cv::Size(640, 480));

          		QImage image((const uchar*)frame.data, frame.cols, frame.rows, QImage::Format_RGB888);
          		ui->LVideo->setPixmap(QPixmap::fromImage(image));
          		ui->LVideo->resize(ui->LVideo->pixmap()->size());
          		ui->LVideo->show();
          	}
          }
          else
          	std::cout << "loading error,please check the path" << std::endl;
          

          }

          BUT NOT work for opencv 4.10, i doubt my lib has problem

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            What is the use of pV ?

            Beside that, did you check that your frame variable contains something valid ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • H Offline
              H Offline
              hitbuyi
              wrote on last edited by hitbuyi
              #6

              pV is pointer to video

              The problem is solved, the fault is that
              (*pV).set(cv::CAP_PROP_FRAME_COUNT, iFrm);
              should be
              (*pV).set(cv::CAP_PROP_POS_FRAMES, iFrm );

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                I know it's a pointer. The problem is that in your code, it's completely useless. Just use the capture object directly rather than what you do with pV.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                H 1 Reply Last reply
                0
                • SGaistS SGaist

                  I know it's a pointer. The problem is that in your code, it's completely useless. Just use the capture object directly rather than what you do with pV.

                  H Offline
                  H Offline
                  hitbuyi
                  wrote on last edited by
                  #8

                  @SGaist your are right,

                  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