Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

demo code for visualizing the prediction on 3D object detection and outdoor segmentation tasks #6

Open
amiltonwong opened this issue Dec 28, 2022 · 2 comments

Comments

@amiltonwong
Copy link

Hi, authors,

Could you provide the demo code for visualizing the prediction on 3D object detection and outdoor segmentation tasks?

Thanks~

@Szy-Young
Copy link
Contributor

Hi @amiltonwong

You can use the following code for a quick visualization with Open3D:

# pc: (N, 3) numpy array
# segm: (N,) numpy array

import open3d as o3d
from utils.visual_util import build_pointcloud

pcds = [build_pointcloud(pc, segm)]
o3d.visualization.draw_geometries(pcds)

For the visualization effects in our paper and video demo, you can first use the following code to convert point clouds into meshes of spheres:

# pc: (N, 3) numpy array
# segm: (N,) numpy array

import open3d as o3d

def pc_segm_to_sphere(pc, segm=None, radius = 0.01, resolution=10, with_background=False, default_color=COLORGRAY2):
    """
    Visualize point cloud as mesh balls. The color denotes hard segmentation.
    :param pc: (N, 3)
    :param segm: (N,)
    """
    assert pc.shape[1] == 3 and len(pc.shape) == 2, f"Point cloud is of size {pc.shape} and cannot be displayed!"
    n_point = pc.shape[0]
    if with_background:
        colors = np.concatenate((COLOR20[-1:], COLOR20[:-1]), axis=0)
    else:
        colors = COLOR20

    meshes = []
    for pid in range(n_point):
        mesh = o3d.geometry.TriangleMesh.create_sphere(radius=radius, resolution=resolution)
        if segm is not None:
            mesh.paint_uniform_color(colors[segm[pid] % colors.shape[0]] / 255.)
        else:
            mesh.paint_uniform_color(default_color / 255.)
        mesh.translate(pc[pid])
        meshes.append(mesh)

    # Merge
    mesh = meshes[0]
    for i in range(1, len(meshes)):
        mesh += meshes[i]
    return mesh

mesh = pc_segm_to_sphere(pc, segm)
save_file = ...
o3d.io.write_triangle_mesh(save_file, mesh)

Then you can render the mesh models with softwares like KeyShot (our choice), Blender, etc.

@amiltonwong
Copy link
Author

@Szy-Young , Thanks a lot, I'll try it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants