Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ depth_anything_3:
inference_height: 518 # Height for inference
inference_width: 518 # Width for inference
input_encoding: "bgr8" # Expected input encoding (bgr8/rgb8)
keep_image_size: false # Resize output to match input resolution

# Output configuration
normalize_depth: true # Normalize depth to [0, 1] range
Expand Down
16 changes: 15 additions & 1 deletion depth_anything_3_ros2/depth_anything_3_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
from sensor_msgs.msg import Image, CameraInfo
from std_msgs.msg import Header
from cv_bridge import CvBridge, CvBridgeError
import cv2

from .da3_inference import DA3InferenceWrapper, SharedMemoryInference, SharedMemoryInferenceFast
from .utils import normalize_depth, colorize_depth, PerformanceMetrics
from .utils import normalize_depth, colorize_depth, PerformanceMetrics, resize_image


class DepthAnything3Node(Node):
Expand Down Expand Up @@ -137,6 +138,7 @@ def _declare_parameters(self) -> None:
self.declare_parameter("inference_height", 518)
self.declare_parameter("inference_width", 518)
self.declare_parameter("input_encoding", "bgr8")
self.declare_parameter("keep_image_size", False)

# Output configuration
self.declare_parameter("normalize_depth", True)
Expand Down Expand Up @@ -166,6 +168,7 @@ def _load_parameters(self) -> None:
self.inference_height = self.get_parameter("inference_height").value
self.inference_width = self.get_parameter("inference_width").value
self.input_encoding = self.get_parameter("input_encoding").value
self.keep_image_size = self.get_parameter("keep_image_size").value

# Output configuration
self.normalize_depth_output = self.get_parameter("normalize_depth").value
Expand Down Expand Up @@ -233,6 +236,17 @@ def image_callback(self, msg: Image) -> None:
# Extract depth map
depth_map = result["depth"]

# Resize if requested
if self.keep_image_size:
original_size = (cv_image.shape[0], cv_image.shape[1])
depth_map = resize_image(
depth_map, target_size=original_size, keep_aspect_ratio=False, interpolation=cv2.INTER_LINEAR
)
if "confidence" in result:
result["confidence"] = resize_image(
result["confidence"], target_size=original_size, keep_aspect_ratio=False, interpolation=cv2.INTER_NEAREST
)

# Normalize if requested
if self.normalize_depth_output:
depth_map = normalize_depth(depth_map)
Expand Down
6 changes: 6 additions & 0 deletions launch/depth_anything_3.launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ def generate_launch_description():
default_value='bgr8',
description='Expected input image encoding (bgr8 or rgb8)'
),
DeclareLaunchArgument(
'keep_image_size',
default_value='false',
description='Resize output depth map to match input image resolution'
),

# Output configuration
DeclareLaunchArgument(
Expand Down Expand Up @@ -136,6 +141,7 @@ def generate_launch_description():
'inference_height': LaunchConfiguration('inference_height'),
'inference_width': LaunchConfiguration('inference_width'),
'input_encoding': LaunchConfiguration('input_encoding'),
'keep_image_size': LaunchConfiguration('keep_image_size'),
'normalize_depth': LaunchConfiguration('normalize_depth'),
'publish_colored': LaunchConfiguration('publish_colored'),
'publish_confidence': LaunchConfiguration('publish_confidence'),
Expand Down
Loading