我必须拼接从许多 (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)