PIXELBANKv9.1.0
Menu

Convert Rectified Disparity to Z-Depth

Implement a function to calculate depth Z from given disparity d, focal length f, and baseline B in a rectified stereo setup. This conversion is crucial in depth estimation tasks, where understanding the relationship between disparity and depth is essential.

The concept of rectified stereo involves two cameras with parallel image planes, allowing for a straightforward calculation of depth from disparity. The disparity is the difference in pixels between the same point in the left and right images, while depth is the actual distance of the point from the camera. The formula Z = (f × B) / d represents this inverse proportionality, where f is the focal length and B is the baseline, or the distance between the two cameras.

Here are the steps to calculate depth Z:

  1. Check if the disparity d is valid (greater than 0).
  2. If d is valid, use the formula to calculate Z.
  3. Handle the case where d is invalid (less than or equal to 0).
Z=f×BdZ = \frac{f \times B}{d}

This technique is widely used in robotics and autonomous vehicles for 3D reconstruction and obstacle detection.

Example:

Input:
d=10, f=500, B=1
Output:
50.0
Reasoning:
  • Check if disparity is valid: d=10>0d = 10 > 0, so proceed with calculation
  • Apply the depth formula: Z=f×Bd=500×110Z = \frac{f \times B}{d} = \frac{500 \times 1}{10}
  • Compute the result: Z=50010=50.0Z = \frac{500}{10} = 50.0
  • Return the calculated depth value: 50.0

Constraints:

    • Input parameters: disparity d (float), focal length f (float), and baseline B (float)
    • Valid ranges: d > 0, f > 0, B > 0
    • Output format: Return depth Z as a float with a precision of 1 decimal place
    • Special conditions: If d is invalid (less than or equal to 0), the function should handle this case and return an appropriate value or error message
    • Assumptions: The input parameters are valid for a rectified stereo setup and the formula Z = (f × B) / d applies
solution.py

Test Results

0/0
Run code to see test results.
Convert Rectified Disparity to Z-Depth - Easy | PixelBank