ZhangZhihui's Blog  

很简单,生成一个窗口实时显示摄像头的内容,然后将摄像头对准这个窗口。代码如下:

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('Window')
cv2.setMouseCallback('Window', onMouse)

success, frame = cameraCapture.read()
while success and cv2.waitKey(1) == -1 and not clicked:
    cv2.imshow('Window', frame)
    success, frame = cameraCapture.read()
cv2.imwrite('recursive.png', frame)

cv2.destroyAllWindows()
cameraCapture.release()

 

效果图如下:

posted on 2020-03-16 17:25  ZhangZhihuiAAA  阅读(126)  评论(0编辑  收藏  举报