create time:2019年7月6日
#!usr/bin/python
# coding=utf-8
import cv2
import numpy
# 從攝像頭採集圖像
# 參數是0,表示打開筆記本的內置攝像頭,參數是視頻文件路徑則打開視頻
cap = cv2.VideoCapture(0)
while True:
# get a frame
# capture.read() 按幀讀取視頻
# ret,frame 是capture.read()方法的返回值
# 其中ret是布爾值,如果讀取幀正確,返回True;如果文件讀到末尾,返回False。
# frame 就是每一幀圖像,是個三維矩陣
ret, frame = cap.read()
# show a frame
cv2.imshow("capture", frame)
# waitKey() 表示等待鍵盤輸入
# 參數 1 ,表示延時1ms切換到下一幀圖像,對視頻而言
# 參數 0 ,表示只顯示當前幀圖像,相當於視頻暫停
# 參數過大,會因延時過就而卡頓
# asc = cv2.waitKey(1)
# asc 鍵盤輸入的ASCII碼,esc鍵對應的ASCII碼是27
# 它以一個字符(長度爲1的字符串)作爲參數,返回對應的 ASCII 數值
asc = cv2.waitKey(1)
# print asc
if asc == ord('q'):
break
# 釋放攝像頭
cap.release()
# 關閉所有圖像窗口
cv2.destroyAllWindows()
參考:
https://blog.csdn.net/u012005313/article/details/82146385
https://blog.csdn.net/syyyy712/article/details/87442429
https://blog.csdn.net/lxy_2011/article/details/78866703
https://www.cnblogs.com/wrjvszq/p/7305915.html