Datasets:

License:
sephyli's picture
Upload folder using huggingface_hub
c1eaa40
raw
history blame
2.93 kB
import cv2
import numpy as np
from navsim.common.extraction.helpers import transformation
def draw_pcs_on_images(pc, cam_infos, eps=1e-3):
for cam_type, cam_info in cam_infos.items():
cur_img_path = cam_info["data_path"]
cur_img = cv2.imread(cur_img_path)
cur_img_h, cur_img_w = cur_img.shape[:2]
cur_pc_cam, cur_pc_in_fov = transformation.transform_pcs_to_images(
pc,
cam_info["sensor2lidar_rotation"],
cam_info["sensor2lidar_translation"],
cam_info["cam_intrinsic"],
img_shape=(cur_img_h, cur_img_w),
eps=eps,
)
cur_pc_cam = cur_pc_cam[cur_pc_in_fov]
for x, y in cur_pc_cam:
cv2.circle(cur_img, (int(x), int(y)), 3, (255, 0, 0), 3)
cv2.imwrite(f"dbg/{cam_type}.png", cur_img)
return None
def draw_pcs(points, labels, color_map):
"""Draw point cloud from BEV
Args:
points: A ndarray with shape as [-1, 3]
labels: the label of each point with shape [-1]
color_map: color of each label.
"""
import matplotlib.pyplot as plt
_, ax = plt.subplots(1, 1, figsize=(9, 9))
axes_limit = 40
# points: LiDAR points with shape [-1, 3]
viz_points = points
dists = np.sqrt(np.sum(viz_points[:, :2] ** 2, axis=1))
colors = np.minimum(1, dists / axes_limit / np.sqrt(2))
# prepare color_map
points_color = color_map[labels] / 255.0 # -1, 3
point_scale = 0.2
scatter = ax.scatter(viz_points[:, 0], viz_points[:, 1], c=points_color, s=point_scale)
ax.plot(0, 0, "x", color="red")
ax.set_xlim(-axes_limit, axes_limit)
ax.set_ylim(-axes_limit, axes_limit)
ax.axis("off")
ax.set_aspect("equal")
plt.savefig("dbg/dbg.png", bbox_inches="tight", pad_inches=0, dpi=200)
def draw_sweep_pcs(info, sweeps):
cur_pc_file = info["lidar_path"]
cur_pc = transformation._load_points(cur_pc_file)
viz_pcs = [cur_pc[:, :3]]
viz_labels = [np.ones_like(cur_pc)[:, 0] * 0.0]
for idx, sweep in enumerate(sweeps):
sweep_pc_file = sweep["data_path"]
sweep_pc = transformation._load_points(sweep_pc_file)
sweep_pc = transformation.transform_sweep_pc_to_lidar_top(
sweep_pc, sweep["sensor2lidar_rotation"], sweep["sensor2lidar_translation"]
)
viz_pcs.append(sweep_pc)
viz_labels.append(np.ones_like(sweep_pc)[:, 0] * (idx + 1))
viz_pcs = np.concatenate(viz_pcs, 0)
viz_labels = np.concatenate(viz_labels, 0).astype(np.int)
color_map = np.array(
[
[245, 150, 100],
[245, 230, 100],
[250, 80, 100],
[150, 60, 30],
[255, 0, 0],
[180, 30, 80],
[255, 0, 0],
[30, 30, 255],
[200, 40, 255],
[90, 30, 150],
]
)
draw_pcs(viz_pcs, viz_labels, color_map)
return None