Skip to content

Commit dfa7e7a

Browse files
committed
add ground filter
1 parent 7b0f604 commit dfa7e7a

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

GEMstack/onboard/perception/cone_detection_parking.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def extract_roi_box(lidar_pc, center, half_extents):
8888
# print('Convert to numpy: ', end - start)
8989
# return pts[mask]
9090

91-
def pc2_to_numpy(pc2_msg, want_rgb=False):
91+
def pc2_to_numpy(pc2_msg, want_rgb=False, filter=True):
9292
"""
9393
Convert a ROS PointCloud2 message into a numpy array quickly using ros_numpy.
9494
This function extracts the x, y, z coordinates from the point cloud.
@@ -99,11 +99,12 @@ def pc2_to_numpy(pc2_msg, want_rgb=False):
9999
pts = np.stack((np.array(pc['x']).ravel(),
100100
np.array(pc['y']).ravel(),
101101
np.array(pc['z']).ravel()), axis=1)
102+
if not filter:
103+
return pts
102104
# Apply filtering (for example, x > 0 and z < 2.5)
103105
mask = (pts[:, 0] > 0) & (pts[:, 2] < -1.5) & (pts[:, 2] > -2.7)
104106
return pts[mask]
105-
106-
107+
107108

108109
def backproject_pixel(u, v, K):
109110
"""
@@ -252,6 +253,11 @@ def transform_points_l2c(lidar_points, T_l2c):
252253
pts_cam = (T_l2c @ pts_hom.T).T # (N,4)
253254
return pts_cam[:, :3]
254255

256+
def filter_ground_points(lidar_points, ground_threshold = 0):
257+
""" Filter points given an elevation of ground threshold """
258+
filtered_array = lidar_points[lidar_points[:, 2] > ground_threshold]
259+
return filtered_array
260+
255261
# ----- New: Vectorized projection function -----
256262
def project_points(pts_cam, K, original_lidar_points):
257263
"""
@@ -308,6 +314,8 @@ def state_outputs(self) -> list:
308314
return ['agents']
309315

310316
def initialize(self):
317+
# Init Variables
318+
self.ground_threshold = -0.15
311319
# Real Subscribers
312320
# self.rgb_sub = Subscriber('/camera_fl/arena_camera_node/image_raw', Image)
313321
# self.lidar_sub = Subscriber('/ouster/points', PointCloud2)
@@ -358,7 +366,8 @@ def viz_object_states(self, cv_image, boxes):
358366
cone_3d_dims.append(agent.dimensions)
359367

360368
# Transform top lidar pointclouds to vehicle frame for visualization
361-
latest_lidar_vehicle = transform_lidar_points(self.latest_lidar, self.T_l2v)
369+
latest_lidar_vehicle = transform_lidar_points(self.latest_lidar_unfiltered, self.T_l2v)
370+
latest_lidar_vehicle = filter_ground_points(latest_lidar_vehicle, self.ground_threshold)
362371
ros_lidar_top_vehicle_pc2 = create_point_cloud(latest_lidar_vehicle, (255, 0, 0), "vehicle")
363372
self.pub_lidar_top_vehicle_pc2.publish(ros_lidar_top_vehicle_pc2)
364373

@@ -397,7 +406,8 @@ def synchronized_callback(self, image_msg, lidar_msg):
397406
rospy.logerr("Failed to convert image: {}".format(e))
398407
self.latest_image = None
399408
step2 = time.time()
400-
self.latest_lidar = pc2_to_numpy(lidar_msg, want_rgb=False)
409+
self.latest_lidar = pc2_to_numpy(lidar_msg, want_rgb=False, filter=True)
410+
self.latest_lidar_unfiltered = pc2_to_numpy(lidar_msg, want_rgb=False, filter=False)
401411
step3 = time.time()
402412
print('image callback: ', step2-step1, 'lidar callback ', step3- step2)
403413

0 commit comments

Comments
 (0)