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 depth value from saved .png img? #8649

Closed
fwf-lernen opened this issue Mar 23, 2021 · 3 comments
Closed

How to get depth value from saved .png img? #8649

fwf-lernen opened this issue Mar 23, 2021 · 3 comments

Comments

@fwf-lernen
Copy link

fwf-lernen commented Mar 23, 2021

00008

Required Info
Camera Model D455
Firmware Version 05.12.11.00
Operating System & Version Ubuntu 16.04
Kernel Version (Linux Only) 4.15.0
Platform PC
SDK Version 2.42.0
Language C

Issue Description

Like #5546 (comment) ,I have saved depth image by
cv::Mat matDepth(cv::Size(imgWidth,imgHeight) , CV_16UC1 , (void *)depth.get_data() , cv::Mat::AUTO_STEP)
However I have no idea how to get actual distance from saved imgs through cv::imread.
In rs_sensor.h,
RS2_FORMAT_Z16 , /**< 16-bit linear depth values. **The depth is meters is equal to depth scale * pixel value**. */
So, is that means I just need to use cv::imread and multiply a depth scale factor? If so, how can I get the scale factor?

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Mar 23, 2021

Hi @fwf-lernen The C++ script in the link below, as part of a discussion on retrieving depth values from a PNG image with imread, may be useful to you:

#2200 (comment)

An alternative approach to the problem is described in this link:

https://stackoverflow.com/questions/51728827/using-a-depth-map/51759748#51759748

However, when RealSense depth data is saved as a PNG, most of the depth information is lost. It is therefore better if possible to save the data as a .raw format image file that preserves the depth detail. The link below provides scripting for retrieving depth information from a .raw file.

#2231 (comment)

Instead of obtaining the depth information from a PNG image, there is also the option of converting the cv::mat back into a RealSense rs2::frame, as described in the link below.

#2634

@fwf-lernen
Copy link
Author

@MartyG-RealSense Thank you very much! That's really helpful.

@MartyG-RealSense
Copy link
Collaborator

You are very welcome @fwf-lernen - thanks for the update!

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

2 participants