From 63abace071d16c9c3428498e8caff3b01be9d28f Mon Sep 17 00:00:00 2001 From: Devon Morris Date: Mon, 27 Feb 2023 11:03:49 -0500 Subject: [PATCH] Fix segmentation fault on too few detections Downstream of the circle detection, refinement and optimization assumed that 4 circles are successfully extracted from the pointcloud. We fix this by ensuring that there are exactly 4 detections and returning early if that condition is not met. --- lidar_detector/src/lib/keypoint_detection.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lidar_detector/src/lib/keypoint_detection.cpp b/lidar_detector/src/lib/keypoint_detection.cpp index fa79dd1..6aeedf5 100644 --- a/lidar_detector/src/lib/keypoint_detection.cpp +++ b/lidar_detector/src/lib/keypoint_detection.cpp @@ -395,6 +395,12 @@ pcl::PointCloud keypointDetection(pcl::PointCloud pattern = processCircles(circles_cloud, cloud_without_ground_floor, config.circle_detection); if (config.visualize) { visualize(cloud_calibration_board, pattern, edges_cloud); } + if (pattern.size() < 4) { + std::cerr << "Failed to find all circles, found only " << pattern.size() << std::endl; + pattern.clear(); + return pattern; + } + // Refine circle centers using calibration board geometry if (config.refinement.refine) { // Refinement using kabsch