# -*- coding: utf-8 -*-
"""
@author: Alex.Duan
"""
import cv2
import numpy as np

# 查看被支持的鼠标事件
#events=[i for i in dir(cv2) if 'EVENT'in i]
#print(events)

def mouse_events(event,x,y,flags,param):
    print(event)
    # 左键单击事件
    if(event==cv2.EVENT_LBUTTONDOWN):
        cv2.circle(img,(x,y),10,(255,0,0),-1)
    elif event==cv2.EVENT_RBUTTONDOWN:
        cv2.circle(img,(x,y),10,(0,255,0),-1)

#--------------------------------------------
# 创建图像与窗口并将窗口与回调函数绑定
img=np.zeros((512,512,3),np.uint8)
cv2.namedWindow('mouse')

# 注册鼠标回调函数
cv2.setMouseCallback('image',mouse_events)

while(1):
    cv2.imshow('mouse',img)
    if cv2.waitKey(20)&0xFF==27:
        break
        
cv2.destroyAllWindows()