Open HuaiyuanXu opened 1 year ago
Can you please elaborate the issue more ?
Many thanks for your reply. Could you provide code in python language to generate global descriptors? In other words, could you give the python language code to replace the c++ language code in the gen_desc folder?
Could you provide a python implementation for preprocessing?
Sorry for not replying in time as I was preparing for ICRA2023 some time ago. I will implement and upload the relevant code as soon as possible.
Could you provide a python implementation for preprocessing?
I'll complete the Python implementation for preprocessing at my earliest convenience.
Perhaps this code will work.
import numpy as np
import yaml
class PreProcessor:
def __init__(self, cfg_file):
with open(cfg_file, 'r') as file:
cfg = yaml.safe_load(file)
self.learning_map = None
if cfg['remap']:
cfg_lm = cfg['learning_map']
max_id = np.max(list(cfg_lm.keys()))
learning_map_list = [cfg_lm[i] if i in cfg_lm else -1 for i in range(max_id + 1)]
self.learning_map = np.array(learning_map_list, dtype='int')
self.valid_labels = np.array([1] + list(range(9, 20)), dtype='int')
self.label_map = np.full(20, -1, dtype='int')
self.label_map[9:] = np.arange(1, 12)
self.label_map[1] = 0
def run(self, pcd_file, label_file):
# load data
points = self.load_pcd(pcd_file)
labels = self.load_label(label_file)
# remove unused label
label_mask = np.isin(labels, self.valid_labels)
points = points[label_mask]
labels = labels[label_mask]
# Remove distant data
dis = np.linalg.norm(points[:, :2], axis=1)
dis_mask = (dis <= 50)
points = points[dis_mask]
labels = labels[dis_mask]
dis = dis[dis_mask]
angles = np.arctan2(points[:, 1], points[:, 0]) + np.pi
angles = (angles * 180.) / np.pi
angles = np.floor(angles).astype('int')
#Ensure the angle is valid
angle_mask = ((angles >=0) & (angles <= 359))
points = points[angle_mask]
labels = labels[angle_mask]
dis = dis[angle_mask]
angles = angles[angle_mask]
# convert label id to 0-11
labels = self.label_map[labels]
order = np.argsort(-dis)
dis = dis[order]
points = points[order]
labels = labels[order]
angles = angles[order]
# desc for semantics other than road
min_desc = np.zeros([12, 360], dtype='float')
min_desc[labels, angles] = dis
order = np.argsort(dis)
dis = dis[order]
points = points[order]
labels = labels[order]
angles = angles[order]
# desc for road
max_desc = np.zeros([12, 360], dtype='float')
max_desc[labels, angles] = dis
min_desc[1] = max_desc[1] # road
return min_desc
def load_pcd(self, file):
points = np.fromfile(file, dtype='float32').reshape(-1, 4)[:, 0:3]
return points
def load_label(self, file):
labels = np.fromfile(file, dtype='uint32')
if self.learning_map is not None:
labels = labels & np.uint32(0x0000FFFF)
labels = self.learning_map[labels]
return labels
if __name__ == '__main__':
processor = PreProcessor("gen_desc/conf/sem_config.yaml")
desc = processor.run('/home/l/workspace/SSC/data/000720.bin', '/home/l/workspace/SSC/data/000720.label')
from matplotlib import pyplot as plt
plt.imshow(desc)
plt.show()
Could you provide a python implementation for preprocessing?