Multiprocessing and multiple cameras?
Hello,
I have five acA1440-220um cameras synchronised by an external hardware trigger (an Arduino).
I can successfully retrieve frames data at 215-220 fps at the cameras native resolution (1440x1080) with no overtriggers events.
Looking at the usbtop command output, all my 5 cameras transfer data at a stable 330 000 kbps rate, so far so good.
I use numpy arrays as frames buffers, with two alternating buffers per camera: once the first is full, they're swapped and the second starts to fill, then they swap again, etc. For instance with buffers of length, say, 100, they are swapped every 100 frames and this works well. Still good.
Now I would like to save to the disk the buffer that is not written into, as soon as it's available (i.e as soon as the buffers swap).
I tried implementing this with two threads per camera (one 'grabbing' thread and one 'saving' thread), and with 5+1 threads (one 'saving' thread per camera and one thread to grab from all of them using a pylon camera array).
If I use less than 5 cameras, both approaches work well, all frames are saved at 215 fps and usbtop says 330 000 kbps for all cameras. Good.
However, when I have the 5 cameras connected, things get weird: if I start more than 5 threads, the framerate drops dramatically, usbtop says 20 000 kbps per camera. This is actually the case even if the 'saving' threads don't actually do anything (commenting out the bit that actually saves data).
Could this be the result of the GIL?
Is there any way around this? I couldn't manage to make use of multiprocessing with pypylon... I'm thinking 1 process per camera with two threads. Would that be achieveable?
Or am I forced to write everything in C/C++/C#?
Cheers!
yes, this could be an issue of GIL. But I am also not sure. This can also an issue of hard drive. Log the camera's streaming parameters to see if buffer underrun is occuring?
And also the time that is consumed to saving image. May it will randomly very high due to parallel activity of hard drive.
Wow! Sounds amazing @FlorentLM could you share the code? getting multiple cameras to work quickly is a pain in pypylon.. almost like the devs want us to buy software..