Syncing multiple cameras with the multiprocessing library

asked 2019-12-27 05:34:46 -0600

arnthorg gravatar image

I have 4 usb cameras and I was interested in using VideoCapture.grab to synchronize them.

I need 4 processes, one for each camera, to be able to distribute the load between the 4 cores of the Rpi 4B.

I tried using a separate process to grab the images and another to Videocapture.retrieve but retrieve returns True and a zero matrix

import cv2
import time
import multiprocessing

def derp(capp):
    print(cv2.VideoCapture.grab(capp))
    time.sleep(2)
    print(cv2.VideoCapture.retrieve(capp))

cap = cv2.VideoCapture(0)

process = multiprocessing.Process(target=derp, args=(cap,))

process.start()
time.sleep(1)
print(cv2.VideoCapture.retrieve(cap))
time.sleep(2)
print(cv2.VideoCapture.retrieve(cap))

the retrieve call in derp() returns an image but the other two in "main" return zero matrixes.

Can anyone tell me why that is the case?

Is that maybe not a good approach to the problem of synchronizing the cameras?

edit retag flag offensive close merge delete

Comments

I have 4 usb cameras

apart from your multiprocessing problems, you won't be able to get the data through a single usb hub

berak gravatar imageberak ( 2019-12-28 03:37:02 -0600 )edit

yeah, that was a problem initially 3 cams was okay but 4 too much, but after changing the encoding to MJPEG the throughput was enough.

arnthorg gravatar imagearnthorg ( 2019-12-28 07:53:51 -0600 )edit