Issue
I am working on a project where i have to use Mouse as a paintbrush. I have used cv2.setMouseCallback()
function but it returned the following error.
here is the part of my code
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()
when I run this It returned me the following error: error Traceback
(most recent call last)
<ipython-input-1-640e54baca5f> in <module>
10 img = np.zeros((512,512,3), np.uint8)
11 cv2.namedWindow('image')
---> 12 cv2.setMouseCallback('image',draw_circle)
13
14 while(1):
error: OpenCV(4.3.0) /io/opencv/modules/highgui/src/window_QT.cpp:717: error: (-27:Null pointer) NULL window handler in function 'cvSetMouseCallback'
My python version - 3.8 Operating System - ubuntu 20
Solution
The error is resolved I removed the previously installed OpenCV
(which is installed using pip pip install opencv-python
) and reinstalled it using
sudo apt install libopencv-dev python3-opencv
Answered By - Avinash Koshal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.