作者:左边我们画圈圈 | 来源:互联网 | 2023-08-30 20:00
先看代码:importcv2importnumpyasnpwindownamedrawingimgnp.zeros((512,512,3),np.uint8)c
先看代码:
import cv2
import numpy as npwindowname = 'drawing'
img = np.zeros((512,512,3), np.uint8)cv2.namedWindow(windowname)def drawCircle(event, x,y,flags, params):if event == cv2.EVENT_LBUTTONDOWN:cv2.circle(img, (x,y), 60,(0,0,255), -1)cv2.setMouseCallback(windowname, drawCircle)while(True):cv2.imshow(windowname, img)if cv2.waitKey(20) == 27:breakcv2.destroyAllWindows()def main():while(True):cv2.imshow(windowname,img )if cv2.waitKey(0) == 27:breakcv2.destroyAllWindows()if __name__ == "__main__":main()
EVENT_LBUTTONDOWN是鼠标左键按下事件,cv2.circle画一个圆,记得按Esc退出程序。
运行看效果: