QLabel show Image problem
Unsolved
General and Desktop
-
I want to get image from opencv capture and show it on QLabel frame by frame. Now i use a timer to refresh ui
this->timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(updatePicture()));
void FaceCamera::updatePicture() { cap >> this->image; showMatOnQLabel(image, ui.cameraLabel); }
void FaceCamera::showMatOnQLabel(cv::Mat mat, QLabel *qlabel) { //conversion from Mat to QImage if (mat.empty()) return; cv::Mat dest; cv::cvtColor(mat, dest, CV_BGR2RGB); QImage imageFromMat = QImage((uchar*)dest.data, dest.cols, dest.rows, dest.step, QImage::Format_RGB888); QImage qimage = imageFromMat.scaled(QSize(qlabel->width(), qlabel->height()), Qt::AspectRatioMode::KeepAspectRatio); //show QImage using QLabel qlabel->setPixmap(QPixmap::fromImage(qimage)); }
it can works, but if i directly get frame in main thread one by one and showMatOnQLabel,
it will not show image util the last frame i get.why this happens ? plese help me
thx : ]
chen.xu
from beijing
2019.9.30 -
Hi and welcome to devnet,
At what speed are you triggering the timer ?