I have a question about cropping the point cloud. I used YOLO for object detection and then SAM (Segment Anything) to segment the object and create the mask. I am using the Intel Realsense D435i camera to take pictures and generate the point cloud. That’s why I can use the ‘function rs2_deproject_pixel_to_point’ to project the 2D pixel to a 3D point and save this into a numpy array. The result of masks looks like this:
[array([[ 0.16566, 0.16544, 0.741],
[ 0.16277, 0.16377, 0.739],
[ 0.16422, 0.16399, 0.74],
...,
[ 0.11585, 0.075646, 0.752],
[ 0.11678, 0.075445, 0.75],
[ 0.11786, 0.075344, 0.749]]),
array([[ -0.18191, 0.11368, 0.748],
[ -0.18067, 0.11368, 0.748],
[ -0.17967, 0.11384, 0.749],
...,
[ -0.1315, 0.044362, 0.75],
[ -0.13416, 0.043176, 0.751],
[ -0.13292, 0.043176, 0.751]])]
I can visualize it and it looks good to me.
But here is the problem, I need to crop the point cloud from probe_2.ply, which I generated from depth Image.
I try to do that by using this code
# Load the point cloud from the PLY file
pcd = o3d.io.read_point_cloud("probe_2.ply")
all_pcds = [pcd]
vol = o3d.visualization.SelectionPolygonVolume()
vol.orthogonal_axis = "Z"
vol.axis_max = 100
vol.axis_min = -100
i = 0
cropped_pcd = []
aabb = []
aabbs_in_pcd = [pcd]
num_mask = len(masks_3d_points)
while i <= num_mask - 1:
cropped_pcd.append(0)
aabb.append(0)
vol.bounding_polygon = o3d.utility.Vector3dVector(masks_3d_points[i])
cropped_pcd[i] = vol.crop_point_cloud(pcd)
#o3d.visualization.draw_geometries([cropped_pcd[i]])
#print(cropped_pcd[i])
aabb[i] = cropped_pcd[i].get_axis_aligned_bounding_box()
aabb[i].color = (1, 0, 0)
aabbs_in_pcd.append(aabb[i])
aabbs_in_pcd.append(cropped_pcd[i])
#all_pcds.append(cropped_pcd[i])
i += 1
#Disable to show bounding boxes in whole pcd
#aabbs_in_pcd.remove(pcd)
o3d.visualization.draw_geometries(aabbs_in_pcd)
o3d.visualization.draw_geometries(cropped_pcd)
However, it couldn’t crop the point cloud like the mask’s object. How can I fix it?
I would greatly appreciate anyone who can help me!
Here is the cropped point cloud, which looks pretty bad to me.