title: How to capture multiple camera streams with OpenCV?
body: <p>I have to stitch the images captured from many (9) cameras. Initially, I tried to capture the frames from 2 cameras with rate 15 FPS. Then, I connected 4 cameras (I also used externally powered USB hub to provide enough power) but I could only see only one stream.</p>
  
  <p>For testing, I used the following script:</p>
  
  <pre><code>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)
              small = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
              frames_preview.append(small)
  
      for i, frame in enumerate(frames_preview):
          cv2.imshow('Cam {}'.format(i), frame)
  
  
      if cv2.waitKey(1) &amp; 0xFF == ord('q'):
          break
  
  # When everything is done, release the capture
  for video_capture in video_captures:
      video_capture.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>Is there any limit for the number of cameras? Does anyone know what is the right way to capture frames from multiple cameras?</p>