alliedvision / VmbPy

Python API of the Vimba X SDK
BSD 2-Clause "Simplified" License
24 stars 8 forks source link

Pickling error on Python multiprocess queue #7

Open jojje42 opened 1 year ago

jojje42 commented 1 year ago

Hi, Trying to change from Python multithreading to multiprocessing. I can queue the frames using threads queue (queue.Queue) but I'll get pickling error during usage of multiprocessor.Queue. I think the reason is that thread queues are skipping serialization in some cases while multiprocessor queues always serialize.

    # Example
    def __call__(self, cam: Camera, stream: Stream, frame: Frame):
        if frame.get_status() == FrameStatus.Complete:
            frame_cpy = copy.deepcopy(frame)
            rgb_frame = frame_cpy.convert_pixel_format(PixelFormat.Bgr8)
            cv_img = rgb_frame.as_opencv_image()
            my_queue.put_nowait(cv_img)
Error
_pickle.PicklingError: Can't pickle <class 'vmbpy.frame.c_ubyte_Array_9560448'>: attribute lookup c_ubyte_Array_9560448 on vmbpy.frame failed

I've tried to make a copy of nd array, e.g. cv_img2 = cv_img.copy(), with the same error.

emasty commented 1 year ago

I can confirm this behaviour. Could you find a solution yet?

There is a multithreading example available, but it doesn't do much due to GIL. Multiprocessing would be the real example required.

emasty commented 1 year ago

I did notice that the issue does not occur once the frame is resized using cv2.resize. I did not have a closer look why though. But for a quick&dirty test, resizing the image with the original resolution does work.

jojje42 commented 1 year ago

I didn't find a solution. Very interesting with the "resize" solution, thanks! Haven't had time to try it but will comment here when tested.