import cv2
capture = cv2.VideoCapture(0)
while(True):
# 获取一帧
ret,frame = capture.read()
# 将这一帧转换为灰度图
# gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',frame)
if cv2.waitKey(1) == ord('q'):
break
没有这两句就看不了图片
if cv2.waitKey(1) == ord(‘q’):
break