|
21 | 21 |
|
22 | 22 | # ----- Helper Functions ----- |
23 | 23 |
|
| 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 | + |
24 | 31 | def undistort_image(image, K, D): |
25 | 32 | h, w = image.shape[:2] |
26 | 33 | newK, _ = cv2.getOptimalNewCameraMatrix(K, D, (w, h), 1, (w, h)) |
@@ -287,6 +294,8 @@ def __init__(self, vehicle_interface: GEMInterface): |
287 | 294 | self.bridge = CvBridge() |
288 | 295 | self.start_pose_abs = None |
289 | 296 | self.camera_front = True |
| 297 | + self.visualize_2d = True |
| 298 | + self.use_cyl_roi = False |
290 | 299 |
|
291 | 300 | def rate(self) -> float: |
292 | 301 | return 4.0 |
@@ -466,11 +475,19 @@ def update(self, vehicle: VehicleState) -> Dict[str, AgentState]: |
466 | 475 | points_3d = roi_pts[:, 2:5] |
467 | 476 | points_3d = remove_ground_by_min_range(points_3d, z_range=0.005) |
468 | 477 | 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) |
474 | 491 | end1 = time.time() |
475 | 492 | print('refine cluster: ', end1 - start) |
476 | 493 | if refined_cluster.shape[0] < 3: |
|
0 commit comments