I want to share my captured frame in OpenVC with my multiprocessing subprocess but video_capture.read()
creates a new object and doesnt write in to my numpy array that iam going to share by wrapping it with multiprocessing.Array()
Here is the code:
ret, frame = video_capture.read()
shared_array = mp.Array(ctypes.c_uint16, frame.shape[0] * frame.shape[1], lock=False)
while True:
b = np.frombuffer(shared_array)
ret, b = video_capture.read()
But the buffer b
gets overridden by the read()
function. So i dont write in to my buffer/shared array.
In subprocess i do following:
img = np.frombuffer(shared_array)
cv2.imshow('Video', img)
The shared array only containing the first frame of the video. How can i correctly write into the shared array to be able to read every frame in subprocess? I dont want to use queues or pipes. Shared memory is the way to go coz more processes will consume the frames.