Is it possible to use cv2.Videocapture to access video devices greater than 7 index on Ubuntu 18.04?

352 views Asked by At

Currently trying to simultaneously capturing 10 images with 10 usb cameras connected to a Raspberry Pi 4 (through board USB ports and usb hub) with Ubuntu 18.04 installed. I am using a multithreading approach to create multiple camera objects which will capture photos. I have it currently working for 4 cameras (this goes up to /dev/video7, with each physical camera occupying 2 device indicies.

The issue I am currently having is accessing any camera device greater than 7 index (5 or higher physical camera won't be accessed). I currently get the following error:

"VIDEOIO ERROR: V4L: index 8 is not correct!"

which is associated to the opencv_3.4.1 source file located in modules/videoio/src/cap_v4l.cpp. In this source file it mentions it was tested for up to 8 inputs, has anyone managed to get more than 8 input devices to capture photos using a Raspberry Pi?

I will also add bit of debugging information I have already tried.

  • Changed #define MAX_CAMERAS 8 (located in cap_v4l.cpp) to a larger value and rebuilt the opencv module however it had no affect.
  • I have also tried just accessing any camera with a device index greater than 7 by themselves and it still persists.
  • I managed to access these cameras using usb_cam on ROS melodic so they are working and connecting properly. I would prefer to get this working via opencv-python if possible but if no solution arises I will explore a ROS approach to solve the task.

Any help or advice is appreciated, thanks.

1

There are 1 answers

0
Asherk03 On

After endless debugging I have found a work around method that allows me to capture images with camera indexed higher than 7. After creating the VideoCapture() object on the first line of code below, this causes the VIDEOIO ERROR to occur still. After this I check if the camera was opened properly and if not I proceed by opening the camera again which then works.

    self.cam = cv2.VideoCapture(camID)
    if(self.cam.isOpened() is False):
        self.cam.open("/dev/video" + str(camID))