import cv2
clicked = False
def onMouse(event, x, y, flags, param):
global clicked
if event == cv2.EVENT_LBUTTONUP:
clicked = True
cameraCapture = cv2.VideoCapture(0)
cv2.namedWindow('MyWindow')
cv2.setMouseCallback('MyWindow', onMouse)
success, frame = cameraCapture.read()
while success and cv2.waitKey(1) == 255:
keycode = cv2.waitKey(1)
cv2.imshow('MyWindow',frame)
success, frame = cameraCapture.read()
cameraCapture.release()
这里的cv2.waitKey(1) == 255的255我是在Ubuntu是测试的结果。也有人说是bug。