Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

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

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.

question from:https://stackoverflow.com/questions/65948516/is-it-possible-to-use-cv2-videocapture-to-access-video-devices-greater-than-7-in

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...