gpt4 book ai didi

python - python画图不连续怎么解决

转载 作者:太空宇宙 更新时间:2023-11-03 21:44:25 25 4
gpt4 key购买 nike

这是我的代码:

import numpy as np
import cv2
drawing = False

def draw_circle(event,x,y,flags,param):
global ix,iy,drawing

if event == cv2.EVENT_LBUTTONDOWN:
drawing= True
ix,iy=x,y
elif event == cv2.EVENT_MOUSEMOVE and flags == cv2.EVENT_FLAG_LBUTTON:
if drawing == True:
cv2.circle(img,(x,y),3,(0,0,0),-1)
elif event == cv2.EVENT_LBUTTONUP:
drawing == False

img=np.ones((512,512,3),np.uint8)*255
cv2.namedWindow('image')
cv2.setMouseCallback('image',draw_circle)

while(True):
cv2.imshow('image',img)

if cv2.waitKey(1)&0xff == ord('q'):
break

cv2.destroyAllWindows()

第一条线画得慢,第二条线画得快:

the first line was drawn slowly, the 2nd one was drawn fast

我的问题是:

  1. 是什么导致了这个问题?
  2. 如何解决。

最佳答案

不要使用circle,当你使用circle时,在快速移动时会有间隙。会有间隙,因为当您快速移动时,在绘制前一个圆圈之前会引发新的鼠标事件。使用 line 代替如下:

def draw_circle(event,x,y,flags,param):
global ix,iy,drawing

if event == cv2.EVENT_LBUTTONDOWN:
drawing= True
ix,iy=x,y
elif event == cv2.EVENT_MOUSEMOVE and flags == cv2.EVENT_FLAG_LBUTTON:
if drawing:
cv2.line(img,(ix,iy),(x,y),(0,0,0), 3)
ix,iy = x,y
elif event == cv2.EVENT_LBUTTONUP:
drawing == False

关于python - python画图不连续怎么解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37435592/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com