I am porting from Windows C++ VS2017 OpenCV 2.4 to 3.4 and now to 4.5
Previously in OCV 2.4 and 3.4 I could create a namedWindow, start a new thread, and reference that namedWindow with imshow, waitKey, etc and, outside of that thread, call the mouse callback for that namedWindow.
Now I am finding out that all calls to a namedWindow have to stay in the same thread that it was created in. So, in the new thread, at the top, I create the namedWindow. and I can now reference it within that thread with imshow, waitKey and destroyWindow. So far so good…except that I can no longer find a way to set the mouse callback for that namedWindow
Originally this call was outside the thread
setMouseCallback(“cameraWindow”, my_mouse_callbackCamera, NULL);
When that is called now from the original outside the thread location the app just sits there. In debug mode I can see that nothing in the thread is getting hit. The app seems to be looping somewhere or just stuck because all I can do is Stop Debugging to exit the app.
So I moved the call back function to a location that can use a memory variable to call the callback from inside the thread.
In effect, inside the thread I have
if (bSetCameraMouseCallback == true){
setMouseCallback(“cameraWindow”, my_mouse_callbackCamera, NULL);
}
The declaration looks like this
void my_mouse_callbackCamera(int event, int x, int y, int flags, void* param);
But, just like when it was called from outside the thread, as soon as the setMouseCallback is called, the program just seems to stop functioning.
So the question is: How would one go about setting a mouseCallback on a namedWindow that is running in a separate thread?
I know that it is “recommended” not to use OpenCV in a multi-threaded app but, in the real world, it would be unreasonable to limit OpenCV to single threaded apps only. There has to be a way. Any help would be appreciated.