Tip:通過攝像頭獲取信息。
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import cv2
#獲取默認攝像頭
cap = cv2.VideoCapture(0)
#判斷攝像頭是否打開
if not cap.isOpened():
raise IOError('Cannot open webcam!')
#無限循環顯示
while True:
#每一幀frame
ret,frame = cap.read()
#擴大1.5倍顯示
frame = cv2.resize(frame,None,fx = 1.25,fy = 1.05,
interpolation = cv2.INTER_CUBIC)
cv2.namedWindow('Video',cv2.WINDOW_FULLSCREEN)
cv2.imshow('Video',frame)
#等待鍵盤響應.按下ESC,退出。
key = cv2.waitKey(1)
if key & 0xFF == 27:
break
#釋放資源
cap.release()
#關閉窗口
cv2.destroyAllWindows()