【问题标题】:Facecam Video does not open with cv2.VideoCapture() and cannot be readFacecam 视频无法使用 cv2.VideoCapture() 打开并且无法读取
【发布时间】:2021-04-06 03:10:31
【问题描述】:

我是 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()

【问题讨论】:

    标签: python opencv


    【解决方案1】:

    这对我有用

    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()
    

    【讨论】:

      猜你喜欢
      • 2021-03-22
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      • 1970-01-01
      • 1970-01-01
      • 2023-01-11
      • 2021-11-08
      • 1970-01-01
      相关资源
      最近更新 更多