Skip to content

Add input validation and error handling in depth processing methods#106

Merged
mgonzs13 merged 1 commit intomgonzs13:mainfrom
luispri2001:fix/add-robust-float-validation
Jan 19, 2026
Merged

Add input validation and error handling in depth processing methods#106
mgonzs13 merged 1 commit intomgonzs13:mainfrom
luispri2001:fix/add-robust-float-validation

Conversation

@luispri2001
Copy link
Contributor

Description

This PR adds comprehensive input validation and float handling to prevent crashes when processing depth images with unusual or invalid values.

Changes Made

  • Added validation checks for depth_image inputs (None, empty, non-ndarray)
  • Added checks for NaN, infinity, and zero values in depth processing
  • Validated camera intrinsic parameters (fx, fy) before division operations
  • Converted numpy float types to Python floats for ROS message compatibility
  • Added early returns with safe default values (0.0, 0.0, 0.0) when validation fails

Motivation

The node was crashing when receiving:

  • Depth images with NaN or infinity values
  • Empty depth regions
  • Invalid camera calibration data
  • Edge cases during depth sensor failures

Affected Methods

  • compute_depth_bounds()
  • convert_bb_to_3d()
  • _compute_height_bounds()
  • _compute_width_bounds()
  • _compute_depth_bounds_weighted()
  • convert_keypoints_to_3d()

- Add input validation for depth images and arrays (None, empty, non-ndarray)
- Check for NaN, infinity, and zero values before processing
- Validate camera intrinsic parameters (fx, fy) to prevent division by zero
- Convert numpy float types to Python floats for ROS message compatibility
- Add early returns with safe default values (0.0, 0.0, 0.0) on validation failures
- Validate intermediate calculation results to prevent propagation of invalid values

This prevents crashes when dealing with:
- Invalid depth camera data (NaN, inf values)
- Empty depth regions or arrays
- Invalid camera calibration data
- Division by zero scenarios
- Edge cases during depth sensor failures

Affected methods:
- compute_depth_bounds()
- convert_bb_to_3d()
- _compute_height_bounds()
- _compute_width_bounds()
- _compute_depth_bounds_weighted()
- convert_keypoints_to_3d()

Tested with edge cases including corrupted depth data, NaN/inf values,
zero divisions, and empty arrays. All validations return safe defaults.
@luispri2001 luispri2001 force-pushed the fix/add-robust-float-validation branch from e88bbaf to 547065d Compare January 19, 2026 14:16
@luispri2001 luispri2001 marked this pull request as ready for review January 19, 2026 14:21
@mgonzs13 mgonzs13 merged commit 8d20df2 into mgonzs13:main Jan 19, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants