相关疑难解决方法(0)

如何使用 OpenCV 捕获多个摄像头流?

我必须拼接从许多 (9) 台相机捕获的图像。最初,我尝试从 2 个相机以 15 FPS 的速率捕获帧。然后,我连接了 4 个摄像头(我还使用了外部供电的 USB 集线器来提供足够的电力)但我只能看到一个流。

为了测试,我使用了以下脚本:

import numpy as np
import cv2
import imutils

index = 0
arr = []
while True:
    cap = cv2.VideoCapture(index)

    if not cap.read()[0]:
        break
    else:
        arr.append(index)
    cap.release()
    index += 1

video_captures = [cv2.VideoCapture(idx) for idx in arr]

while True:
    # Capture frame-by-frame
    frames = []
    frames_preview = []

    for i in arr:
        # skip webcam capture
        if i == 1: continue
        ret, frame = video_captures[i].read()
        if ret:
            frames.append(frame) …
Run Code Online (Sandbox Code Playgroud)

python performance multithreading opencv video-streaming

12
推荐指数
1
解决办法
2万
查看次数