本文介绍了如何创建多个VideoCapture对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建多个VideoCapture对象,以便将多台摄像机的视频拼接到一个视频混搭中.

I wanted to create multiple VideoCapture Objects for stitching video from multiple cameras to a single video mashup.

例如:我具有要使用下面显示的视频捕获"对象读取的三个视频的路径,以从各个视频中获取帧,以便将其用于写作.

for example: I have path for three videos that I wanted to be read using Video Capture object shown below to get the frames from individual videos,so they can be used for writing.

预期:用于N个视频路径

Expected:For N number of video paths

   cap0=cv2.VideoCapture(path1)
   cap1=cv2.VideoCapture(path2)
   cap2=cv2.VideoCapture(path3)
   .
   . 
   capn=cv2.VideoCapture(path4)

类似地,我还想创建框架对象来读取类似的框架

similarly I also wanted to create frame objects to read frames like

ret,frame0=cap0.read()
ret,frame1=cap1.read()
.
.
ret,frameN=capn.read()

我尝试在存储路径的列表上使用for循环,但是每次只读取一条路径并且仅为该特定视频存储帧.我已经在许多论坛中看到可以在C ++中创建多个捕获对象但在动态情况下的python中不是这样,在这种情况下,事先无法知道视频数量.到目前为止,这是我的代码

I tried using for loop on the lists where the paths are stored but every time only one path is read and frames are stored for that particular video only.I have seen in many forums it is possible to create multiple capture objects in C++ but not in python in dynamic scenario where number of videos are not known before hand.This is my code until now

frames=[]
for path in videoList:
    indices=[]
    cap = cv2.VideoCapture(path)

    while(cap.isOpened()):
        ret,frame=cap.read()
        if not ret:
           break
        indices.append(cap.get(1))
    frames.append(indices)
    cap.release()
    cv2.destroyAllWindows()

推荐答案

我不是python程序员,但解决方案可能是这样的:

I'm not a python programmer, but probably the solution is something like:

frames = []
caps = []
for path in videoList:
    caps.append(cv2.VideoCapture(path))

for cap in caps:
    while cap.isOpened():
        ret, frame = cap.read()
        if not ret:
            break
        frames.append(frame)

# now "frames" holds your captured images.

这篇关于如何创建多个VideoCapture对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 16:59