2

I am using Opencv 3 and python 3.6 for my project work. I want to set up multiple cameras at a time to see video feed from all of them at once. I want to do facial recognition using it. But there is no good way to do this. Here is one link which I followed but nothing happens: Reading from two cameras in OpenCV at once

I have tried this blog post as well but it only can capture one image at a time from video and cannot show the live video. https://www.pyimagesearch.com/2016/01/18/multiple-cameras-with-the-raspberry-pi-and-opencv/

Previously people have done this with C++ but with python it seems difficult to me.

Vickel
  • 7,879
  • 6
  • 35
  • 56
Urvish
  • 643
  • 3
  • 10
  • 19

3 Answers3

1

the below code works and i've tested it, so if u're using two cameras 1 a webcam and another is a usb cam then, (adjust videocapture numbers if both are usb cam)

import cv2


cap1 = cv2.VideoCapture(0)
cap2 = cv2.VideoCapture(1)

while 1:

  ret1, img1 = cap1.read()
  ret2, img2 = cap2.read()

  if ret1 and ret2:

      cv2.imshow('img1',img1)
      cv2.imshow('img2',img2)

      k = cv2.waitKey(100) 
      if k == 27: #press Esc to exit
         break

cap1.release()
cap2.release()
cv2.destroyAllWindows()
bharatk
  • 4,202
  • 5
  • 16
  • 30
Ahmed
  • 89
  • 10
  • 1
    what If we have more than 10 webcams. any solution using looping ?? or any predefined method or library ?? – M. D. P Oct 03 '18 at 04:59
  • I dont know how you are gonna add 10 webcams in one pc anyways just add cap3 = cv2.VideoCapture(3) and keep adding ..although i should tell you that the program would run very slowly the more you webcams you add – Ahmed Oct 04 '18 at 14:33
0

my experience with R_Pi & 2 cams showed the limitation was the GPU on the R_Pi. I used setup to allocate more GPU memory to 512Mb. It would slow down with more than 10 fps with 2 cams. Also, the USB ports restricted the video stream.

0

One solution is to put each camera on it's own usb controller. I did this using a 4 channel PCIe card. The card must have a separate controller for each port. I'm just finishing a project where I snap images from 4 ELP usb cameras, combine the images into one, and write it to disk. I spent days trying to make it work. I found examples for two cameras that worked with my laptop camera and an external camera but not two external cameras. The internal camera is on a different usb controller than the external ports...

GregR
  • 1
  • 1