cv2鼠标点击事件画圆
本篇博客主要介绍利用python中cv2模块实现图片相应鼠标点击事件画圆。
下面是示例代码:
import cv2 import numpy as np def draw_circle(event, x, y, flags, param): if event == cv2.EVENT_LBUTTONDOWN: cv2.circle(img, (x, y), 100, (255, 0, 0), -1) img = np.zeros((512, 512, 3), np.uint8) cv2.namedWindow('image', cv2.WINDOW_NORMAL) cv2.setMouseCallback('image', draw_circle) while True: cv2.imshow('image', img) key = cv2.waitKey(1) if key == ord('q'): break cv2.destroyAllWindows()
结果示例: