所有人,
我想从点云中裁剪并保存一个区域并保存。
我有BBox坐标(maxx,maxy,minx,miny),它们是Pointcloud的MaxP和MinP,想要从中制作出多边形。使用bbox_to_Polygon(MaxP,MinP)
,BBox坐标将转换为角点。这些应该用于创建两个多边形。因此,我用pyny3D制作了一个Polyhedron。
现在我可以喂我认为带有音量的open3d.visualization.SelectionPolygonVolume()。我不想使用Open3d Docs Crop from Cloud中描述的JSON文件。所以我找到了这个How to Create a open3d.visualization.SelectionPolygonVolume Object Without Loading a json Filel。
为什么是orthogonal_axis="Y"
?为什么不只是“ Z”轴?在example of JSON-File中,Y值为0。我建议使用orthogonal_axis="Y"
,但我不明白为什么?我们不需要PolygonVolume吗?
我会很乐意提供帮助。
我正在使用Google Colab和Jupyter NotebookPython 3.6
#Vertics Poyhedrol to create a PolygonVolume
bounding_polygon = np.array([
#Vertics Polygon 1
[488.8989868164062, 612.208984375, 286.5320129394531],
[485.114990234375, 612.208984375, 286.5320129394531],
[485.114990234375, 605.0880126953125, 286.5320129394531],
[488.8989868164062, 605.0880126953125, 286.5320129394531],
#Vertics Polygon2
[488.89898681640625, 612.208984375, 291.6619873046875],
[485.114990234375, 612.208984375, 291.6619873046875],
[485.114990234375, 605.0880126953125, 291.6619873046875],
[488.89898681640625, 605.0880126953125, 291.6619873046875]]).astype("float64")
vol = o3d.visualization.SelectionPolygonVolume()
vol.orthogonal_axis = "Y"
vol.axis_max = 500
vol.axis_min = 700
vol.bounding_polygon = o3d.utility.Vector3dVector(bounding_polygon)
comp = vol.crop_point_cloud(pcd)
comp
#Since I took the MaxP and MinP of the Pointcloud as BBCoords I would expect the same number of points. But I get this:
#`geometry::PointCloud with 0 points`
这里是整个代码
import numpy as np
import pyny3d
import pyny3d.geoms as pyny
import open3d as o3d
from open3d import JVisualizer
path_incloud = ('/gdrive/My Drive/Colab Notebooks/Georeferenzierung/BildGeoreferenzieren/PointCloud/PointCloudFormats/Kranfundament - Cloud.ply')
pcd = o3d.io.read_point_cloud(path_incloud)
print("Input Cloud:", pcd)
visualizer = JVisualizer()
visualizer.add_geometry(pcd)
visualizer.show()
def bbox_to_Polygon(MaxP,MinP):
p1= [MaxP[0], MaxP[1], MinP[2]]
p2= [MaxP[0],MinP[1],MinP[2]]
p3= [MinP[0],MaxP[1],MinP[2]]
p4= MinP
p5= MaxP
p6= [MinP[0],MaxP[1],MaxP[2]]
p7= [MinP[0],MinP[1],MaxP[2]]
p8= [MaxP[0],MinP[1], MaxP[2]]
listPoints1 = [p1,p3,p4,p2]
print(listPoints1)
listPoints2 = [p5,p6,p7,p8]
print(listPoints2)
return listPoints1,listPoints2
MaxP = MaxPoint_PointCloud
MinP = MinPoint_PointCloud
listPointsPoly1 , listPointsPoly2 = bbox_to_Polygon(MaxP= MaxP, MinP=MinP)
poly1 = pyny.Polygon(np.array(listPoints1))
poly2 = pyny.Polygon(np.array(listPoints2))
poly1.plot()
poly2.plot()
polyhedron = pyny.Polyhedron.by_two_polygons(poly1, poly2)
polyhedron.plot('b')
MaxP = MaxPoint_PointCloud
MinP = MinPoint_PointCloud
#Vertics Poyhedrol to create a PolygonVolume
bounding_polygon = np.array([
#Vertics Polygon 1
[488.8989868164062, 612.208984375, 286.5320129394531],
[485.114990234375, 612.208984375, 286.5320129394531],
[485.114990234375, 605.0880126953125, 286.5320129394531],
[488.8989868164062, 605.0880126953125, 286.5320129394531],
#Vertics Polygon2
[488.89898681640625, 612.208984375, 291.6619873046875],
[485.114990234375, 612.208984375, 291.6619873046875],
[485.114990234375, 605.0880126953125, 291.6619873046875],
[488.89898681640625, 605.0880126953125, 291.6619873046875]]).astype("float64")
vol = o3d.visualization.SelectionPolygonVolume()
vol.orthogonal_axis = "Y"
vol.axis_max = 1000
vol.axis_min = -1000
vol.bounding_polygon = o3d.utility.Vector3dVector(bounding_polygon)
comp = vol.crop_point_cloud(pcd)
print("Cropped Cloud",comp)
您可以选择任何轴作为正交轴。例如,如果选择Z,则使用Z = 0的一组点定义面。然后设置Z最小值和最大值,就像使用Z最小值和最大值之间的多边形拉伸体积一样。希望这会有所帮助。