各位,
我想从点云裁剪并保存一个区域,然后保存它
我有BBox坐标(maxx,maxy,minx,miny),它们是点云的MaxP和MinP,并希望从中生成一个多边形。使用bbox_to_Polygon(MaxP,MinP)
将BBox坐标转换为角点。这些应用于创建两个多边形。因此,我与pyny3D进行了一次Polyhedron
现在我可以吃了 我想,open3d.visualization.SelectionPolygonVolume()和一个卷。 我不想使用Open3d文档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"
,但我不明白为什么?我们不需要一本多功能卷吗
我希望能得到一些帮助
我正在使用Google Colab和Jupyter笔记本电脑 Python 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)
下面是一个简短的版本,演示了如何使用
np.array
个顶点裁剪点云:之前的示例:
后面的示例(来自云中心的蓝色点块):
您可以选择任意轴作为正交轴。例如,如果选择Z,则使用一组Z=0的点定义多边形。然后设置Z最小值和最大值,就像使用Z最小值和最大值之间的多边形挤出体积一样。希望这有帮助
这篇文章帮助我在长方体范围内裁剪出一个点云。我还经常使用
vol.crop_point_cloud(pcd)
遇到geometry::PointCloud with 0 points
,无法使它工作,但我找到了一个不同的解决方案最后,我引用了这个PR#1218来使用open3d.geometry.OrientedBoundingBox长方体来裁剪点云。下面的代码围绕开始位置创建一个200m x 200m的“平铺”长方体,该长方体对应于点云内的ego车辆开始姿势,并过滤仅位于平铺内的点
相关问题 更多 >
编程相关推荐