Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get real distance from 16-bit value in depth image #2348

Closed
spiritas1004 opened this issue Sep 3, 2018 · 8 comments
Closed

How to get real distance from 16-bit value in depth image #2348

spiritas1004 opened this issue Sep 3, 2018 · 8 comments

Comments

@spiritas1004
Copy link

  • Before opening a new issue, we wanted to provide you with some useful suggestions (Click "Preview" above for a better view):

  • All users are welcomed to report bugs, ask questions, suggest or request enhancements and generally feel free to open new issue, even if they haven't followed any of the suggestions above :)


Required Info
Camera Model { R200 / F200 / SR300 / ZR300 / D400 }
Firmware Version (Open RealSense Viewer --> Click info)
Operating System & Version {Win (8.1/10) / Linux (Ubuntu 14/16/17) / MacOS
Kernel Version (Linux Only) (e.g. 4.14.13)
Platform PC/Raspberry Pi/ NVIDIA Jetson / etc..
SDK Version { legacy / 2.. }
Language {C/C#/labview/nodejs/opencv/pcl/python/unity }
Segment {Robot/Smartphone/VR/AR/others }

Issue Description

<I have depth images (png format), and I want to convert each pixel value (16bit) to real distance data (mm).
How can I convert it? Is there any specific formula? Thanks>

@dorodnic
Copy link
Contributor

dorodnic commented Sep 3, 2018

Each depth sensor has a depth scale value that translates pixels to meters.
Using it in C++ it would look something like:

using namespace rs2;
pipeline p;
pipeline_profile profile = p.start();
device dev = profile.get_device();
depth_sensor ds = dev.query_sensors().front().as<depth_sensor>();
float scale = ds.get_depth_scale();
frameset fs = p.wait_for_frames();
depth_frame depth = fs.get_depth_frame();
uint16_t* data = (uint16_t*)depth.get_frame_data();
uint16_t pixel = data[0];
float meters = pixel * scale;

The syntax may differ, but the APIs are very similar in other languages.

@RealSense-Customer-Engineering
Copy link
Collaborator

[Realsense Customer Engineering Team Comment]
Hi @spiritas1004,

The PNG image doesn't have the depth data info. You need to have the raw image (For example: use rs-convert tool to convert ros bag to raw) which data layout is according to the UVC spec for the depth stream.

@WeiChihChern
Copy link

@dorodnic Will depth_scale change according to different scenes or distances between the camera and objects or it's a fixed number?

@dorodnic
Copy link
Contributor

dorodnic commented Sep 4, 2018

It's a fixed number for sensor. With D400 advanced mode APIs you can adjust it a bit, to get better precision up close or further away, but that's a rather advanced use-case.
@RealSense-Customer-Engineering is correct, in that you need the original 16-bit depth data. Output of the colorizer is after histogram equalization, and while it does make the depth image look better, it essentially distorts all the distances.

@RealSense-Customer-Engineering
Copy link
Collaborator

[Realsense Customer Engineering Team Comment]
This is a similar question like #2231 and #2200.
You can refer to the BKM white paper to know more about the advanced settings.
https://www.intel.com/content/dam/support/us/en/documents/emerging-technologies/intel-realsense-technology/BKMs_Tuning_RealSense_D4xx_Cam.pdf

@WeiChihChern
Copy link

@dorodnic @RealSense-Customer-Engineering Thanks for the anwer, much appreciated!

@RealSense-Customer-Engineering
Copy link
Collaborator

[Realsense Customer Engineering Team Comment]
Hi @WeiChihChern,

Still need any support for this topic?

@lucasjinreal
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants