[SOLVED] Using Qt and OpenCV to display videos
-
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,
-
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
-
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. -
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 :)