使用 Open3D 将点云与地板(平面)对齐

ray*_*yon 7 python 3d numpy rotational-matrices open3d

社区,

\n

我正在尝试使用 Open3D 将点云与检测到的地板对齐。到目前为止,我实施了以下步骤(此答案的一部分):

\n
    \n
  1. 使用 Open3D 的平面分割检测地板
  2. \n
  3. 将平面平移到坐标中心
  4. \n
  5. 计算平面法线与 z 轴之间的旋转角度
  6. \n
  7. 计算旋转轴
  8. \n
  9. 使用 Open3Ds 函数旋转点云get_rotation_matrix_from_axis_angle(参见3
  10. \n
\n

结果还不错,但我必须在最后使用优化因子以获得更好的结果。是否有错误或更简单/更精确的对齐方式?

\n
# See functions below\n\n# Get the plane equation of the floor \xe2\x86\x92 ax+by+cz+d = 0\nfloor = get_floor_plane(pcd)\na, b, c, d = floor\n\n# Translate plane to coordinate center\npcd.translate((0,-d/c,0))\n\n# Calculate rotation angle between plane normal & z-axis\nplane_normal = tuple(floor[:3])\nz_axis = (0,0,1)\nrotation_angle = vector_angle(plane_normal, z_axis)\n\n# Calculate rotation axis\nplane_normal_length = math.sqrt(a**2 + b**2 + c**2)\nu1 = b / plane_normal_length\nu2 = -a / plane_normal_length\nrotation_axis = (u1, u2, 0)\n\n# Generate axis-angle representation\noptimization_factor = 1.4\naxis_angle = tuple([x * rotation_angle * optimization_factor for x in rotation_axis])\n\n# Rotate point cloud\nR = pcd.get_rotation_matrix_from_axis_angle(axis_angle)\npcd.rotate(R, center=(0,0,0))\n\n# FUNCTIONS    \ndef vector_angle(u, v):\n    return np.arccos(np.dot(u,v) / (np.linalg.norm(u)* np.linalg.norm(v)))\n\ndef get_floor_plane(pcd, dist_threshold=0.02, visualize=False):\n    plane_model, inliers = pcd.segment_plane(distance_threshold=dist_threshold,\n                                             ransac_n=3,\n                                             num_iterations=1000)\n    [a, b, c, d] = plane_model    \n    return plane_model\n
Run Code Online (Sandbox Code Playgroud)\n