【发布时间】:2015-03-08 16:19:00
【问题描述】:
我正在尝试跟随鼠标的移动进行绘制。它工作正常。
当我缓慢移动鼠标时,绘制的内容看起来是连续的,但是当我稍微加快鼠标移动时,我会得到不连续的图形。
如何用鼠标连续画图
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)
print x,y
elif event==cv2.EVENT_LBUTTONUP:
drawing=False
if mode==True:
cv2.circle(img,(x,y),1,(0,0,255),-1)
#print x,y
#cv2.line(img,(x,y),(x,y),(0,0,255),10)
return x,y
img = np.zeros((512,512,3), np.uint8)
cv2.namedWindow('begueradj')
cv2.setMouseCallback('begueradj',interactive_drawing)
while(1):
cv2.imshow('begueradje',img)
k=cv2.waitKey(1)&0xFF
if k==27:
break
cv2.destroyAllWindows()
我得到的结果:
【问题讨论】:
标签: python python-2.7 opencv