Oct-19-2019, 08:34 AM
I'm developing a video processing application using Python.
Capture (Producer) --> Processing (Consumer)
My design:
My app works. Capture process have to copy data into queue and consumer process have to copy data from queue to fill into a numpy array.
But I want to find a design which doesn't use memory copy. Below is some problems:
Capture (Producer) --> Processing (Consumer)
My design:
- Because of GIL ==> use multiprocessing (a capture process and a video processing process)
- Because image data is a large numpy array (~ 11 MB) ==> choose IPC: shared memory
- Use a single producer - single consumer ring queue to pass image data
- Ring queue contains n multiprocessing.RawArray + 2 semaphores.
My app works. Capture process have to copy data into queue and consumer process have to copy data from queue to fill into a numpy array.
But I want to find a design which doesn't use memory copy. Below is some problems:
- In producer, I use opencv-python and I can't ask opencv to capture frame into a pre-allocated buffer.
- In consumer, I don't feel safe if run computing on video frame which is on shared region (memory caching or ...).
- In method pop of my queue, I acquire an used-slot semaphore, fill slot data into numpy array, and release an empty-slot semaphore. If I want to process directly on frame data, I need to insert processing code between acquire and release semaphore. However, I can add acquire and release method in MyQueue class which other codes call them. This is still a bad design.