feat(depth): certify evidence points instead of whole voxels (phase 1)

The whole-voxel rule never clears a voxel whose box crosses the image edge.
A person bending over to lift an object leaves high voxels at the top edge
of the image: in the 2026-10-15 lift bag 0 of 54 phantom cells cleared.

- DepthEvidenceStore keeps, per marked voxel, the 6 per-axis extreme points
  plus the most recent ones, keyed by a window-independent cell index.
- DepthVisibilityChecker::classifyPoints: Free only when every evidence
  point projects with a full patch inside the usable image and sees valid
  depth behind it; any surface in front keeps it, invalid depth keeps it.
- Paired marking drops points within depth_marking_border_px of the image
  edge, so every kept point can be re-checked from the pose that saw it.
- Voxels without evidence keep the whole-voxel rule; evidence is erased on
  clear, pruned on rolling shift and every 50 frames.
- New keys depth_evidence_points_enabled (default false),
  depth_evidence_points_per_voxel (8, 6..16), depth_marking_border_px
  (must be > depth_projection_margin_px when enabled); startup log and
  counters (by_evidence, border_dropped_points, evidence_voxels).
- Tests: depth_evidence_store_test; checker and layer tests for the image
  top cut, border drop, rolling shift and a still-visible object.
This commit is contained in:
2026-10-15 13:22:28 +07:00
parent 2ca0bcc1c1
commit 5e38857e48
11 changed files with 608 additions and 15 deletions

View File

@@ -37,6 +37,7 @@
*********************************************************************/
#include <robot_costmap_2d/obstacle_layer.h>
#include <robot_costmap_2d/costmap_math.h>
#include <robot_costmap_2d/depth_evidence_store.h>
#include <robot_sensor_msgs/point_cloud2_iterator.h>
@@ -278,6 +279,26 @@ bool ObstacleLayer::getParams(const std::string& config_file_name, robot::NodeHa
if (frustum_config.observed_volume_clearing &&
(!std::isfinite(frustum_config.voxel_z_resolution_m) || frustum_config.voxel_z_resolution_m <= 0))
throw std::invalid_argument("observed_volume requires finite positive voxel z resolution");
int evidence_points = static_cast<int>(frustum_config.evidence_points_per_voxel);
int marking_border = static_cast<int>(frustum_config.marking_border_px);
read_depth_option("depth_evidence_points_enabled", frustum_config.evidence_points_enabled);
read_depth_option("depth_evidence_points_per_voxel", evidence_points);
read_depth_option("depth_marking_border_px", marking_border);
if (evidence_points < static_cast<int>(DepthEvidenceStore::kExtremeSlots) ||
evidence_points > static_cast<int>(DepthEvidenceStore::kMaxPoints) ||
marking_border < 0 || marking_border > 64)
throw std::invalid_argument("depth_evidence_points_per_voxel must be 6..16 and "
"depth_marking_border_px 0..64");
frustum_config.evidence_points_per_voxel = static_cast<unsigned int>(evidence_points);
frustum_config.marking_border_px = static_cast<unsigned int>(marking_border);
if (frustum_config.evidence_points_enabled && !frustum_config.observed_volume_clearing)
throw std::invalid_argument("depth_evidence_points_enabled requires depth_clearing_mode: observed_volume");
// One pixel more than the patch radius absorbs rounding of the stored float points,
// so every kept evidence point is re-checked with a full patch from its own pose.
if (frustum_config.evidence_points_enabled &&
frustum_config.marking_border_px <= frustum_config.projection_margin_px)
throw std::invalid_argument("depth_marking_border_px must be > depth_projection_margin_px "
"when depth_evidence_points_enabled is true");
frustum_config.pixel_step = static_cast<unsigned int>(std::max(1, frustum_pixel_step));
frustum_config.clear_left_border_px =
@@ -418,9 +439,13 @@ bool ObstacleLayer::getParams(const std::string& config_file_name, robot::NodeHa
paired_depth_sources_.push_back(paired);
marking_buffers_.erase(std::remove(marking_buffers_.begin(), marking_buffers_.end(), m.buffer), marking_buffers_.end());
robot::log_info("depth clearing observed_volume: paired %s + %s, height=[%.3f, %.3f] m; "
"unknown/occluded/outside FOV retained; queue=%u age=%.3f s; one valid free frame\n",
"unknown/occluded/outside FOV retained; queue=%u age=%.3f s; one valid free frame; "
"evidence_points=%s per_voxel=%u marking_border=%u px projection_margin=%u px\n",
paired->cloud_topic.c_str(), paired->depth_topic.c_str(), m.min_height, m.max_height,
paired->config.pair_queue_size, paired->config.observation_max_age_s);
paired->config.pair_queue_size, paired->config.observation_max_age_s,
paired->config.evidence_points_enabled ? "true" : "false",
paired->config.evidence_points_per_voxel, paired->config.marking_border_px,
paired->config.projection_margin_px);
}
}
catch (const YAML::BadFile& e) {