import cv2
import time

 

cap = cv2.VideoCapture(0)

#Check whether user selected camera is opened successfully.

if not (cap.isOpened()):
    print('Could not open video device')
else:
    print('Video device opened')

 

cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

 

while(True):
  ret, frame = cap.read()

  # 將圖片轉為灰階
  #gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

  #cv2.imwrite('test.jpg', frame)
 

  cv2.imshow('frame', frame )

  if cv2.waitKey(1) & 0xFF == ord('q'):
    break

 

cap.release()
cv2.destroyAllWindows()

 

[運行環境]

Windows 10

python 3.8.3

OpenCV 4.4.0.42

 

相關參數

fps = cap.get(cv2.CAP_PROP_FPS)
frame_size = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
              int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))

 

[參考資料]

https://blog.gtwang.org/programming/opencv-webcam-video-capture-and-file-write-tutorial/

arrow
arrow
    文章標籤
    python openCV
    全站熱搜
    創作者介紹
    創作者 門外漢 的頭像
    門外漢

    門外漢的筆記

    門外漢 發表在 痞客邦 留言(0) 人氣()