2

We are trying to simultaneously run 6 cameras on a Raspberry Pi 3B+ with an add-on 4 port USB hub that has an external power supply. The cameras are set at 15 FPS with a colour image size of 640 X 480. I found that it just works properly when I opened 2 cameras simultaneously. When I add a third camera I get this error message: "select timeout".

Below is the test code I'm using :

import cv2
import sys
print sys.argv
if len(sys.argv) < 2:
    print "Usage : > python video.py [camno1] [camno2]"
    sys.exit(0)
cam = []
cap = []
for i in range(len(sys.argv) - 1):
    cam.append(int(sys.argv[i+1]))
    cap.append(cv2.VideoCapture(cam[i]))
while True:
    for i in range(len(cam)):
        print "cam"+str(i)+" read"
        ret, frame = cap[i].read()
        if ret :
            cv2.imshow("frame"+str(i), frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
for i in range(len(cam)):
    cap[i].release()

My goal is to get a still image from each camera, one-by-one, and I don't need higher than 15 FPS. When I try to open/read and close each camera, one-by-one, it takes too long to start them all (around 1.5 sec per camera) so that the total time is more than 10 secs. So I am looking for a solution to either keep all 6 cameras open at the same time or to speed up the: open/read/close times for each camera so that my total rotation time is around one second. Anyone have any ideas?

3
  • I wouldn't be surprised if that data rate from 6 cameras at once was more than the USB alone can handle, but I haven't done the calculations. Even if the USB bus could handle the throughput, that's 6 different devices trying to send data.
    – T. M.
    Commented Jan 5, 2019 at 1:15
  • Welcome to Raspberry Pi! Please take the tour and visit the helpcenter to see how things work here. Could you please provide a datasheet of the cameras (or at least make&model)? Do you know what colordepth the images have and what compression settings are available/selected?
    – Ghanima
    Commented Jan 6, 2019 at 15:09
  • Clusterhat (look it up) is a solution that connects 4 Pi Zeros to a Pi 3+. Each could handle one or two USB cameras in an asynchronous fashion. Dunno why a moderator would want to delete this.
    – Ian Boag
    Commented Jun 7, 2020 at 8:04

2 Answers 2

2

640x480 Pixel at 24 Bit (guessing here) has an uncompressed size of 1 MB. At 15 FPS that would be 15 MB/s per camera. Six cameras for a total of 90 MB/s. That would be outside the realm of the possible. Expect a net data rate in the range of 35 to 40 MB/s at best (see here and here).

If we, however, assume a compression ratio of 1:10 (which would seem reasonable for JPG) that could be as less as 9 MB/s and well within a reasonable range for the Pi's USB 2.0 ("Hi-Speed"). But it all depends on bandwith requirements of the cameras (compression setting, colordepth) and protocol overhead. Not to mention the processing of the captured images - I take it the Pi is supposed to do something meaningful with those images.

1
  • Thank you for your analysis. We ran the same numbers as you did regarding the compression ratio and are baffled at why we can only turn on two cameras at the same time. It would be OK if we could cut down the start-up sequence to 0.2 seconds per camera instead of the present 1.5 seconds. We are doing pattern recognition on a 360 degree scan and 10+ seconds is just too long. Commented Jan 8, 2019 at 20:20
1

This intrigued me, so I tried a script that looks like

fswebcam -d /dev/video0 p0.jpg &
sleep 0.9
fswebcam -d /dev/video1 p1.jpg &
sleep 0.9
fswebcam -d /dev/video2 p2.jpg &
sleep 0.9
fswebcam -d /dev/video3 p3.jpg &

I was using bog-standard Chinese 640x480 USB cameras.

This was on a Pi 2 and 0.9 seconds is as low as I could go. Anything less and the instances start tripping over each other. Maybe it could be less on a later zippier Pi.

However if you installed a clusterhat (clusterhat.com) that would let you fire off four cameras at once - one on each of the attached Pi Zeros. That plus two cameras one second apart on the "main" pi should meet your requirements for 1.5 sec total sweep time. AFAICT taking a pic on a connected Pi Zero would not load the main system at all, so they could be (effectively) simultaneous.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.