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

Get distance from a saved depth image #10275

Closed
mnauf opened this issue Mar 1, 2022 · 8 comments
Closed

Get distance from a saved depth image #10275

mnauf opened this issue Mar 1, 2022 · 8 comments

Comments

@mnauf
Copy link

mnauf commented Mar 1, 2022

Required Info
Camera Model D415
Firmware Version 05.13.00.50
Operating System & Version Win10
Kernel Version (Linux Only) N/A
Platform PC (Lenovo Legion 5i
SDK Version 2.50.0
Language Python
Segment not sure what it means

Issue Description

How to get distance, given that I have a depth image from D415 saved in my machine. Please note, that I can't do Depth = depth_frame.get_distance(int(x),int(y)) here, since it is not a Livestream. I know the depth scale = 0.0010000000474974513.

@mnauf mnauf changed the title Get distance from a static depth image Get distance from a saved depth image Mar 1, 2022
@mnauf
Copy link
Author

mnauf commented Mar 1, 2022

Does depth_image[int(cordinate[1])][int(cordinate[0])] * depth_scale give us distance in meters?

@mnauf
Copy link
Author

mnauf commented Mar 1, 2022

But doing so gives me distance = 0.216 meters, even though the object was at least 2.1 meters away. Please note that I have already done on-chip calibration, so calibration shouldn't be an issue.

@mnauf
Copy link
Author

mnauf commented Mar 1, 2022

This is what depth image looks like and this is how I read it:
cv2.imread(FILENAME, flags=cv2.IMREAD_ANYDEPTH)
260_depth

@mnauf
Copy link
Author

mnauf commented Mar 1, 2022

When I multiply this depth_scale with a Livestream depth image in example align-depth2color.py, it gives the correct distance, because depth_image values there aren't in between 0 to 255

@mnauf
Copy link
Author

mnauf commented Mar 1, 2022

I had saved the depth_image by
cv2.imwrite(FILENAME, depth_image)

@MartyG-RealSense
Copy link
Collaborator

MartyG-RealSense commented Mar 1, 2022

Hi @mnauf If you are not using get_distance then an alternative method of obtaining the real-world distance in meters is to multiply the raw pixel depth value uint16_t by the depth unit scale (which is 0.001 by default on the 400 Series camera models). There is a discussion about this subject at #7264

@mnauf
Copy link
Author

mnauf commented Mar 3, 2022

@MartyG-RealSense Thanks. The issue was, my saved depth image values were in uint8, so I dumped them again using uint16, and then everything worked fine. You may close this issue now.

@MartyG-RealSense
Copy link
Collaborator

It's excellent to hear that you achieved a solution, @mnauf - thanks very much for the update! As you suggested, I will close this case. Thanks again!

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