Ask Your Question

Sleep (or equivalent) vs waitKey

asked 2020-04-03 14:08:23 -0500

SiberianRob gravatar image

updated 2020-04-03 14:43:14 -0500

I am using c++ in opencv 4.2.0 and would like to start with three threads. two threads to manage one camera each and another to manage commands from the user. I noticed that just removing the WaitKey(10) section that is commonly used in favor of Sleep(10) or chrono sleep for 10 milliseconds prevents the image showing regardless of one camera or two. If I remove the WaitKey(10) from my processVideo() function it always shows a dialog box that is completely grey.


I am not sure what is different about the Sleep (or "equivalent") function call as it seems that it should be doing the same thing I am not sure why changing one line would have this result.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2020-04-04 02:04:32 -0500

berak gravatar image

updated 2020-04-04 03:10:26 -0500

waitKey() is needed to show an image (it triggers the window update, while imshow() only copies a pointer) , so you cannot replace it with sleep() or the like

and would like to start with three threads

however, all your gui calls (imshow, waitKey, etc) have to remain on the main thread

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2020-04-03 14:08:23 -0500

Seen: 620 times

Last updated: Apr 04 '20