How to create multiple VideoCapture Objects

2024/10/9 8:29:34

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.

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()

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:breakindices.append(cap.get(1))frames.append(indices)cap.release()cv2.destroyAllWindows()
Answer

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:breakframes.append(frame)# now "frames" holds your captured images.
https://en.xdnf.cn/q/118606.html

Related Q&A

How to read Data from Url in python using Pandas?

I am trying to read the text data from the Url mentioned in the code. But it throws an error:ParserError: Error tokenizing data. C error: Expected 1 fields in line 4, saw 2url="https://cdn.upgrad.…

Testing multiple string in conditions in list comprehension [duplicate]

This question already has answers here:How to test multiple variables for equality against a single value?(31 answers)Closed 6 years ago.I am trying to add multiple or clauses to a python if statement…

Filter range from two dates in the same query Django/Python

I need the result from a query that filters two dates from the same model. I need to get in the result 5 days (today plus 4 days) from original date and sale from target date (today plus 4 more days) b…

Python While/For loop

how can I make this into a while loop and output the same thing????for x in range(56,120) :if (x < 57) :summation = 0summation = x + summationif (x == 119) :print (“Sum of integers from 56 to 1…

Read a file into a nested dictionary?

Say I have a simple file like so holding arbitrary values:A, 20, Monday, 14, Tuesday, 15, Tuesday, 16 B, 40, Wednesday, 14, Friday, 12How would I get it into a nested dictionary so that each k/v pair l…

Using .replace function

I have a code with more than 2500 lines that contains several references to GIS layers. I need to replace these layers in the code for several web maps so I have to find a way to automate a find and re…

Python Turtle unit of measurement

When we instantiate a turtle object, we can draw a circle. I wonder about the radius parameter of the circle() method. import turtle myTurtle = turtle.Turtle() myTurtle.circle(50)What is the unit of me…

Python reverse() vs [::-1] slice performance [duplicate]

This question already has answers here:Difference between reverse and [::-1](2 answers)Time complexity of reversed() in Python 3(1 answer)Closed last year.Python provides two ways to reverse a list: Li…

Django Callback on Facebook Credits

I would like to use Facebook Credits with my Django Application.In the Facebook Credits documentation, there is only a sample for the callback page in PHP (https://developers.facebook.com/blog/post/489…

Remove \n from each string stored in a python list

I have a python list in which look like this:my_list = [OFAC\n, Social Media Analytics\n, Teaching Skills\n, Territory...\n, Active Directory...\n, Business Research\n, Call Center...\n, Treatment of d…