Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to create multiple VideoCapture Obejcts

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.

click to hide/show revision 2
No.2 Revision

updated 2016-09-26 06:03:34 -0600

berak gravatar image

How to create multiple VideoCapture Obejcts

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.

videoList=glob.glob(r'C:\Users\chaitanya\Desktop\Thesis\*.avi')
        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()

How to create multiple VideoCapture Obejcts

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.

videoList=glob.glob(r'C:\Users\chaitanya\Desktop\Thesis\*.avi')
        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()