2
$\begingroup$

How can I get the depth in meters? I need the "real" distance from the camera to each pixel.

As the next picture but each pixel values representing the distance in meters to the camera.

Depth image rendered from Z pass

I am creating my first project with Blender, which builds an animation to obtain rendered images from different viewpoints. I am setting several values for the camera location using python scripts and using the Depth option (Z pass) in Render Layers Node.

I already read many answers about it, but I still don't understand how to set correctly the camera intrinsic parameters for real depth.


Something is wrong, I need this pixel value closed to 7m, or depending on the camera distance, but I am obtaining the next results.

Properties:

enter image description here enter image description here

Actual depth result with a normalization node: enter image description here

Actual depth result without normalization: enter image description here

$\endgroup$
  • 2
    $\begingroup$ If need the "real" distance from the camera to each pixel, then avoid normalizing. By normalizing you are already changing the scale. Keep the Z pass in OpenEXR format to keep the information undistorted. $\endgroup$ – cegaton Mar 7 '18 at 3:00
  • 3
    $\begingroup$ Which render engine are you using? In Cycles the Z pass is the distance from the camera, but in BI the Z pass is the distance from the view plane $\endgroup$ – gandalf3 Mar 7 '18 at 4:07
  • $\begingroup$ Normalizing takes the high and low values of your data and makes them 1 and 0 respectively, while converting the rest of the values to fit in between. Your data is not only compressed (with the resulting loss in precision) but could also suffer if it is saved using 8 bit formats and will be further distorted if it is encoded using any color transform (like sRGB). $\endgroup$ – cegaton Mar 7 '18 at 7:05
  • $\begingroup$ The second image (not normalized) is actually problematic because has been saved in a format that is not designed for the needs of storing distance information: any values beyond one will be ignored if represented in display referred formats. OpenEXR will keep your data (think always of the Z-depth pass as data not as an image) in float precision, with no scaling or any other form of distortion. $\endgroup$ – cegaton Mar 7 '18 at 7:06
  • $\begingroup$ @gandalf3 I am using Blender Render. I need the distance from the camera to the object considering its geometric centroids. $\endgroup$ – Marco Ruiz Jul 15 '18 at 3:29
2
$\begingroup$

The Z pass is the absolute distance from the camera to objects in the scene for every given pixel on the image. The camera is the 0 on the scale and the units used for its values are the working units set for the scene (blender units, meters, cm, inches, etc).

enter image description here

The minimum and maximum values are clipped according to the camera's start and end clip distances.

enter image description here

$\endgroup$
  • $\begingroup$ I set the metric, the unit scale, and the clipping start-end to 1m-100m; but I still get a distance measurement different from the real one (7m in this case). The pixel value at the center is 54 with normalization node and 255 for all image pixels (pure white) without normalization. $\endgroup$ – Marco Ruiz Mar 5 '18 at 23:37
  • 2
    $\begingroup$ don't normalize and use EXR (Z pass is not a picture, is linear data) $\endgroup$ – cegaton Mar 6 '18 at 1:50
  • $\begingroup$ Even using EXR, I am getting an incorrect value for the distance. $\endgroup$ – Marco Ruiz Jul 15 '18 at 3:31
  • $\begingroup$ Please edit your original question and add an update detailing how you are reading the information on the EXR and what kind of values you are getting vs those that you expect to get. $\endgroup$ – cegaton Jul 15 '18 at 5:26
0
$\begingroup$

In order to get the real 'meters' you need to define what the scale is. This can be done in Scene => Units.

This configured unit is also used for the depth pass. So a Z-Value of 1.0 when 1 blender unit = 1 meter means that the depth is 1 meter.

enter image description here

enter image description here

Please note that if you use a different Unit scale. You also have to apply this to the Z-Value of the Depth pass.

$\endgroup$
  • $\begingroup$ Scene units/unit scale have no affect on the Z pass $\endgroup$ – gandalf3 Mar 7 '18 at 4:05
  • $\begingroup$ @gandalf3 the depth buffer uses the same unit. Yes it does not change values, but it gives meaning to the values. Will change the answer to reflect this. Thanks for pointing out $\endgroup$ – J. Bakker Mar 7 '18 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.