user1726
user1726

Reputation: 65

Displaying image sequence in Qt GUI?

I have an OpenCV algorithm that processes an image sequence, and I want to display each processed frame in the Qt window using code like this:

while(someCondition){
    Mat img;
    ... //some OpenCV process here
    QImage qimg = matToQImage (img); //a function I found
    ui->someLabel->setPixmap(QPixmap::fromImage(qimg));

    //I want to add a delay here or some wait condition
}

But only the last image is displayed in the label. I think it's because the loop is too fast and the GUI can't update it fast enough. Is there a way I can make the loop pause to give the GUI time to show the image, and then continue only when the GUI has displayed the image?

Upvotes: 1

Views: 1731

Answers (1)

László Papp
László Papp

Reputation: 53175

Based on your reply to my comment question, this seems to be an acceptable solution for you:

    connect(timer, &QTimer::timeout, [=] () {
        Mat img;
        ... //some OpenCV process here
        QImage qimg = matToQImage (img); //a function I found
        ui->someLabel->setPixmap(QPixmap::fromImage(qimg));
    });
    timer->start(10);

Since it is using the new shiny signal-slot syntax for syntactic sugar, do not forget to add this to your project file:

CONFIG += c++11

Upvotes: 1

Related Questions