Is MouseCallback running in another thread?

Assume I have a main thread which calls namedWindow, setMouseCallback, imread, imshow, etc. Is MouseCallback running in another different thread from the main thread when a mouse event occurs?

This is kind of important to me because both the main thread and MouseCallback write/read the same variable possibly at the same time. If MouseCallback is running in another thread from the main one, I need to write mutex to avoid racing. I did not find related OpenCV document so I ask here. Thanks for you help.

no, it runs in the context of waitKey()

Can you please be more specific about what “context of waitKey” is?

your callbacks are called in waitKey()

waitKey()'s purpose isn’t to wait for a key. its purpose is to process GUI events.

2 Likes