Files
open-cv-experiment/test/2024,9,23/mouse_event.py
T
2024-09-23 21:26:08 +08:00

21 lines
491 B
Python

import cv2 as cv
import numpy as np
img=np.ones((512,512))
def draw_circle(event,x,y,flags,param):
if event==cv.EVENT_LBUTTONDOWN:
cv.circle(img,(x,y),20,0,-1)
cv.namedWindow('show_img')
cv.setMouseCallback('show_img',draw_circle)
while(1):
cv.imshow('show_img',img)
pressedKey=cv.waitKey(5)
if pressedKey==ord('q'):
break
elif pressedKey==ord('s'):
cv.imwrite("mouse_draw_circle.jpg",img);
print("save success")
cv.destroyAllWindows()