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

Point cloud crop using bounding box #6436

Closed
3 tasks done
itsgoodforyou2 opened this issue Oct 20, 2023 · 2 comments · Fixed by #6444
Closed
3 tasks done

Point cloud crop using bounding box #6436

itsgoodforyou2 opened this issue Oct 20, 2023 · 2 comments · Fixed by #6444
Labels

Comments

@itsgoodforyou2
Copy link

itsgoodforyou2 commented Oct 20, 2023

Checklist

My Question

Hello, I'm trying to crop the point cloud using the bounding box. However, it doesn't seem to work as well as the attached image. Is there something wrong?
After running line 332, the problem is that the number of point clouds is zero. And when I visualize, of course, none of the points come out.
pointcloud file format is ply.
Regards,
jihwan.

image
image
image
before
after

@saurabheights
Copy link
Contributor

saurabheights commented Oct 21, 2023

@itsgoodforyou2 The issue happens from creating bounding box with incorrect min_bound and max_bound. For a quick fix, you should just change min_bd and max_bd variable such that min_bd is smaller in each dimension against max_bd.

@ssheorey Will it be ok if I add a PR for this? It will be my first PR in C++ side.

Short Code to replicate above issue and further analysis:-

import open3d as o3d

correct_bounding_box_bound_values = True
incorrect_bounding_box_values_in_two_dimensions = False
if correct_bounding_box_bound_values:
    lower_b = [-2.0, -2.0, 1.0]
    upper_b = [4.0, 2.0, 2.0]
elif incorrect_bounding_box_values_in_two_dimensions:
    # When max bound value is smaller in two dimensions, it gives correct volume since upper_b-lower_b is negative in two places
    # Here bounding box can be visualized but cropping fails.
    # When max bound value is smaller in 1 or 3 dimensions,
    # it gives incorrect volume since max-min is negative in 1 or 3 places respectively.
    lower_b = [4.0, -2.0, 1.0]
    upper_b = [3.0, 2.0, -2.0]
else:
    # Here bounding box cannot be visualized and crop will crash with error - AxisAlignedBoundingBox either
    # has zeros size, or has wrong bounds.
    lower_b = [2.0, -2.0, 1.0]
    upper_b = [3.0, 2.0, -2.0]

bbox = o3d.geometry.AxisAlignedBoundingBox(min_bound=lower_b, max_bound=upper_b)
bbox.color = [1.0, 0.0, 0.0]
print(bbox, bbox.get_extent(), bbox.volume())

ply_point_cloud = o3d.data.PLYPointCloud()
pcd = o3d.io.read_point_cloud(ply_point_cloud.path)

o3d.visualization.draw_geometries([bbox, pcd],
                                  zoom=0.3412,
                                  front=[0.4257, -0.2125, -0.8795],
                                  lookat=[2.6172, 2.0475, 1.532],
                                  up=[-0.0694, -0.9768, 0.2024])
pcd1 = pcd.crop(bbox)
o3d.visualization.draw_geometries([bbox, pcd1],
                                  zoom=0.3412,
                                  front=[0.4257, -0.2125, -0.8795],
                                  lookat=[2.6172, 2.0475, 1.532],
                                  up=[-0.0694, -0.9768, 0.2024])

@itsgoodforyou2
Copy link
Author

itsgoodforyou2 commented Oct 22, 2023

@saurabheights

Thank you for your reply.
I found that the function works only when the values of each dimension of min_bd are smaller than those of all dimension of max_bd.

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