【问题标题】:Not able to fetch the video from the camera using OpenCV无法使用 OpenCV 从摄像头获取视频
【发布时间】:2019-12-19 15:17:35
【问题描述】:

我无法从笔记本电脑的摄像机中捕捉视频

我正在使用 OpenCV-Python。我正在尝试获取相机视频,但只显示单帧。

import cv2

# 1, -1, 0
cap = cv2.VideoCapture(0);

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

    gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)

    #cv2.imshow('frame', frame)
    cv2.imshow('frame', gray)

    if cv2.waitKey(0): #& OxFF == ord('q'): Error so commented
        break

cap.release()
cv2.destroyAllWindows()

期待摄像头视频,但只接收到单帧。

【问题讨论】:

    标签: python-3.x opencv


    【解决方案1】:

    如果您提供0 作为cv2.waitKey 的参数,它会等到有按键按下。如果您将0 更改为1(或其他一些小数字),脚本就可以工作。

    出于兴趣,即使不更改 0,您也可以看到脚本“有效”。如果您反复点击任何键,框架就会更新。

    0xFF 的问题是您尝试使用O(字母)而不是0(数字),所以python 无法识别它。

    完整列表:

    import cv2
    
    # 1, -1, 0
    cap = cv2.VideoCapture(0);
    
    while(True):
        ret, frame = cap.read()
    
        gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
    
        #cv2.imshow('frame', frame)
        cv2.imshow('frame', gray)
    
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    
    cap.release()
    cv2.destroyAllWindows()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-29
      • 2021-01-06
      • 1970-01-01
      • 2018-07-26
      • 1970-01-01
      • 1970-01-01
      • 2021-10-21
      • 1970-01-01
      相关资源
      最近更新 更多