title: Insight on Multiple Webcam Capture with python and OpenCV vs VideoCapture
body: <p>I'm experimenting with trying to capture an image from multiple webcams simultaneously (or near-simultaneously).  I've been playing with <strong>OpenCV</strong> and with <strong>VideoCapture</strong> and programming in python.  But have some confusion and hoped someone could help explain things...</p>
  
  <p>To Start, I tried VideoCapture (Markus Gritsch's work found here: <a href="http://videocapture.sourceforge.net/" rel="noreferrer">http://videocapture.sourceforge.net/</a>).
  This is a very easy to use add-in for python.  If I just wanted to capture a simple image. It works just fine... for the most part.</p>
  
  <p>My setup is 2 cheapie webcams in a USB hub on a single USB port and my laptop's built-in webcam.</p>
  
  <p>I have read all about using the same model webcam on the same USB bus and how it may not work, etc. but decided to give it a go. (I also have some photobooth program that I must have installed eons ago called "Cyberlink YouCam" For some reason, this program "looks" like a camera to both OpenCV and VideoCapture.</p>
  
  <p>VideoCapture connects to and captures from each camera like this:</p>
  
  <pre><code>Cam0 = Device(devnum=0)
  Cam0.saveSnapshot("filename0.jpg")
  del Cam0
  Cam1 = Device(devnum=1)
  Cam1.saveSnapshot("filename1.jpg")
  del Cam1
  </code></pre>
  
  <p>With VideoCapture and the setup I described, I can independently capture from all the cameras on my system (4 total, including the YouCam... 0 - 3)</p>
  
  <p>The problem is that this program does not seem to be able to connect to more than one camera at the same time... if I don't close the previous camera instance, it simply freezes and I have to disconnect and reconnect the first webcam from USB to regain access to it.</p>
  
  <p>This won't work:</p>
  
  <pre><code>cam0 = Device(devnum=0)
  cam1 = Device(devnum=1)
  cam0.saveSnapshot("filename0.jpg")
  cam1.saveSnapshot("filename1.jpg")
  del cam0
  del cam1
  </code></pre>
  
  <p>Cam0 will open, but that is the end of it.  Frozen.</p>
  
  <p>Another thing with VideoCapture is that on the cheapo webcams, there is a major delay (almost a second) until the picture comes alive... in order to do a successful capture, I had to do something like this:</p>
  
  <pre><code>Cam1 = Device(devnum=1)
  Cam1.saveSnapshot("filename1.jpg") #gets the camera going and saves black image
  time.sleep(.75) #delay
  Cam1.saveSnapshot("filename1.jpg") #captures the image second time around
  </code></pre>
  
  <p>Effectively saving the image twice...</p>
  
  <p>I wouldn't have minded if the images from each camera were a few milliseconds apart taken in squence</p>
  
  <pre><code>#open connection to cam, take image
  #close connection to cam
  
  #connect to next cam, take next image
  #close connection to cam
  
  #etc.
  </code></pre>
  
  <p>But the delay was way too much... I thought the delay was the cheap webcams, but I saw a different result with Open CV so it must be VideoCapture's fault.</p>
  
  <p>For one thing, I COULD open more than one camera at the same time with OpenCV... but only of different types. (One of the cheapo cams and my built-in cam... and / or the Cyberlink program)  OpenCV seemed to see the 2 cheapo cams on the same USB hub as one (it only turned on one of the cams.)</p>
  
  <pre><code>capture0 = CaptureFromCAM(0) #this was Cyberlink Program
  capture1 = CaptureFromCAM(1) #this was cheapo cam
  capture2 = CaptureFromCAM(2) #this was built-in cam
  #CaptureFromCAM(3) resulted in error... did not find a 4th "camera"
  
  frame0 = QueryFrame(capure0)
  frame1 = QueryFrame(capure1)
  frame2 = QueryFrame(capure2)
  cv.SaveImage("filename0.jpg",frame0)
  cv.SaveImage("filename1.jpg",frame1)
  cv.SaveImage("filename2.jpg",frame2)
  </code></pre>
  
  <p>Whereas VideoCapture could see the 2 similar cameras independently, OpenCV could not.</p>
  
  <p>Anyone know why that would be?  How are the two packages interacting with the computer differently that one can determine different cams on the same USB and the other cannot?</p>
  
  <p>Secondly, OpenCV opened my cheap cams instantaneously... no .75 second delays there.</p>
  
  <p>Again, I am curious how the two packages (videoCapture vs OpenCV) communicating with the cameras differently from each other?</p>
  
  <p>What I am ultimately interested in doing is being able to capture from 2 or 3 cameras at the same time (or close to it, if there were a few milliseconds delay, that is fine).  Looks like OpenCV would be the package of choice, however, I am trying to understand better how the software is interacting with the cameras.</p>
  
  <p>Thank you all for the insight!</p>
  
  <p>J</p>