QCoreApplications::processEvent() takes a lot of time when I use a background photo.
-
Good work everyone!
I am writing a program with QT using C++. In the program I have a function to show OpenCV matrices in the background. In my main loop
QImage img( vars.frame.data, vars.frame.cols, vars.frame.rows, vars.frame.step, QImage::Format_BGR888); vars.ui.background->setPixmap(QPixmap::fromImage(img));
when I do this transformation and then
QCoreApplication::processEvents();
when I call this process, processEvents takes a significant amount of time, about 15-16 ms.
But when I call the processEvents function directly without using background, it takes less than 1 ms.
I also tried this with OpenGL Widget, QGraphicsView and QLabel and got no different result.
How can I overcome this. Thank you in advance.
Processor: Intel(R) Core(TM) i7-7560U CPU @ 2.40GHz
Display Card: Intel(R) Iris(R) Plus Graphics 640 -
@thegkhn It does not seem unreasonable to assume that if commenting this:
QImage img( vars.frame.data, vars.frame.cols, vars.frame.rows, vars.frame.step, QImage::Format_BGR888); vars.ui.background->setPixmap(QPixmap::fromImage(img));
removes ~15 ms of processing time, then that is how long this image conversion processing takes.
Why are you calling QCoreApplication::processEvents at all?
-
-
@thegkhn said in QCoreApplications::processEvent() takes a lot of time when I use a background photo.:
When I run opencv outside of the main thread, I experience extreme performance loss.
-
@thegkhn said in QCoreApplications::processEvent() takes a lot of time when I use a background photo.:
while the processEvents that I call after this conversion takes around 14 ms.
@JonB said in QCoreApplications::processEvent() takes a lot of time when I use a background photo.:
But make sure you are calling it only once(?), not in a loop?
-
processEvents is a crutch. Your grandma with a crutch will never be Flash. Sometimes processEvents helps to solve a problem, especially if performance is no concern. If you want performance, don't use processEvents!!!
Nobody can give you any more guidance because the code you have showed is not enough to analyze your problem. Maybe you have many slots queued that need to be handled. Certainly, if done properly having a separate thread of opencv will be faster (in total) because two threads with a lot of work is faster than a single thread. If you do too much synchronization between the GUI thread and the opencv thread, it'll be too slow. Use double buffering for the pixmap/image.