-
Notifications
You must be signed in to change notification settings - Fork 881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PyPi version 4.3.0.36 sometimes crashes on cv2.setMouseCallback #356
Comments
The base |
I think this is some kind of race condition in OpenCV code or elsewhere. OpenCV (or Qt) seems to open randomly some other window or something before the actual named window appears. Very odd behavior... I have no time to deep dive into the issue, so here is a short workaround which seems to work reliably and should get you going: import numpy as np
import cv2
window_name = "test"
def draw_circle(event,x,y,flags,param):
if event == cv2.EVENT_LBUTTONDBLCLK:
cv2.circle(img,(x,y),100,(255,0,0),-1)
img = np.zeros((512,512,3), np.uint8)
window_open = False
# just try as long as a matching window is found
while not window_open:
try:
cv2.namedWindow(window_name)
cv2.setMouseCallback(window_name, draw_circle)
window_open = True
except:
# destroy any "erroneous" windows OpenCV might have created
cv2.destroyAllWindows()
while(1):
cv2.imshow(window_name, img)
if cv2.waitKey(20) & 0xFF == 27:
break
cv2.destroyAllWindows() Other alternative is to use some actual Qt wrapper (i.e. PyQt) / GUI toolkit to create UIs. OpenCV's GUI functionality is quite limited and imho useful only for debugging purposes. |
I agree on try-except work-around, as an alternative to using another version, like As for the practicality of HighGUI, note that it's being built upon by some larger-scale projects in the community. Notably, I encountered this github issue originally when trying to make GibsonV2 work. I personally would also use PyQt instead, but I can understand the developers' wish to go fast on their main contributions (a robot simulation environment) and delegate responsibility to other libraries. |
This issue might get solved if I manage to update the Linux wheels to Qt5. As there are workarounds, I'm not planning to debug this further unless someone points me directly to the root cause. I'll keep the issue open so I remember to test it in the future in new versions. |
Closing, please see #362 |
opencv/opencv#17767
Expected behaviour
Actual behaviour
On 4.3.0.36 version, sometimes after step 2, OpenCV crashes:
cv2.error: OpenCV(4.3.0) /io/opencv/modules/highgui/src/window_QT.cpp:717: error: (-27:Null pointer) NULL window handler in function 'cvSetMouseCallback'
.Note that this symptom does not occur on version 4.2.0.34.
Steps to reproduce
The text was updated successfully, but these errors were encountered: