You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have tried several ways to viusalize the semantic segmentation annotation outputs in pcd format, but the annotations are not being shown. Any help is appreciated.
I am using the following code. I see the original pcd ,but the annotation are not shown. Only reading the PCD alone also didn't work.
importopen3daso3dimportnumpyasnp# Read the original point cloud with coordinatespcd=o3d.io.read_point_cloud("20220929_083807_525890.pcd")
# Read segmentation datawithopen('20220929_083807_549617_lidar_point_cloud_0_segmentation.pcd', 'rb') asf:
# Skip headerfor_inrange(11):
f.readline()
seg_data=np.frombuffer(f.read(), dtype=np.uint8)
# From the histogram, we can see major semantic classessemantic_colors= {
1: [1, 0, 0], # Red (largest peak in histogram)128: [0, 1, 0], # Green (second major peak)156: [0, 0, 1], # Blue40: [1, 1, 0], # Yellow122: [1, 0, 1], # Magenta8: [0, 1, 1], # Cyan
}
# Create colors arraycolors=np.zeros((len(seg_data), 3))
print(seg_data)
# Assign colors based on semantic classesforclass_id, colorinsemantic_colors.items():
mask= (seg_data==class_id)
colors[mask] =color# For unassigned classes, use grayunassigned_mask=~np.any([seg_data==keyforkeyinsemantic_colors.keys()], axis=0)
colors[unassigned_mask] = [0.5, 0.5, 0.5] # Gray for unassigned points# Assign colors to point cloudpcd.colors=o3d.utility.Vector3dVector(colors)
# Visualizationvis=o3d.visualization.Visualizer()
vis.create_window()
vis.add_geometry(pcd)
# Improve visualization settingsopt=vis.get_render_option()
opt.background_color=np.asarray([0, 0, 0]) # Black backgroundopt.point_size=2.0# Add coordinate framecoordinate_frame=o3d.geometry.TriangleMesh.create_coordinate_frame(
size=1.0, origin=[0, 0, 0])
vis.add_geometry(coordinate_frame)
vis.run()
vis.destroy_window()
for reading the annotation PCD file alone:
importopen3daso3dimportnumpyasnp# Read the PCD filepcd=o3d.io.read_point_cloud("20220929_083807_549617_lidar_point_cloud_0_segmentation.pcd")
# Assuming semantic labels are stored in the 'labels' attributelabels=np.asarray(pcd.labels)
# Create a color map for different semantic classescolor_map= {
0: [1, 0, 0], # Red for class 01: [0, 1, 0], # Green for class 12: [0, 0, 1], # Blue for class 2# Add more colors for additional classes
}
# Assign colors based on semantic labelscolors=np.array([color_map[label] forlabelinlabels])
pcd.colors=o3d.utility.Vector3dVector(colors)
# Visualize the semantically colored point cloudo3d.visualization.draw_geometries([pcd])
using the output with x,y,z,seg also does not work and the following code, colorizes the objects instance-wise and not semantic-wise
importopen3daso3dimportnumpyasnpimportstructdefread_binary_pcd(filename):
withopen(filename, 'rb') asf:
# Skip headerfor_inrange(11):
f.readline()
binary_data=f.read()
fmt='fffi'size=struct.calcsize(fmt)
num_points=len(binary_data) //sizepoints= []
foriinrange(num_points):
offset=i*sizept=struct.unpack(fmt, binary_data[offset:offset+size])
points.append(pt)
points=np.array(points)
returnpoints[:, :3], points[:, 3].astype(np.int32)
# Define semantic class colors based on the plateaus in the visualizationsemantic_colors= {
0: [0.7, 0.7, 0.7], # background10: [1.0, 0.0, 0.0], # road40: [0.0, 1.0, 0.0], # vegetation80: [0.0, 0.0, 1.0], # building120: [1.0, 1.0, 0.0], # car130: [1.0, 0.0, 1.0], # pedestrian140: [0.0, 1.0, 1.0], # pole150: [0.8, 0.4, 0.0], # traffic sign160: [0.5, 0.5, 0.5] # other
}
# Read point cloudxyz, seg_labels=read_binary_pcd("20220929_084039_549664_lidar_point_cloud_0_segmentation.pcd")
# Create Open3D point cloudpcd=o3d.geometry.PointCloud()
pcd.points=o3d.utility.Vector3dVector(xyz)
# Create colors arraycolors=np.zeros((len(seg_labels), 3))
# Assign colors based on semantic classes# Round the segmentation labels to the nearest semantic classforlabelinnp.unique(seg_labels):
# Find the closest semantic classclosest_class=min(semantic_colors.keys(), key=lambdax: abs(x-label))
mask= (seg_labels==label)
colors[mask] =semantic_colors[closest_class]
# Assign colors to point cloudpcd.colors=o3d.utility.Vector3dVector(colors)
# Visualizationvis=o3d.visualization.Visualizer()
vis.create_window()
vis.add_geometry(pcd)
# Improve visualization settingsopt=vis.get_render_option()
opt.background_color=np.asarray([0, 0, 0])
opt.point_size=2.0vis.run()
vis.destroy_window()
The text was updated successfully, but these errors were encountered:
Hi,
I have tried several ways to viusalize the semantic segmentation annotation outputs in pcd format, but the annotations are not being shown. Any help is appreciated.
I am using the following code. I see the original pcd ,but the annotation are not shown. Only reading the PCD alone also didn't work.
for reading the annotation PCD file alone:
using the output with x,y,z,seg also does not work and the following code, colorizes the objects instance-wise and not semantic-wise
The text was updated successfully, but these errors were encountered: