Getting distance from depth map

Forgive me if this is a silly question but I just found there is something wrong with what I think of this.


In the playground, I think the black part should be yellow but they are not.
The left point and the center point have different distance to camera but they have same depth value, it is strange for me.

1 Like

it’s prolly coz depth map measures distance from the near plane and not the camera position exactly.

we can rectify this taking the camera fov into account.

Since if we know the fov, then we know how much the angle of view changes from left of screen to right of screen and we can correct the depth we read by calculating the falloff.

That’s too much math tho.

here’s a kinda visually coherent approximation


Hello :slight_smile:

It’s the normal behavior of OpenGL based rendering, and by the way that’s why it’s called “Depth”. Best way to understand this is taking the camera as a boat over the see :

The “Depth” is indeed the same for points A and B, even if the distance is not the same. Depth map is a depth map, not a distance map.

Now, if you need the distance you can easily create a function depth_to_distance which compute distance from depth map. It’s just a matter of trigonometric cosinus computation, using the FOV of the camera, the image size, and the 2D coordinates of the considered point :slight_smile:



Thanks for your explainations! I’ve made a playground that work.