python-OpenCV 调用摄像头

import cv2
import numpy as np

vc = cv2.VideoCapture(0)
if vc.isOpened():
    opened, frame = vc.read()
else:
    opened = False

while opened:
    ret, frame = vc.read()
    if frame is None:
        break
    if ret:
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        cv2.imshow('result', gray)
        cv2.imshow('result2', frame)
        if cv2.waitKey(10) & 0XFF == 27:
            break
vc.release()
cv2.destroyAllWindows()

 

你可能感兴趣的:(python,OpenCV)