halcon拓展系列—平面拟合算子fit_plane

本文详细介绍了Halcon的fit_plane算子,用于最小二乘法平面拟合,适用于线激光设备的点云图像处理。算子在平面度和段差计算中有应用,但不适用于倾斜平面的滤波。文章还提到了相关基础算子fit_surface_first_order和gen_image_surface_first_order的功能和参数说明。

一、算子说明

fit_plane(imageRealrectangleFit : imageSurface : rateLowRemoverateHighRemoveoperatorType : )

** 功能:最小二乘法拟合平面
** 输入
** image                             点云图像
** rectangleFit                    拟合区域
** rateLowRemove            去除高度低的百分比(滤波) eg:0.1
** rateHighRemove           去除高

Hi~ 可私信我了解后再进行下载~ 1.基于halcon算法平台; 2.提供深度图源文件以及解压密码; 3.代码预览: */********************************* * @文档名称: 基于点云的平面拟合。 * @作者: hugo * @版本: 1.1 * @日期: 2021-6-16 * @描述: 该方法支持点云平面拟合以及深度图平面拟合。 **********************************/* read_image (imageReal, './replay_38893_2021-6-7.tif') xResolution:=0.06 yResolution:=0.06 zResolution:=0.001 ScaleFactor:=[xResolution,yResolution,zResolution] rateLowRemove:=0.1 rateHighRemove:=0.1 dev_get_window (WindowHandle) *采样区域1 create_drawing_object_rectangle2 (300, 120, rad(90), 30, 20, DrawID) set_drawing_object_params (DrawID, 'color', 'red') set_drawing_object_params (DrawID, 'line_width', 1) attach_drawing_object_to_window (WindowHandle, DrawID) ......... TransPose := [0,0,d,0,0,0,0] rigid_trans_object_model_3d (SampledObjectModel3D1, TransPose, _SampledObjectModel3D1) rigid_trans_object_model_3d (ObjectModelPlane1, TransPose, _ObjectModelPlane1) create_pose (0, 0, Mean/2, 180, 0, 0, 'Rp+T', 'gba', 'point', Pose1) *visualize_object_model_3d (WindowHandle, [_ObjectModelPlane1,_SampledObjectModel3D1,SampledObjectModel3D2], [], [Pose1], [], ['intensity','lut','lut'], ['&amplitude','sqrt','sqrt'], '', 'Edited by AmazingRobot+ ' , PoseOut) visParamName := ['intensity_1','color_0','color_2','alpha_0'] visParamValue := ['coord_z','red','yellow',0.5] visualize_object_model_3d (WindowHandle, [_SampledObjectModel3D1,SampledObjectModel3D2,_ObjectModelPlane1], [], [], visParamName, visParamValue, 'Edited by AmazingRobot+', [], '', PoseOut) stop () 谢谢您的信任~
fit_plane_3d_ransac函数使用Halcon实现的代码及函数编写思路如下: 函数代码: ```python def fit_plane_3d_ransac(points, max_iterations=100, distance_threshold=0.01): """ :param points: List of 3D points in the format [(x1, y1, z1), (x2, y2, z2), ...] :param max_iterations: Maximum number of iterations to perform :param distance_threshold: Distance threshold to determine inliers :return: A tuple of the form (a, b, c, d), representing the plane equation ax + by + cz + d = 0 """ import numpy as np import math import copy best_inliers = [] best_plane = None # Convert points to Halcon format halcon_points = np.array(points, dtype=np.float64) halcon_points = np.transpose(halcon_points) # Convert distance threshold to Halcon format halcon_distance_threshold = distance_threshold # Loop through the specified number of iterations for i in range(max_iterations): # Randomly select 3 points random_points = np.random.choice(halcon_points.shape[1], 3, replace=False) random_points = halcon_points[:, random_points] # Fit a plane to the random points using Halcon's ransac_plane function plane_coefficients = hoperators.ransac_plane(random_points, 'distance', halcon_distance_threshold) # Extract the plane coefficients from the result a = plane_coefficients[0] b = plane_coefficients[1] c = plane_coefficients[2] d = plane_coefficients[3] # Compute the distance between all points and the plane distances = [] for j in range(halcon_points.shape[1]): point = halcon_points[:, j] distance = math.fabs(a * point[0] + b * point[1] + c * point[2] + d) / math.sqrt(a ** 2 + b ** 2 + c ** 2) distances.append(distance) # Determine the inliers based on the distance threshold inliers = [point for j, point in enumerate(points) if distances[j] < distance_threshold] # If the number of inliers is greater than the current best, update the best plane and inliers if len(inliers) > len(best_inliers): best_inliers = copy.deepcopy(inliers) best_plane = (a, b, c, d) return best_plane ``` 函数编写思路: 1. 首先定义一个函数fit_plane_3d_ransac,该函数接收一个包含3D点的列表,最大迭代次数和距离阈值作为输入参数。 2. 在函数中,定义一个变量best_inliers,用于存储当前拟合平面中的内点,同时定义一个变量best_plane,用于存储当前最佳平面的方程。 3. 将输入的points转换为Halcon格式。 4. 在循环中,执行max_iterations次以下操作: - 随机选择三个点。 - 使用Halcon的ransac_plane函数拟合这三个点所在的平面方程。 - 从拟合结果中提取平面方程系数。 - 计算所有点到该平面的距离。 - 根据距离阈值确定内点。 - 如果内点数目大于当前最佳平面的内点数目,则更新最佳平面和内点。 5. 返回最佳平面的方程。 总的来说,该函数使用Halcon的ransac_plane函数来拟合3D平面,可以在存在噪声和离群值的情况下得到可靠的结果。注意,由于Halcon的ransac_plane函数返回的平面方程系数的顺序与Python中的顺序不同,因此需要在函数中进行转换。
评论 56
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

谷棵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值