[python] 擷取視訊鏡頭

回覆文章
Lexaul
文章: 231
註冊時間: 2019-10-18, 14:28

[python] 擷取視訊鏡頭

文章 Lexaul » 2022-01-27, 14:39

參考資料:https://www.itread01.com/content/1545212010.html
延伸閱讀:https://shengyu7697.github.io/python-opencv-resize/

使用openCV
pip install opencv-python

Code

代碼: 選擇全部

import cv2

cap = cv2.VideoCapture(0)        #開啟攝像頭

while(1):
    # get a frame
    ret, frame = cap.read()
    # show a frame
    cv2.imshow("capture", frame)     #生成攝像頭視窗
    
    if cv2.waitKey(1) & 0xFF == ord('q'):   #如果按下q 就截圖儲存並退出
        cv2.imwrite("D:/test.png", frame)   #儲存路徑
        break

cap.release()
cv2.destroyAllWindows()
[email protected]
github.com/Lexaul

回覆文章