小编TIZ*_*012的帖子

cv2.VideoCapture(0, cv2.DSHOW) 返回无

我正在尝试使用 opencv 从笔记本电脑(或外部 USB 摄像头)上的内置网络摄像头捕获视频,特别是带有 DSHOW 参数的 VideoCapture。我知道有一种方法可以设置分辨率甚至 FPS,但是当我将其包含在代码中时, API 的 DirectShow 参数不会返回任何内容。

例如;

# returns my webcam's stream, but all optional arguments are ignored
camera = cv2.VideoCapture(0)
camera = cv2.VideoCapture(0, cv2.CAP_V4L2)

# returns none and loops infinitely or errors out when *if im.any()*
camera = cv2.VideoCapture(0, cv2.CAP_DSHOW)
Run Code Online (Sandbox Code Playgroud)

这是上面之后的代码;

# should set resolution, settings are always ignored
camera.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)

while(True):
    retval, im = camera.read()
    if im.any(): # errors out when image is none
        cv2.imshow("image", im)

    k = …
Run Code Online (Sandbox Code Playgroud)

streaming opencv ubuntu-18.04 python-3.9

1
推荐指数
1
解决办法
8374
查看次数

标签 统计

opencv ×1

python-3.9 ×1

streaming ×1

ubuntu-18.04 ×1