Skip to content
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

Cannot Set Call Back to Named Window - using opencv.org example code #17880

Closed
Rylangrayston opened this issue Jul 18, 2020 · 2 comments
Closed

Comments

@Rylangrayston
Copy link

  • OpenCV version 4.3.0
  • Operating System / Platform => Ubuntu 20.04 64 Bit freshly installed and updated.
  • python3

this code copied directly from the cv website (https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_mouse_handling/py_mouse_handling.html#mouse-handling):

import cv2
import numpy as np

# mouse callback function
def draw_circle(event,x,y,flags,param):
    if event == cv2.EVENT_LBUTTONDBLCLK:
        cv2.circle(img,(x,y),100,(255,0,0),-1)

# Create a black image, a window and bind the function to window
img = np.zeros((512,512,3), np.uint8)
cv2.namedWindow('image')
cv2.setMouseCallback('image',draw_circle)

while(1):
    cv2.imshow('image',img)
    if cv2.waitKey(20) & 0xFF == 27:
        break
cv2.destroyAllWindows()

Fails with this error:

Failed to load module "canberra-gtk-module"
Traceback (most recent call last):
  File "paint.py", line 12, in <module>
    cv2.setMouseCallback('image',draw_circle)
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'
@alalek
Copy link
Member

alalek commented Jul 18, 2020

You using Pypi opencv-python* package (unofficial) with conflicted Qt binaries.
There is nothing to fix in OpenCV sources.

See #17827 and opencv/opencv-python#356

Workaround: build from sources directly.

@Rylangrayston
Copy link
Author

Thankyou alalek!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants