Skip to content

Commit 9008a9a

Browse files
committed
add ground and max dist filter
1 parent 5aa571b commit 9008a9a

3 files changed

Lines changed: 30 additions & 6 deletions

File tree

GEMstack/onboard/perception/fusion.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def __init__(self):
1818
self.visualization = True
1919
self.confidence = 0.7
2020
self.classes_to_detect = 0
21+
self.ground_threshold = 1.6
22+
self.max_dist_percent = 0.7
2123

2224
# Load calibration data
2325
self.R = load_extrinsics(os.getcwd() + '/GEMstack/onboard/perception/calibration/extrinsics/R.npy')
@@ -84,18 +86,28 @@ def fusion_callback(self, rgb_image_msg: Image, lidar_pc2_msg: PointCloud2):
8486
(pts[:, 1] < bottom_bound)
8587
]
8688

87-
extracted_2d_pts = list(np.array(extracted_pts)[:, :2].astype(int))
89+
#if no points extracted for this bbox, skip
90+
if len(extracted_pts) < 1:
91+
continue
92+
93+
extracted_pts = filter_ground_points(extracted_pts, self.ground_threshold)
94+
extracted_pts = filter_far_points(extracted_pts)
95+
96+
extracted_2d_pts = list(extracted_pts[:, :2].astype(int))
8897
flattened_pedestrians_2d_pts = flattened_pedestrians_2d_pts + extracted_2d_pts
89-
90-
extracted_3d_pts = list(np.array(extracted_pts)[:, -3:])
98+
99+
extracted_3d_pts = list(extracted_pts[:, -3:])
91100
pedestrians_3d_pts.append(extracted_3d_pts)
92101
flattened_pedestrians_3d_pts = flattened_pedestrians_3d_pts + extracted_3d_pts
93102

94103
# Used for visualization
95104
if(self.visualization):
96105
cv_image = vis_2d_bbox(cv_image, xywh, box)
97106

98-
if len(pedestrians_3d_pts) > 0:
107+
if len(flattened_pedestrians_3d_pts) > 0:
108+
# print(f"x_dim pedestrians_3d_pts: {np.max(np.array(flattened_pedestrians_3d_pts)[:, 0]), np.min(np.array(flattened_pedestrians_3d_pts)[:, 0])}")
109+
# print(f"y_dim pedestrians_3d_pts: {np.max(np.array(flattened_pedestrians_3d_pts)[:, 1]), np.min(np.array(flattened_pedestrians_3d_pts)[:, 1])}")
110+
# print(f"z_dim pedestrians_3d_pts: {np.max(np.array(flattened_pedestrians_3d_pts)[:, 2]), np.min(np.array(flattened_pedestrians_3d_pts)[:, 2])}")
99111
# Draw projected 2D LiDAR points on the image.
100112
for pt in flattened_pedestrians_2d_pts:
101113
cv2.circle(cv_image, pt, 2, (0, 0, 255), -1)

GEMstack/onboard/perception/fusion_utils.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from sensor_msgs.msg import PointCloud2, PointField
2+
from scipy.stats import zscore
23
import numpy as np
34
import sensor_msgs.point_cloud2 as pc2
45
import open3d as o3d
@@ -23,12 +24,23 @@ def downsample_points(lidar_points):
2324
# Apply voxel grid downsampling
2425
voxel_size = 0.1 # Adjust for desired resolution
2526
downsampled_pcd = pcd.voxel_down_sample(voxel_size=voxel_size)
26-
27+
2728
# Convert back to numpy array
2829
transformed_points = np.asarray(downsampled_pcd.points)
2930
return transformed_points
3031

3132

33+
def filter_ground_points(lidar_points, ground_threshold = 0):
34+
filtered_array = lidar_points[lidar_points[:, 3] < ground_threshold]
35+
return filtered_array
36+
37+
38+
def filter_far_points(lidar_points, max_dist_percent=0.85):
39+
max_dist = np.max(lidar_points[:, 4])
40+
filtered_array = lidar_points[lidar_points[:, 4] < max_dist_percent * max_dist]
41+
return filtered_array
42+
43+
3244
# Credits: The following lines of codes (from 33 to 92) are adapted from the Calibration Team B
3345
def load_extrinsics(extrinsics_file):
3446
"""

GEMstack/onboard/perception/transform.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def publish_tf():
99

1010
while not rospy.is_shutdown():
1111
br.sendTransform(
12-
(0, 1.5, 7), # (x, y, z) translation
12+
(0, 1.6, 7), # (x, y, z) translation
1313
tf.transformations.quaternion_from_euler(0.5* np.pi, 0, 0), # (roll, pitch, yaw)
1414
rospy.Time.now(),
1515
"os_sensor", # Child frame (sensor)

0 commit comments

Comments
 (0)