I’m trying to crop a point cloud using 8 corners, the xyz of the corners are right but it seems that no point is included in the volume when cropping, I also created a bounding box from the cornes to be sure that they were right.
corners = calculatePolygon(pcds[0])
# Convert the corners to a numpy array
corners = np.array(corners)
print("Corners:", corners)
# Convert the corners array to have type float64
bounding_polygon = corners.astype("float64")
# Create a SelectionPolygonVolume
vol = o3d.visualization.SelectionPolygonVolume()
points = np.asarray(pcds[0].points)
maxy = max(points[:, 0])
miny = min(points[:, 0])
print("Volume x: ", bounding_polygon[:, 0])
print("Volume z: ", bounding_polygon[:, 2])
vol.orthogonal_axis = "Y"
vol.axis_max = maxy
print("Axis max: ", vol.axis_max)
vol.axis_min = miny
print("Axis min: ", vol.axis_min)
bounding_polygon[:, 1] = 0
vol.bounding_polygon = o3d.utility.Vector3dVector(bounding_polygon)
cropped_pcd = vol.crop_point_cloud(pcds[0])
points = o3d.utility.Vector3dVector(corners)
oriented_bounding_box = o3d.geometry.OrientedBoundingBox.create_from_points(points)
oriented_bounding_box.color = (1, 0, 0)
Calculate Polygon method, where i calculate the max and min of xyz and the corners:
def calculatePolygon(pcd):
# Define the coordinates of the vertices
print("|___________________Calculate_Polygon___________________|")
points = np.asarray(pcds[i].points)
maxx = max(points[:, 0])
minx = min(points[:, 0])
maxy = max(points[:, 1])
miny = min(points[:, 1])
maxz = max(points[:, 2])
minz = min(points[:, 2])
print("Max x: {0}".format(maxx))
print("Min x: {0}".format(minx))
print("Max y: {0}".format(maxy))
print("Min y: {0}".format(miny))
print("Max z: {0}".format(maxz))
print("Min z: {0}".format(minz))
print("|______________________________________________________|")
vertex1 = [minx, maxy, minz]
vertex2 = [maxx, maxy, minz]
vertex3 = [minx, maxy, maxz]
vertex4 = [maxx, maxy, maxz]
vertex5 = [minx, miny, minz]
vertex6 = [maxx, miny, minz]
vertex7 = [minx, miny, maxz]
vertex8 = [maxx, miny, maxz]
corners = [vertex1, vertex2, vertex3, vertex4, vertex5, vertex6, vertex7, vertex8]
print("Vertex 1:", vertex1)
print("Vertex 2:", vertex2)
print("Vertex 3:", vertex3)
print("Vertex 4:", vertex4)
print("Vertex 5:", vertex5)
print("Vertex 6:", vertex6)
print("Vertex 7:", vertex7)
print("Vertex 8:", vertex8)
return corners
New contributor
Alberto Fasan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.