Hello, I'm doing a project in C ++ using GUI QT. In the project in question I need to display images of a camera in the window, but in doing so, the performance of the window is very compromised, all other buttons and features that it includes in the window are slow, overwhelmed it seems. Here is the image capture code for the device.
void mainwindow::on_ButtonShowCamera_clicked(){
ligaCam = true;
if(!this->cap.isOpened()){ // se ja estiver aberto, nao abre denovo //
this->cap.open(0);
}
QImage img;
while(ligaCam == true){
Mat frame;
this->cap.read(frame);
img = MatToQImage(frame); // converte tipo Mat para QImage //
ui->labelScreen->setPixmap(QPixmap::fromImage(img));
ui->labelScreen->setScaledContents(true);
qApp->processEvents();
//imshow("help", frame);
if (waitKey(30) >= 0)
break;
}
}
The variable ligaCam takes care of changing the value when I click on another button (Close Camera) to exit the loop.
My question is if there is any way to display camera images in QLabel using another thread? Or if there was some way to display the images without overloading the window in question? Thanks in advance for your help.