I am trying to pass an i01.opencv image into a python 3 aruco marker detection program using rpyc.

Found a script from alessandro that creates a jpg file when asking for it. That is a solution that will write the jpg file to disk and my aruco search could load it from there.

By having the rpyc module in the pythonModule folder of mrl I can exchange messages with my python 3 task.
import rpyc
conn = rpyc.connect("localhost", 20001")
i01.opencv.capture()
photoFileName = i01.opencv.recordSingleFrame()
res = conn.root.exposed_image(photoFileName)
Tried to step through the java code but did not see how I can pass a "pickled" image over rpyc to my detection program and avoiding having to store the files on disk, something like
 
img = i01.opencv.getOpenCVData()
pickledImg = pickle.dumps(img)
res = conn.root.exposed_image(pickledImg)
 
 

AutonomicPerfe…

7 years 1 month ago

Hi Juerg!

Looked into the problem you're having. It looks like it's a weird side effect of the Jython interpreter's implementation. Jython can pickle Python objects just fine, but when it comes to Java objects it fails, since it does not have support for pickling them. I would suggest getting the binary data from the OpenCVData object, and then using Base64 to convert that binary data into Ascii text. You can then just pass this text directly to rpyc and convert the Base64 text back into binary data in your Python 3 app. There are numerous tutorials online for using Base64, and the JavaDoc for OpenCVData and BufferedImage can show you how to extract the raw binary data. Be aware though, that sending Base64 text instead of raw binary data increases network traffic by around 33% and executing the Base64 converter takes precious CPU cycles. On a relatively fast computer, this shouldn't be a problem.

Hope this helps!

 

PS: If MRL's version of Python isn't 3, it'll cause some weird problems with rpyc. I've had some really strange stacktraces thrown at me from this, so don't be surprised if something weird happens down-the-road.

your nickname looks to fit your knowledge! Thanks for your reply

Decided now to capture the image within my python 3 program with opencv - so no pickling or conversion of image data needs to be in place.

It will also simplify my rpyc interface - the MRL-python scriptlet can simply ask 'checkForMarker' and the respond will be none or the x/y coordinates and the distance of the marker.

I like the idea of having a server per subject, so I plan to have one to control and visualize the cart, one for the marker detection and another one for the pathFinding - and I love to be able to do that in python in my own environment and not have to add it on the java side.

I hope I do not run into problems having more then one task trying to capture a frame from the same camera and that I can take 2-3 frames/second for marker detection and maybe one every other second for path finding.