import cv2
import numpy as np
# 鼠标回调函数
def mouseCallback(event, x, y, flags, userData):
print(event, x, y, flags, userData)
# 设置窗口
cv2.namedWindow('mouse', cv2.WINDOW_NORMAL)
# 设置窗口大小
cv2.resizeWindow('mouse', 640, 480)
# 鼠标回调函数-设置
cv2.setMouseCallback('mouse', mouseCallback, "123")
# 创建黑底图片
img = np.zeros((360, 640, 3), np.uint8)
while True:
cv2.imshow('mouse', img),
key = cv2.waitKey(1)
if key & 0xFF == ord('q'):
break
cv2.destroyAllWindows()