测试效果
首先拿到点云

去除点云周围的杂点,可以通过高度,可以通过聚类,半径滤波都行
、


识别点云的边缘

这一圈大约200个点
识别到的边缘点 向内寻找最高点

识别到最高点后 向内推固定距离

计算点胶路径的法向量,方便六轴机械手点胶位姿

测试代码
import open3d as o3d
import numpy as np
from scipy.interpolate import splprep, splev
from scipy.spatial import ConvexHull
import cv2
from scipy.spatial import KDTree
import copy
# 2. 栅格化点云为二值图像
def points_to_binary_image(points_2d, resolution=0.1):
"""将点云转换为二值图像(1:有点,0:无点)"""
# 计算图像范围和尺寸
x_min, y_min = np.min(points_2d, axis=0)
x_max, y_max = np.max(points_2d, axis=0)
width = int((x_max - x_min) / resolution) + 1
height = int((y_max - y_min) / resolution) + 1
# 初始化图像
image = np.zeros((height, width), dtype=np.uint8)
# 填充点云位置为1
coords = ((points_2d - [x_min, y_min]) / resolution).astype(int)
image[coords[:, 1], coords[:, 0]] = 255
return image, (x_min, y_min, resolution)
# 2. 计算边缘点的法线方向(指向内部)
def compute_inward_normals(points_2d):
"""计算指向内部的法线(垂直于边界,朝向点云中心)"""
centroid = np.mean(points_2d, axis=0)
normals = points_2d - centroid
normals = normals / np.linalg.norm(normals, axis=1, keepdims=True)
return normals
# 3. 对每个边缘点生成截面线并找最高点
def find_highest_point_on_section(pcd, edge_point, normal, length=5.0, steps=100):
"""
沿法线方向生成截面线,并找最高Z值点
:param edge_point: 边缘点坐标(3D)
:param normal: 法线方向(3D,XY平面内)
:param length: 截面线长度(mm)
:param steps: 截面线采样点数
"""
# 生成截面线点(沿法线方向向内延伸)
t = np.linspace(0, length, steps)
section_points = edge_point + t[:, np.newaxis] * normal
# 找到截面线附近的原始点云中的点
kdtree = KDTree(np.asa

最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



