Untitled
unknown
plain_text
a year ago
1.2 kB
8
Indexable
import numpy as np
def relative_to_metric_depth(relative_depth, focal_length, baseline):
"""
Convert relative depth to metric depth.
Args:
relative_depth (numpy.ndarray): Relative depth map
focal_length (float): Focal length of the camera in pixels
baseline (float): Baseline distance between stereo cameras in meters
Returns:
numpy.ndarray: Metric depth map
"""
# Assuming relative_depth is normalized between 0 and 1
# Convert to disparity (inverse of depth)
disparity = 1 / (relative_depth + 1e-6) # Add small epsilon to avoid division by zero
# Convert disparity to metric depth
metric_depth = (focal_length * baseline) / disparity
return metric_depth
# Example usage
relative_depth_map = np.random.rand(480, 640) # Example relative depth map
focal_length = 500 # Example focal length in pixels
baseline = 0.1 # Example baseline in meters
metric_depth_map = relative_to_metric_depth(relative_depth_map, focal_length, baseline)
print("Shape of metric depth map:", metric_depth_map.shape)
print("Min depth:", np.min(metric_depth_map), "meters")
print("Max depth:", np.max(metric_depth_map), "meters")Editor is loading...
Leave a Comment