Skip to content

Point cloud crop using bounding boxΒ #6436

Closed

Description

@itsgoodforyou2

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

Activity

  1. saurabheights commented on Oct 21, 2023

    @saurabheights
    Contributor

    @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])
    
  2. itsgoodforyou2 commented on Oct 22, 2023

    @itsgoodforyou2
    Author

    @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.

  3. added 3 commits that reference this issue on Oct 22, 2023
    f3a37b2
    7145f91
    20df843
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions