How to pickle pyrealsense2.composite_frame objects?
Hello,
I'm trying to parallelize the computation of three D415 realsense cameras so I have to encapsulate all the processing within one function (I'm using pyrealsense2 Python wrapper and multiprocessing module).
In order to pass the frames as argument, they need to be serialized by some library (pickle by default) but I haven't found how to do it.
TypeError: can't pickle pyrealsense2.pyrealsense2.composite_frame objects
My code schema is the following:
- Initialize 3 pipelines for the three cameras.
- While True
- Get frames from three cameras.
- Initialize one process for each camera with frames as argument in parallel.
- Retrieve results from the three cameras
Any idea?
Best regards,
Daniel
-
I don't personally know of code for doing this with Pickle and Python, though there has been a RealSense community member who got two 400 Series cameras running in parallel and posted a C++ script. It may be a useful reference source about a general structure for a Python-based version of it.
https://github.com/IntelRealSense/librealsense/issues/2219#issuecomment-412899468
-
Hi Daniel Dsalvadu,
I have exactly the same issue, did you solve it?
Best regards Chris
-
Hi Chris Geiger The EtherSense Python ethernet networking project for connecting multiple cameras to a host computer uses pickle in its server and client code.
A couple of days ago, a RealSense user also shared their Python multicam project, which does not seem to be based on pickling but I offer the link in case you are interested.
https://github.com/ivomarvan/samples_and_experiments/tree/master/Multiple_realsense_cameras
-
Hi MartyX Grover,thanks for the links! My main problem is the parallel processing: I have only one camera, and I would like to do the instance sementation and some calculations in the first process (core 1) and the whole visualization in a second process. I also use multiprocess as Dsalvadu, and I also get following error: TypeError: can't pickle pyrealsense2.pyrealsense2.pipeline objects. Do you have any idea what's the error causing?
Thanks in advance
-
There are very few RealSense related Python resources involving pickling unfortunately, and not many about multiprocessing either. I will add a Python link about RealSense multiprocessing suggested by a RealSense team member.
https://gist.github.com/mengyui/8d00dbbefff65e70db9691965b99efb8
The Python case in the link below also discussed problems with saving composite objects that the RealSense user in the case believed to be related to pickling. The solution that worked for them was to use the SDK's Keep() function to store frames in memory.
-
Hi,
I have been trying multiprocessing as well. MartyG your first link is working but I use a class to instantiate the camera and the start() method is not working because I have issues passing Queues back and forth.
I can prepare a couple of code sample files if needed.
Has someone succeeded in using mp and classes for the realsense ?
thank you
-
Hi Brice Miramont The RealSense discussion in the link below features a RealSense Python user who was importing multiprocess and using classes, and having problems with queues. It may provide some useful insights.
-
Hi MartyG, the provided example is using threads and not multiprocessing. Example is working but does not help with the error I have: when I pass queues in the run() method I have the error mentioned at the start of this thread. A multiprocess exemple in Python provided by Intel would be great :)
I'll try to serialize the frames with different methods (I'm new to Python)
thank you,
Brice
-
There are few Python multiprocessing scripting references available other than the ones in the links below.
https://github.com/IntelRealSense/librealsense/issues/7365
https://github.com/IntelRealSense/librealsense/issues/9085
https://github.com/IntelRealSense/librealsense/issues/7968#issuecomment-744538550
Please sign in to leave a comment.
Comments
10 comments