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:
@@ -30,6 +30,13 @@ robot_sensor_msgs::PointCloud2 cloud(robot::Time stamp, bool point=true) {
|
||||
*x=-.01;*y=.11;*z=.62; }
|
||||
return c;
|
||||
}
|
||||
// One marking point given in the optical frame of the camera.
|
||||
robot_sensor_msgs::PointCloud2 cloudAt(robot::Time stamp, float ox, float oy, float oz) {
|
||||
robot_sensor_msgs::PointCloud2 c=cloud(stamp,true);
|
||||
robot_sensor_msgs::PointCloud2Iterator<float> x(c,"x"), y(c,"y"), z(c,"z");
|
||||
*x=ox;*y=oy;*z=oz;
|
||||
return c;
|
||||
}
|
||||
tf3::TransformStampedMsg pose(robot::Time stamp, double yaw=0) {
|
||||
tf3::TransformStampedMsg p; p.header.frame_id="odom";p.child_frame_id="camera";
|
||||
p.header.stamp=tf3::Time(stamp.sec,stamp.nsec);
|
||||
@@ -73,6 +80,41 @@ TEST(DepthVisibility, RejectsWrongStampModelAndMalformedImage) {
|
||||
d=depth(2);d->depth.data.pop_back();EXPECT_FALSE(c.prepare(d,p,0,3,cfg));
|
||||
d=depth(2);d->depth.is_bigendian=true;EXPECT_FALSE(c.prepare(d,p,0,3,cfg));
|
||||
}
|
||||
// Camera frame == global frame here. A box whose top crosses the image top can never be
|
||||
// certified, while a measured point inside the image can.
|
||||
TEST(DepthVisibility, EvidencePointsCertifyAVoxelCutByTheImageTop) {
|
||||
DepthVisibilityChecker c; DepthFrustumConfig cfg;
|
||||
tf3::TransformStampedMsg p; p.header.frame_id="odom";p.child_frame_id="camera";
|
||||
p.header.stamp=tf3::Time(100,0);p.transform.rotation.w=1;
|
||||
const Eigen::Vector3d lo(-.02,-.80,1),hi(.02,-.75,1.05); // v from about 0 to 5 px
|
||||
const std::vector<Eigen::Vector3d> evidence{Eigen::Vector3d(0,-.77,1)}; // v = 3
|
||||
auto d=depth(2);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.classify(lo,hi).state,DepthVisibility::Unknown);
|
||||
EXPECT_EQ(c.classifyPoints(evidence).state,DepthVisibility::Free);
|
||||
d=depth(.9);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.classifyPoints(evidence).state,DepthVisibility::Surface);
|
||||
d=depth(2);uint16_t zero=0;std::memcpy(&d->depth.data[4*400+101*2],&zero,2); // inside the 3x3 patch
|
||||
ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.classifyPoints(evidence).state,DepthVisibility::Unknown);
|
||||
d=depth(2);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.classifyPoints({Eigen::Vector3d(0,-.80,1)}).state,DepthVisibility::Unknown); // v = 0
|
||||
EXPECT_EQ(c.classifyPoints({Eigen::Vector3d(0,0,-1)}).state,DepthVisibility::Unknown); // behind
|
||||
EXPECT_EQ(c.classifyPoints({}).state,DepthVisibility::Unknown);
|
||||
// Every point must be free: one point in front of a surface keeps the voxel.
|
||||
d=depth(1.5);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_EQ(c.classifyPoints({Eigen::Vector3d(0,0,1),Eigen::Vector3d(0,0,1.6)}).state,DepthVisibility::Surface);
|
||||
}
|
||||
TEST(DepthVisibility, ProjectsInsideHonoursBorderAndUsableStrips) {
|
||||
DepthVisibilityChecker c; DepthFrustumConfig cfg;cfg.clear_left_border_px=10;
|
||||
tf3::TransformStampedMsg p; p.header.frame_id="odom";p.child_frame_id="camera";
|
||||
p.header.stamp=tf3::Time(100,0);p.transform.rotation.w=1;
|
||||
auto d=depth(2);ASSERT_TRUE(c.prepare(d,p,-10,10,cfg));
|
||||
EXPECT_TRUE(c.projectsInside(Eigen::Vector3d(0,-.77,1),2)); // v = 3
|
||||
EXPECT_FALSE(c.projectsInside(Eigen::Vector3d(0,-.79,1),2)); // v = 1
|
||||
EXPECT_TRUE(c.projectsInside(Eigen::Vector3d(-.88,0,1),2)); // u = 12
|
||||
EXPECT_FALSE(c.projectsInside(Eigen::Vector3d(-.89,0,1),2)); // u = 11, inside the left strip + 2
|
||||
EXPECT_FALSE(c.projectsInside(Eigen::Vector3d(0,0,.05),2)); // nearer than valid_min_z
|
||||
}
|
||||
TEST(DepthPairer, MissingHalfExactPairAndDeduplication) {
|
||||
robot::Time::setNow(robot::Time(100,0));DepthFrustumConfig cfg;DepthFramePairer p(cfg,.5);
|
||||
auto c=cloud(robot::Time(100,0));p.addCloud(c);DepthFramePairer::Candidate next;
|
||||
@@ -112,11 +154,22 @@ protected:
|
||||
setenv("PNKX_NAV_CORE_CONFIG_DIR",runtime.c_str(),1);
|
||||
YAML::Node cfg=YAML::Clone(YAML::LoadFile((runtime/"costmap_common_params.yaml").string())["obstacles"]);
|
||||
cfg["observation_sources"]="pc_marking pc_clearing";cfg["footprint_clearing_enabled"]=false;cfg["enabled"]=true;
|
||||
// Explicit, so the result does not depend on what the runtime YAML currently enables.
|
||||
cfg["pc_clearing"]["depth_evidence_points_enabled"]=false;
|
||||
configure(cfg);
|
||||
robot::NodeHandle nh("~");nh.setParam("depth_test",cfg);
|
||||
parent.getCostmap()->resizeMap(80,80,.05,-2,-2);layer.initialize(&parent,"depth_test",&tf);
|
||||
ASSERT_TRUE(layer.isEnabled());
|
||||
}
|
||||
virtual void configure(YAML::Node&) {}
|
||||
robot::Time now() {return robot::Time(100,++tick*10000000);}
|
||||
// Marking point given in the camera optical frame; the image shows `measurement` everywhere.
|
||||
void frameCloud(double measurement,float ox,float oy,float oz) {
|
||||
auto stamp=now();robot::Time::setNow(stamp);ASSERT_TRUE(tf.setTransform(pose(stamp),"test"));
|
||||
layer.dataCallBack(cloudAt(stamp,ox,oy,oz),"/camera/depth/points_proc");
|
||||
robot_sensor_msgs::DepthCameraData::ConstPtr d=depth(measurement,stamp);
|
||||
layer.dataCallBack(d,"/camera/depth/data");update();
|
||||
}
|
||||
void update() {double a=1e9,b=1e9,c=-1e9,d=-1e9;layer.updateBounds(0,0,0,&a,&b,&c,&d);}
|
||||
void frame(double measurement,bool point=false,double yaw=0,bool hasTf=true,bool hasCloud=true,bool hasDepth=true) {
|
||||
auto stamp=now();robot::Time::setNow(stamp);
|
||||
@@ -205,6 +258,45 @@ TEST_F(DepthLayerTest, AStillOccludedVoxelKeepsItsColumnLethal) {
|
||||
d=partial;layer.dataCallBack(d,"/camera/depth/data");update();EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(2);EXPECT_EQ(at(),FREE_SPACE);
|
||||
}
|
||||
// A point seen 7 px below the image top marks voxel z [0.625, 0.6875] m, whose top
|
||||
// corner projects above the image. Whole-voxel rule: never certified (the person/hand
|
||||
// phantom of the 2026-10-15 lift bag).
|
||||
TEST_F(DepthLayerTest, WholeVoxelRuleKeepsAVoxelCutByTheImageTop) {
|
||||
frameCloud(.62,-.01f,-.45f,.62f);ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(2);EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
}
|
||||
class DepthEvidenceLayerTest:public DepthLayerTest {
|
||||
protected:
|
||||
void configure(YAML::Node& cfg) override {
|
||||
cfg["pc_clearing"]["depth_evidence_points_enabled"]=true;
|
||||
cfg["pc_clearing"]["depth_marking_border_px"]=2;
|
||||
}
|
||||
};
|
||||
TEST_F(DepthEvidenceLayerTest, EvidencePointsClearAVoxelCutByTheImageTop) {
|
||||
frameCloud(.62,-.01f,-.45f,.62f);ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(2);EXPECT_EQ(at(),FREE_SPACE);
|
||||
}
|
||||
TEST_F(DepthEvidenceLayerTest, RetainsOutsideInvalidOccludedAndClearsOnFirstValidFrame) {
|
||||
frame(.62,true);ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(2,false,1.57);EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(0);EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(.4);EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(2);EXPECT_EQ(at(),FREE_SPACE);
|
||||
}
|
||||
TEST_F(DepthEvidenceLayerTest, MarkingDropsPointsInTheImageBorder) {
|
||||
frameCloud(.62,-.01f,-.49f,.62f);EXPECT_NE(at(),LETHAL_OBSTACLE); // v = 0.97 px
|
||||
frameCloud(.62,-.01f,-.45f,.62f);EXPECT_EQ(at(),LETHAL_OBSTACLE); // v = 7.4 px
|
||||
}
|
||||
TEST_F(DepthEvidenceLayerTest, EvidenceSurvivesRollingShift) {
|
||||
frameCloud(.62,-.01f,-.45f,.62f);ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
layer.updateOrigin(-1.5,-2);EXPECT_EQ(at(),LETHAL_OBSTACLE);
|
||||
frame(2);EXPECT_EQ(at(),FREE_SPACE);
|
||||
}
|
||||
TEST_F(DepthEvidenceLayerTest, AStillVisibleObjectIsNeverCertifiedFree) {
|
||||
frameCloud(.62,-.01f,-.45f,.62f);ASSERT_EQ(at(),LETHAL_OBSTACLE);
|
||||
for(int i=0;i<3;++i) {frameCloud(.62,-.01f,-.45f,.62f);EXPECT_EQ(at(),LETHAL_OBSTACLE);}
|
||||
frame(.62);EXPECT_EQ(at(),LETHAL_OBSTACLE); // no marking this frame, surface still seen
|
||||
}
|
||||
}
|
||||
int main(int argc,char**argv) {robot::Time::init();testing::InitGoogleTest(&argc,argv);return RUN_ALL_TESTS();}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user