Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Syncing multiple cameras with the multiprocessing library

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?