python-3.x - 在点云中找到一个十字的中心
问题描述
我有一个由从顶部取出的两个圆柱体组成的十字点云。我不知道如何确定位于最高圆柱顶部边缘的交叉元素的中心点?
我还不太擅长 Python 脚本,几天前发现了“PyntCloud”库。我的知识足以在边界框和曲率的帮助下从背景(周围)切割英特尔实感摄像头拍摄的点云。我试图用体素网格简化点云,但现在我不确定它是否可以帮助我找到中心。
output.ply - 代码中使用的 PLY
Screen.png - 带有标记中心点的屏幕截图
这段代码取自 Jupyter Notebook:
import numpy as np
from pyntcloud import PyntCloud
#Cropping everything that doesn't fit the curvature of shapes:
cropped_input = PyntCloud.from_file('C:\Python37\PC\output.ply')
k_neighbors = cropped_input.get_neighbors(k=1000)
ev = cropped_input.add_scalar_field("eigen_values", k_neighbors=k_neighbors)
cropped_input.add_scalar_field("curvature", ev=ev)
curvature = cropped_input.points["curvature(1001)"]
cropped_input.points = cropped_input.points[curvature > curvature.mean()]
cropped_input.to_file("C:\Python37\PC\simplified_cloud.ply")
cropped_input.plot()
#print(cropped_input)
#Use voxel grid to reduce number of points
cropped_input = PyntCloud.from_file('C:\Python37\PC\simplified_cloud.ply')
voxelgrid_id = cropped_input.add_structure("voxelgrid", n_x=30, n_y=30, n_z=30)
new_cloud = cropped_input.get_sample("voxelgrid_nearest", voxelgrid_id=voxelgrid_id, as_PyntCloud=True)
new_cloud.plot()
#print(new_cloud)
我希望收到中心点的坐标,或者从点云列表中获取的点的索引。
先感谢您!
解决方案
正如我在评论中提到的,“质心”在这里不是一个解决方案,因为十字不是对称的。解决方案是使用 numpy 库,并根据这些值确定与从 numpy.histogram 沿每个轴获取的点的密度相关的圆柱交叉区域,并根据这些值创建一个过滤器。然后点云被裁剪,所以从顶部看,图形看起来像矩形(并且几乎是对称的)。只有这样我才使用掩码(numpy.isin)并确定离“质心”最近的点的坐标和索引是什么。
推荐阅读
- javascript - 如何在angularjs中重新加载指令数据?
- c# - 从 Microsoft Computer Vision 调用 Face API,请求正文为“application/json”
- javascript - 如何根据某些条件合并来自 2 个对象的嵌套数组属性?
- angular - 基于mat-table中的多个下拉选择进行过滤
- javascript - jQuery 自定义验证无法正常工作
- html - 无法内联所有按钮以使其看起来像 NavBar
- java - 在文本文件中查找特定单词并将该单词存储在数组列表中
- real-time - 具有单个生产者和单个消费者的环形缓冲区的最佳大小
- node.js - 如何在发布之前安装已发布的范围包?
- php - 如何解决 Laravel 中的“Access-Control-Allow-Origin”问题?