Halcon直线拟合fit_line_contour_xld详解

Halcon直线拟合fit_line_contour_xld详解
fit_line_contour_xld
原型
fit_line_contour_xld(Contours : : Algorithm, MaxNumPoints, ClippingEndPoints, Iterations, ClippingFactor : RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)
功能
根据XLD轮廓拟合直线
参数列表
Contours (input_object) :输⼊的XLD轮廓
拟合直线Algorithm (input_control):直线拟合算法( ‘drop’, ‘gauss’, ‘huber’, ‘regression’, ‘tukey’)
MaxNumPoints (input_control):参与拟合直线的最⼤轮廓点数(设置-1代表所有点参与计算;最⼩值要⼤于等于2,因为⾄少两点才能确认⼀条直线)
ClippingEndPoints (input_control) :拟合直线时,需要忽略轮廓起始处点个数。(⼀个XLD轮廓会被线分割成很多个⼩轮廓)Iterations (input_control) :最⼤迭代次数。(不适⽤于’regression’)
ClippingFactor (input_control):剔除异常值因⼦。(算法 ‘huber’ 、‘drop’ 设置1.0,'tukey’设置2.0)
RowBegin (output_control) :拟合后的线段起始点⾏坐标
ColBegin (output_control) :拟合后的线段起始点列坐标
RowEnd (output_control) :拟合后的线段终点点⾏坐标
ColEnd (output_control) :拟合后的线段终点点列坐标
Nr (output_control) :直线⽅程法线式x相乘系数
Nc (output_control) :直线⽅程法线式y相乘系数
Dist (output_control) :坐标系原点到线段的距离
详解
fit_line_contour_xld⽬的是将⼀个XLD轮廓拟合成⼀条线段。⼏何数学上获取线段的起始点坐标,以及直线法线式⽅程中的Nr,Nc向量。
法线式⽅程如下:
这个算⼦在⼯业检测中有很⼤⽤处,⽐如:
1、精细寻产品的边界⽤于⾓度计算
2、拟合两条边,然后求交点,做定位⽤
3、求解参与拟合的点到直线的距离,可以做异常值检测
拟合直线的算法有以下⼏种:
‘regression’:回归,标准的最⼩⼆乘法拟合
‘huber’:加权的最⼩⼆乘法拟合,异常值的影响被减⼩。
‘tukey’:加权的最⼩⼆乘法拟合,异常值被忽略,Halcon推荐⽅法。
‘drop’:加权的最⼩⼆乘法拟合,异常值被忽略。
‘gauss’:加权的最⼩⼆乘法拟合,异常值去除是根据轮廓点距拟合直线距离的平均值以及标准差⽅式决定。
Part1
For ‘huber’, ‘tukey’, and ‘drop’ a robust error statistics is used to estimate the standard deviation of the distances from the contour points without outliers from the approximating line. The parameter ClippingFactor (a scaling factor for the standard deviation) controls the amount of outliers: The smaller the value chosen for ClippingFactor the more outliers are detected. The detection of outliers is repeated. The parameter Iterations specifies the number of iterations.
没有原码,根据上⾯说明⽂档结合实际项⽬应⽤经验,说说我的理解:针对’huber’, ‘tukey’, 'drop’这三种算法,⾸先是根据所有点近似拟合⼀条直线,然后计算原始轮廓上每⼀点到拟合直线的距离,再根据统计学中标准差⽅式去除异常点。
假设有100个点参与拟合直线,其中有20个点是偏离直线的异常点,那么通过标准差的⽅式100个点对应100个统计值,按照距离直线远近从⼤到⼩排序。如果都参与拟合直线,拟合的直线和实际会有偏差,
原因是其中混杂了异常值,所以为了确保拟合的准确度,可以通过参数 ClippingFactor 控制要排除的异常点数量,值越⼩,参与拟合的异常值越多,拟合的准确度越低。
为了进⼀步提⾼拟合精度,参数Iterations 控制迭代次数,也就是说每次都会重复以上步骤。
Part2
In the mode ‘regression’ this value is ignored. Note that in the approach of Tukey (‘tukey’), the outliers are removed before performing the approximation and all other points are weighted, whereas in the approach of Huber (‘huber’), the outliers still have a small influence.
需要注意的是这个值对⽅法’regression’ 不起作⽤;⽅法’tukey’在拟合直线时去除了所有的异常值;异常值对⽅法’huber’依然会存在影响。
Particularly, for outliers the optimization is influenced linearly and for points with a smaller distance it is influenced to the square. In practice, the approach of Tukey is recommended.
虽然可以通过计算标准差、参数ClippingFactor 控制异常值个数、Iterations 增加迭代次数尽可能避免异常值对拟合直线的影响。但求解最优直线⽅程始终是有限的,只能说⽆限逼近。有的⼩伙伴会说,不是有ClippingFactor 、Iterations 这两个参数可以控制吗,那这两个参数如何组合才是最优?Clippin
gFactor 、Iterations ⼤了,会造成拟合的点变少,⽽且也许去掉的所谓‘异常值’,实际是正常值呢;值太⼩也会有同样的问题,所以只能说是⽆限接近,始终会存在误差。Halcon推荐使⽤Tukey ⽅法。
Part3
To reduce the computational load, the fitting of lines can be restricted to a subset of the contour points: If a value other than -1 is assigned to MaxNumPoints, only up to MaxNumPoints points - uniformly distributed over the contour - are used.介绍的是MaxNumPoints 参数,⽬的是提⾼拟合效率。如果你的轮廓⽐较长,轮廓点较多,⼜想节约时间,不妨考虑通过这个参数控制要参与拟合的轮廓点。如果不在乎时间,默认值-1即可。需要注意的时除了-1外,这个值最⼩要为2,因为⾄少两个点才能确定⼀条线段。
Part4
The start point and the end point of a line segment is determined by projecting the first and the last point of the corresponding contour to the approximating line. Due to artifacts in the pre-processing the start and end points of a
contour might be faulty. Therefore, it is possible to exclude ClippingEndPoints points at the beginning
and at the end of a contour from the line fitting. However, they are still used for the determination of the start point and the end point of the line segment.
The minimum necessary number of contour points for fitting a line is two. Therefore, it is required that the number of contour points is at least .
介绍的是ClippingEndPoints参数。获取的轮廓⼀般头尾会有缺陷,⽐如可能是相邻区域的衔处,预处理获取轮廓的时候会多出来⼀部分弧度或者线条,因此需要设置参数ClippingEndPoints控制去除头尾的轮廓点数。去除的头尾轮廓点数始终是ClippingEndPoints值的2倍,因此如果这个参数⼤于0,就必须要求参与拟合直线的轮廓⾄少有2+2ClippingEndPoints个点。虽然头尾去除了2ClippingEndPoints个点,但拟合的直线头尾位置依然是根据原始轮廓的起点确定的,不会因为去除了部分点造成拟合的线段变短了。
举例
1、介绍的是在实际应⽤中寻产品边缘点,然后根据边缘点拟合直线,最后计算出产品偏移⾓度,根据⾓度可以进⾏后续纠偏等操作
2、介绍的是在实际应⽤中根据寻点拟合两个边界直线,然后求两直线交点作为定位点。这样的好处是定位点⽐直接不拟合直线求交点的精度要精准的多。

本文发布于:2024-09-23 16:27:12,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/4/359515.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:拟合   直线   轮廓   参数   线段   参与   控制   计算
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议