Skip to content

Commit d27f767

Browse files
committed
Update cone_detection.py
1 parent 1e41933 commit d27f767

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

GEMstack/onboard/perception/cone_detection.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121

2222
# ----- Helper Functions -----
2323

24+
def cylindrical_roi(points, center, radius, height):
25+
horizontal_dist = np.linalg.norm(points[:, :2] - center[:2], axis=1)
26+
vertical_diff = np.abs(points[:, 2] - center[2])
27+
mask = (horizontal_dist <= radius) & (vertical_diff <= height / 2)
28+
return points[mask]
29+
30+
2431
def undistort_image(image, K, D):
2532
h, w = image.shape[:2]
2633
newK, _ = cv2.getOptimalNewCameraMatrix(K, D, (w, h), 1, (w, h))
@@ -287,6 +294,8 @@ def __init__(self, vehicle_interface: GEMInterface):
287294
self.bridge = CvBridge()
288295
self.start_pose_abs = None
289296
self.camera_front = True
297+
self.visualize_2d = True
298+
self.use_cyl_roi = False
290299

291300
def rate(self) -> float:
292301
return 4.0
@@ -466,11 +475,19 @@ def update(self, vehicle: VehicleState) -> Dict[str, AgentState]:
466475
points_3d = roi_pts[:, 2:5]
467476
points_3d = remove_ground_by_min_range(points_3d, z_range=0.005)
468477
points_3d = filter_points_within_threshold(points_3d, 15)
469-
points_3d = filter_depth_points(points_3d, max_human_depth=0.3)
470-
471-
# Cluster the points and remove ground.
472-
refined_cluster = refine_cluster(points_3d, np.mean(points_3d, axis=0), eps=0.5, min_samples=10)
473-
refined_cluster = remove_ground_by_min_range(refined_cluster, z_range=0.03)
478+
points_3d = filter_depth_points(points_3d, max_depth_diff=0.3)
479+
480+
# Modification: optionally use cylindrical ROI adjustment.
481+
if self.use_cyl_roi:
482+
global_filtered = filter_points_within_threshold(lidar_down, 20)
483+
# Build a cylindrical ROI based on the global filtered LiDAR points
484+
# and the mean of the extracted points as the center.
485+
roi_cyl = cylindrical_roi(global_filtered, np.mean(points_3d, axis=0), radius=0.3, height=1.2)
486+
refined_cluster = remove_ground_by_min_range(roi_cyl, z_range=0.01)
487+
refined_cluster = filter_depth_points(refined_cluster, max_depth_diff=0.2)
488+
else:
489+
# Use the original method.
490+
refined_cluster = remove_ground_by_min_range(points_3d, z_range=0.05)
474491
end1 = time.time()
475492
print('refine cluster: ', end1 - start)
476493
if refined_cluster.shape[0] < 3:

0 commit comments

Comments
 (0)