1

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.

batuman
  • 7,066
  • 26
  • 107
  • 229
  • it looks that the img is somewhere implicitly converted to float64. More code may be necessary to find the source of the bug. – tstanisl Jul 15 '19 at 07:01
  • This may be unrelated issue to your problem but you assign variable "sharedarray" twice. In means that the first object Array[] is destroyed without being used. – tstanisl Jul 15 '19 at 07:02
  • @tstanisl yes in `sharedarray=Array['d',6220800,dtype=np.uint8]` d is double and I need to change to correct format. Thank you – batuman Jul 15 '19 at 07:35
  • Now changed to ShardArray `https://pypi.org/project/SharedArray/` and things are solved – batuman Jul 15 '19 at 08:15

0 Answers0