Vote count:
0
I modified a simple program taken from OpenCV documentation.
I simply want to draw using the mouse pointer continuously. For the moment I succeeded to draw, but not in a continuous way unless if I move too slowly the mouse cursor.
Code:
import cv2
import numpy as np
drawing=False # true if mouse is pressed
mode=True # if True, draw rectangle. Press 'm' to toggle to curve
# mouse callback function
def interactive_drawing(event,x,y,flags,param):
global ix,iy,drawing, mode
if event==cv2.EVENT_LBUTTONDOWN:
drawing=True
ix,iy=x,y
elif event==cv2.EVENT_MOUSEMOVE:
if drawing==True:
if mode==True:
cv2.circle(img,(x,y),1,(0,0,255),-1)
elif event==cv2.EVENT_LBUTTONUP:
drawing=False
if mode==True:
cv2.circle(img,(x,y),1,(0,0,255),-1)
img = np.zeros((512,512,3), np.uint8)
cv2.namedWindow('Window')
cv2.setMouseCallback('Window',interactive_drawing)
while(1):
cv2.imshow('Window',img)
k=cv2.waitKey(1)&0xFF
if k==27:
break
cv2.destroyAllWindows()
Hopefully this screenshot explains my problem: the small line looks continuous because I had to move the mouse cursor too slowly. The longer line, is not continuous because I had to move the cursor with the normal speed:
Any one could show how to resolve this problem ? Thank you in advance.
asked 35 secs ago
OpenCV: how to draw continously with a mouse?
Aucun commentaire:
Enregistrer un commentaire