gpt4 book ai didi

c++ - 在 Qt GUI 中显示图像序列?

转载 作者:太空宇宙 更新时间:2023-11-03 22:58:28 25 4
gpt4 key购买 nike

我有一个处理图像序列的 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);

因为它正在使用 the new shiny signal-slot syntax for syntactic sugar ,不要忘记将其添加到您的项目文件中:

CONFIG += c++11

关于c++ - 在 Qt GUI 中显示图像序列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23851147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com