Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. 3rd Party Software
  4. [SOLVED] Using Qt and OpenCV to display videos
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Using Qt and OpenCV to display videos

Scheduled Pinned Locked Moved 3rd Party Software
5 Posts 2 Posters 10.3k Views 1 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.
  • A Offline
    A Offline
    ArchGabe
    wrote on last edited by
    #1

    Hi guys,

    I am using Qt and openCV to display some videos.
    Everything works fine except that the video displays very fast! I thought it could be a problem with the frame rate definition in openCV, but it is not. Also tried to set a larger interval in the timer (QTimer), but none of this works.

    Here is my code:
    @
    void MainWindow::on_btnLoad_clicked()
    {
    filename = ui->lnFile->text();
    QByteArray ba = filename.toLocal8Bit();
    string name = ba.data();
    inputVideo = new VideoCapture(name.c_str());

    inputVideo->set(CV_CAP_PROP_FPS, 27.5);
    
    if (inputVideo->isOpened() == false){
        ui->txtInfo->appendPlainText("Problem loading file!");
        std::abort();
    } else
        ui->txtInfo->appendPlainText("Ok!");
    
    timer = new QTimer(this);
    
    cvWaitKey(100);
    connect(timer, SIGNAL(timeout()), this, SLOT(DisplayVideo()));
    timer->start(1);
    

    }

    void MainWindow::DisplayVideo(){

    *inputVideo >> img;
    QImage qImage((uchar*)img.data, img.cols, img.rows, img.step, QImage::Format_RGB888);
    ui->lblVideo->setPixmap(QPixmap::fromImage(qImage));
    

    }
    @
    Can anyone help me, please?

    Thank you in advance,

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

      Hi and welcome to devnet,

      Please enclose your code with coding tags, it will make readable.

      Your timer (which I supposed is connected to DisplayVideo) has a timeout of 1 ms, isn't that a bit fast ?

      By the way, your connect statement doesn't make any sense, could please correct it so we know what should happen ?

      Hope it helps

      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
      0
      • A Offline
        A Offline
        ArchGabe
        wrote on last edited by
        #3

        Hello and thank you very much for your reply!
        .
        How do I change my timer speed? timeout doen't have any parameter changing. (As long as I can see in the function description.)
        .
        Sorry, but I am very new at Qt, so I just adapted the code in this video to my problem:
        .
        https://www.youtube.com/watch?v=0ONxIy8itRA
        .
        So I don't really know how my connect statement should look like...
        .
        Thank you, in advance.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ArchGabe
          wrote on last edited by
          #4

          Ok, ok! I just figured out how to make things work!
          .
          Just changed the "start" input value and now it is working fine!

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

            Nice you found out !

            Don't forget to update the thread's title so that other forum users may know that it has been solved :)

            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
            0

            • Login

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