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

Segmentation Fault for Colored Point Cloud Registration #6935

Closed
3 tasks done
aenoca opened this issue Aug 27, 2024 · 3 comments · Fixed by #6942
Closed
3 tasks done

Segmentation Fault for Colored Point Cloud Registration #6935

aenoca opened this issue Aug 27, 2024 · 3 comments · Fixed by #6942
Labels
bug Not a build issue, this is likely a bug.

Comments

@aenoca
Copy link

aenoca commented Aug 27, 2024

Checklist

Describe the issue

I have been trying to fit two colored point clouds together using colored icp and it returns a segfault every single time. I know some other issue has brought up a similar issue but for the general icp_registration.

Steps to reproduce the bug

import open3d as o3d
import numpy as np

cylinder = o3d.geometry.TriangleMesh.create_cylinder(radius=0.05, height=0.3, resolution=20, split=20)
cylinder.paint_uniform_color([0.5, 0.5, 0.5])
points = cylinder.sample_points_uniformly(3000)

# assign color to the points
points.colors = o3d.utility.Vector3dVector([np.random.rand(3) for i in range(len(points.points))])

# Visualize the pointcloud
# o3d.visualization.draw_geometries([points])

# color the cylinder with the same color as the pointcloud
kdtree = o3d.geometry.KDTreeFlann(cylinder)

# For each point in the point cloud, find the nearest vertex on the mesh
print(len(points.points), len(cylinder.vertices))
for i, point in enumerate(points.points):
    _, idx, _ = kdtree.search_knn_vector_3d(point, 1)  # KNN search for 1 nearest neighbor
    nearest_vertex_index = idx[0]

    # print(nearest_vertex_index, i, len(self.pc_colors), len(self.mesh.vertex_colors))
    
    # Transfer the color from the point cloud to the corresponding mesh vertex
    # print(idx, i)
    cylinder.vertex_colors[nearest_vertex_index] = points.colors[i]

# Visualize the colored mesh
# o3d.visualization.draw_geometries([cylinder])

# sample new points from the cylinder
new_points = cylinder.sample_points_uniformly(2500)
# rotate the cylinder
R = cylinder.get_rotation_matrix_from_xyz((0, 0, np.pi/12))
new_points.points = o3d.utility.Vector3dVector(np.asarray(new_points.points) @ R.T)

# display the new points

voxel_size = 0.001
# downsample the pointclouds
points = points.voxel_down_sample(voxel_size)
new_points = new_points.voxel_down_sample(voxel_size)
new_points.estimate_normals()
o3d.visualization.draw_geometries([points, new_points])

result = o3d.pipelines.registration.registration_icp(
    points, new_points, max_correspondence_distance=1.5*voxel_size, init=np.eye(4),
    estimation_method=o3d.pipelines.registration.TransformationEstimationForColoredICP(),
criteria=o3d.pipelines.registration.ICPConvergenceCriteria(relative_fitness=1e-6,
                                                          relative_rmse=1e-6,
                                                          max_iteration=300))

print(result.transformation)

Error message

Segmentation fault (core dumped)

Expected behavior

A print of the transformation from one pointcloud to the other (if it has converged)

Open3D, Python and System information

- Operating system: Ubuntu 22.04
- Python version: Python 3.10.12
- Open3D version: 0.18.0
- System architecture: x86 
- How did you install Open3D?: pip

Additional information

No response

@aenoca aenoca added the bug Not a build issue, this is likely a bug. label Aug 27, 2024
@nicolaloi
Copy link
Contributor

Theoretically, you could use either registration_colored_icp or registration_icp. But indeed there is a bug when using registration_icp with TransformationEstimationForColoredICP(), it seems the colored point cloud is not initialized correctly. I will open a PR, but you can already use registration_colored_icp.

@aenoca
Copy link
Author

aenoca commented Aug 28, 2024

Okay great! I'll try that one out.

@kanao-contineu
Copy link

@aenoca what's your numpy version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not a build issue, this is likely a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@aenoca @nicolaloi @kanao-contineu and others