第一步,先用MeshLab软件打开ply点云文件,然后点击工具栏的信息按钮,再按空格键切换为点提取模式,用鼠标在要测量的面上拾取点并查看三维坐标,多拾取几个点得到要测量面的大概Z轴范围。
第二步,使用Halcon读取ply点云文件,通过Z轴范围对点云进行过滤,代码如下:
dev_close_window ()
dev_open_window (0, 0, 400, 500, ‘black’, WindowHandle)
*读取点云ply文件
read_object_model_3d(‘PointCloud_20220815155258886.ply’, ‘mm’, ‘convert_to_triangles’, ‘true’, ObjectModel3D, Status)
*过滤Z轴指定范围内的点
select_points_object_model_3d (ObjectModel3D, ‘point_coord_z’, -0.490, -0.480, ObjectModel3DThresholded)
*拟合平面
fit_primitives_object_model_3d (ObjectModel3DThresholded, [‘primitive_type’,‘fitting_algorithm’], [‘plane’,‘least_squares_tukey’], ObjectModel3DOut)
*获取平面位姿
get_object_model_3d_params (ObjectModel3DOut, ‘primitive_pose’, Pose)
*将点云坐标系转为拟合平面的坐标系
pose_to_hom_mat3d(Pose, HomMat3D)
hom_mat3d_invert(HomMat3D, HomMat3DInvert)
affine_trans_object_model_3d(ObjectModel3DThresholded, HomMat3DInvert, ObjectModel3DAffineTrans)
*显示点云和坐标轴
visualize_object_model_3d (WindowHandle, ObjectModel3DAffineTrans, [], [],
[‘lut’,‘color_attrib’,‘disp_pose’],
[‘color1’,‘coord_z’,‘true’], ‘’, [], [], PoseOut)
最终,显示点云如下: