D400: depth frames in Python vs. Java
Hello there!
I have worked with RealSense D415 and D435i models for quite a while now. I used Python all the way but recently tried Java because of some system requirements. I got very surprised when I found out that similar scripts and the same camera produce very different depth frames depending on the language used.
As an example, this minimal code in Python:
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
pipeline.start(config)
frames = pipeline.wait_for_frames()
depth_frame = frames.get_depth_frame()
depth_image = np.asanyarray(depth_frame.get_data())
cv2.imwrite(path.png, depth_image*100)
produces a frame with only 17 different depth values, while this Java code:
Pipeline pipeline = new Pipeline();
Config cfg = new Config();
cfg.enableStream(Stream.Depth, 640, 480, Format.Z16, 30);
PipelineProfile pp = pipeline.start(cfg);
FrameList frames = null;
frames = pipeline.waitForFrames();
DepthFrame depthFrame = frames.getDepthFrame();
BufferedImage depthImage = ImageUtils.createBufferedImage(depthFrame);
File depth = new File(path);
ImageIO.write(depthImage, "PNG", depth);
produces a frame with 256 different values. See both examples below.
Why does this happen? Is there a way to make them alike? So far I am just clustering the frames taken with Java into the depth values that the Python SDK registers.
Thanks!!


-
Hi Llorcarodriguez This is a difficult question, as there are only a couple of good examples that I know of to refer to regarding a RealSense example of a Java script for exporting a camera depth frame to bitmap image in an Android application.
https://github.com/IntelRealSense/librealsense/issues/5446
https://github.com/IntelRealSense/librealsense/issues/6089
The simpler image from Python looks like a more correct representation of a typical RealSense depth frame than the more complex image from your Java code does.

Given the lack of reference materials available about exporting to a bitmap image from Java, I would recommend looking at the code in the two links that I shared above to see whether it provides useful insights.
-
Hello MartyG!
First of all, thank you very much for the work you put into these forums.
I will look into the links. I am using Java in PC through Maven, Gradle and IntelliJ anyway, not any sort of android development. Still very intrigued about what goes into the Java wrapper to make the depth pictures look so much more sensible.
Have a nice day!
-
You are very welcome, Llorcarodriguez :)
Outside of Android, the two Java compatibility wrappers available for the RealSense SDK are unofficial and contributed by RealSense users. You can find them under the Community Projects heading of the SDK examples directory at the link below.
Of those two wrappers, the one by cansik is the most recently updated one and has some example programs.
https://github.com/IntelRealSense/librealsense/tree/master/wrappers#community-projects
Please sign in to leave a comment.
Comments
3 comments