I have gstreamer buffer and like to convert to cv2 frame in python multiprocessing
Gstreamer
gets buffer from camera in one process and buffer is passed to another process using Multprocessing.Array
Gstreamer gets buffer in one process as
processing=Multiprocess.process(target=imageprocess, args=(sharedarray,))
sharedarray=Array['d',6220800,dtype=np.uint8]
sample = sink.emit("pull_sample")
buf=sample.get_buffer()
sharedarray=np.frombuffer(buffer=buf.extract_dup(0,buf.get_size()),dtype=np.uint8)
I checked and sharedarray has length 6220800.
Then in another process,
def imageprocess(img):
image=np.frombuffer(img,dtype=np.uint8)
cv2.imshow('image ', image.reshape(1080,1920,3))
If I set dtype=np.uint8, I have error as cannot reshape array of size 49766400 into shape (1080,1920,3).
Only no error, if I set dtype=np.float64, but I have black image.
How to have correct image in this issue? I can convert image type from double to char in cv2, but wonder why source has uint8 and np.frombuffer can't retrieve uint8 directly.