File size: 1,824 Bytes
cdcdc46 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import numpy as np
import open3d as o3d
# Colors:
S3DIS_COLORS = [
[0.5, 0.5, 0.5], # 0: ceiling (grey)
[0.8, 0.4, 0.4], # 1: floor (light red)
[0.4, 0.8, 0.4], # 2: wall (green)
[0.6, 0.6, 0.2], # 3: beam (yellow)
[0.6, 0.2, 0.6], # 4: column (violet)
[0.2, 0.6, 0.6], # 5: window (light blue)
[0.8, 0.6, 0.2], # 6: door (orange)
[0.9, 0.1, 0.1], # 7: chair (strong red)
[0.1, 0.9, 0.1], # 8: table (strong green)
[0.1, 0.1, 0.9], # 9: bookcase (strong blue)
[0.9, 0.9, 0.1], # 10: sofa (yellow)
[0.9, 0.1, 0.9], # 11: board (magenta)
[0.5, 0.5, 0.9], # 12: clutter (blue/grey)
]
def visualize_s3dis_labels(pcd_path, label_path):
# 1. Load the pcd:
pcd = o3d.io.read_point_cloud(pcd_path)
if not pcd.has_points():
print(f"Impossible de charger le fichier PCD : {pcd_path}")
return
# 2. load the labels:
labels_data = np.loadtxt(label_path)
if labels_data.size == 0:
print(f"Fichier de labels vide : {label_path}")
return
semantic_labels = (
labels_data[:, 0].astype(int) if labels_data.ndim > 1 else labels_data.astype(int)
)
if len(pcd.points) != len(semantic_labels):
print("Error : Mismatch between the number of points and labels!")
return
colors = np.zeros((len(semantic_labels), 3))
for i, label in enumerate(semantic_labels):
if 0 <= label < len(S3DIS_COLORS):
colors[i] = S3DIS_COLORS[label]
else:
colors[i] = [0.0, 0.0, 0.0]
pcd.colors = o3d.utility.Vector3dVector(colors)
print(f"Scene: {pcd_path}")
print(f"Number of points: {len(pcd.points)}")
o3d.visualization.draw_geometries([pcd], window_name="Verification S3DIS")
# Example:
visualize_s3dis_labels("test_export\Area_6\office_18\office_18.pcd", "test_export\Area_6\office_18\office_18_labels.txt") |