Skip to content

Commit 28df7f6

Browse files
committed
avoid NaN and add void label
1 parent a600526 commit 28df7f6

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ The script [convert_pointcloud](convert_pointcloud.py) reads a given rosbag and
2323
* `--id [String]`: Name of the sequence (default `'00'`)
2424
* `-n, --name [String]`: Name of the folder of the point cloud files (default `'velodyne'`)
2525

26-
These indications are also available by using `-h`, it will display all the above informations
26+
These indications are also available by using `-h`, it will display all the above informations. Note that if the name of the sequence already exists,
27+
it will continue to add new files to it without overwriting.
2728

2829
## Automatic labeling using normal orientation threshold
2930

@@ -33,7 +34,8 @@ We have developed this algorithm for labeling point clouds:
3334

3435
1. Estimate the normal on each point considering a number of neighboors to estimate the local surface
3536
2. For each normal, compares its angle with a reference vector (here, the relative vertical)
36-
3. If the angle is above the define threshold, the point is labeled as _obstacle_ (`1`) otherwise, the point is labeled as _free space_ (`0`)
37+
3. If the angle is above the define threshold, the point is labeled as _obstacle_ (`2`) otherwise, the point is labeled as _free space_ (`1`)
38+
4. If the intensity or the coordinates of the point are 0, the point is labeled as _void_ (`0`)
3739

3840
* We have the following options:
3941
* `-d, --dataset [String]`: Path to the dataset

convert_pointcloud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
bag = rosbag.Bag(path_bagfile, "r")
9797
for index, (topic, msg, t) in tqdm(enumerate(bag.read_messages(topic_lidar))):
9898
# Generate the point list
99-
pc_list = list(pc2.read_points(msg))
99+
pc_list = list(pc2.read_points(msg, skip_nans=True))
100100
# Convert the list into an array
101101
pc_array = np.array(pc_list)
102102
x = pc_array[:, 0]

label_normals.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ def label_points(normals, reference=np.array([0, 0, 1])):
121121
else:
122122
normalised_ref = reference
123123

124-
# Determine angle threshold
124+
# Determine angle threshold
125125
cos_angle = np.cos(np.deg2rad(angle_degree))
126126

127127
# Calculate dot product for all normals at once
128128
dot_products = np.dot(normals, normalised_ref)
129129

130130
# Check threshold and create an array of labels based on the dot product values
131-
label_array = np.where(np.abs(dot_products) <= cos_angle, 1, 0)
131+
label_array = np.where(np.abs(dot_products) <= cos_angle, 2, 1)
132132

133133
return label_array
134134

@@ -142,6 +142,13 @@ def write_label(label_array, folder_path, filename):
142142
# Id is set by default to 0
143143
file.write(bin_label)
144144

145+
# If the intensity or the coordinates of a point is 0, label it as void (0)
146+
def label_void(data, labels):
147+
for i in range(data.shape[0]):
148+
if (data[i, 0] == 0 and data[i, 1] == 0 and data[i, 2] == 0) or data[i, 3] == 0:
149+
labels[i] = 0
150+
return labels
151+
145152

146153
# List of all files in the bin folder
147154
bin_folder = os.path.join(id_sequence_folder, folder_data)
@@ -159,5 +166,7 @@ def write_label(label_array, folder_path, filename):
159166
normals = estimate_normals(data_bin, nb_neighboors)
160167
# Generate an array of labels
161168
labels = label_points(normals)
169+
# Check void points
170+
labels = label_void(data_bin, labels)
162171
# Write the resulting .label file
163172
write_label(labels, label_folder, file_name)

0 commit comments

Comments
 (0)