#=*-coding:utf-8-*- import cv2 import numpy as np def mouse_callback(event,x,y,flags,userdata): # print(event,x,y,flags) # cv2.circle(userdata, (x, y), 100, (0, 255, 0), -1) if event == cv2.EVENT_LBUTTONDBLCLK: cv2.circle(userdata,(x,y),100,(0,255,0),-1) cv2.imshow('mouse', userdata) print(event, x, y, flags,'EVENT_LBUTTONDBLCLK') elif event== cv2.EVENT_MBUTTONDOWN: cv2.rectangle(userdata,(x,y),(x+100,y+200),(0,0,255),-1) cv2.imshow('mouse', userdata) print(event, x, y, flags,'EVENT_MBUTTONDOWN') elif event == cv2.EVENT_RBUTTONDOWN: cv2.rectangle(userdata,(x,y),(x+100,y+200),(0,0,255),-1) cv2.circle(userdata, (x, y), 100, (0, 255, 0), -1) cv2.imshow('mouse', userdata) print(event, x, y, flags,'EVENT_RBUTTONDOWN') if __name__ == '__main__': img = np.zeros((460,500,3),np.uint8) cv2.namedWindow('mouse') cv2.resizeWindow('mouse',500,460) cv2.setMouseCallback('mouse',mouse_callback,img) # while True: cv2.imshow('mouse', img) key = cv2.waitKey(0) if key == ord('q'): cv2.destroyWindow('mouse') break
鼠标事件响应
最新推荐文章于 2024-07-26 13:24:37 发布