Ask Your Question

Revision history [back]

waitkey(1) freezes display output when previewing in multiple threading

I'm using OpenCV(4.1.2) with ubuntu(18.04), and built with GTK support. I need to preview more than one video(actually 2) in multiple threading. It means imshow() will be called in every thread that the application created. I knew that waitKey(ms) also needs to be called following by imshow().

My question is all 2 display outputs would be frozen when the application runs for a while. And then some time costed for search the solution. and someone said that What's happening is that you're abusing some feature of OpenCV that doesn't support running in a multi-threaded environment. https://stackoverflow.com/questions/43094972/opencv-multi-threading-giving-errors.

He suggests naming a new window before calling imshow(), or add thread mutex to control competition between threads.

I tried all the above but no any could give help. Then waitkey(ms) removed inadvertently, and the problem never occurred again. But I really do not understand why calling waitKey can effect it. Here's my code image description