Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在QtGUI中显示图像序列?_C++_Qt_Opencv_Qtgui_Qt Signals - Fatal编程技术网

C++ 在QtGUI中显示图像序列?

C++ 在QtGUI中显示图像序列?,c++,qt,opencv,qtgui,qt-signals,C++,Qt,Opencv,Qtgui,Qt Signals,我有一个处理图像序列的OpenCV算法,我想用如下代码在Qt窗口中显示每个处理过的帧: 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

我有一个处理图像序列的OpenCV算法,我想用如下代码在Qt窗口中显示每个处理过的帧:

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
}

但标签中仅显示最后一个图像。我认为这是因为循环太快,GUI更新不够快。有没有办法让循环暂停,让GUI有时间显示图像,然后仅在GUI显示图像后继续?

根据您对我的评论问题的回答,这似乎是您可以接受的解决方案:

    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);
由于它正在使用,请不要忘记将其添加到项目文件中:

CONFIG += c++11

如果图像更新速度比UI更新速度快,为什么还要频繁地更新它?为什么你不放弃循环的概念来支持信号和插槽,比如QTimer或者用drawImage()和自己的信号发射在小部件子类中重新实现paintEvent?我想我可以做一些事情,比如只使用OpenCV,在每次迭代中调用
cv::imshow()
,然后调用
cvWaitKey()
。实际上,我刚刚将循环重写为一个QTimer插槽,它现在可以工作了。