簡體   English   中英

Facecam 視頻無法使用 cv2.VideoCapture() 打開且無法讀取

[英]Facecam Video does not open with cv2.VideoCapture() and cannot be read

我是 OpenCV 的新手,剛開始學習我正在使用 macOS,python 版本 3.8.1

我的代碼:

import cv2
# takes facecam video
cap = cv2.VideoCapture(-1)

while True:
    # Capture frame-by-frame
    ret, frame = cap.read()
    if cap.isOpened() == True:
        # Our operations on the frame come here
        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

        # Display the resulting frame
        cv2.imshow('frame',gray)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
         cap.open(-1)

    # When everything done, release the capture
    cap.release()
    cv2.destroyAllWindows()

這對我有用

import cv2
cap = cv2.VideoCapture(0)

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

    cv2.imshow("Webcam Capture", frame)
    

    if cv2.waitKey(1) & 0xFF == ord("A"):
        break


cap.release()
cv2.destroyAllWindows()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM