OpenCV的线拟合算法算法、OpenCV

2023-09-11 02:13:57 作者:小屁孩先森^

我想了解OpenCV的fitLine()算法。

I'm trying to understand OpenCV fitLine() algorithm.

这是来自OpenCV的code片段: icvFitLine2D功能 - icvFitLine2D

This is fragment of code from OpenCV: icvFitLine2D function - icvFitLine2D

我看到有一些随机函数,选择点近似,然后计算距离从点到fited线(带choosen点),然后选择的其他点,并试图尽量减少与choosen distType距离

I see that there is some random function that chooses points for approximation, then computes distances from points to fited line (with choosen points), then choose other points and tries to minimize distance with choosen distType.

有人可以明确的this此刻中没有硬数学和假设没有很大的统计知识。 OpenCV的code意见和变量名并不能帮助我理解这个code。

Can someone clarify what happens from this moment without hard mathematics and assuming no great statistic knowledge. OpenCV code comments and variable names does not help me in understanding this code.

推荐答案

(这是一个老问题,但这个问题引起了我的好奇心)

(This is an old question, but the subject piqued my curiosity)

OpenCV的FitLine implemements两种不同的机制。

The openCV FitLine implemements two different mechanisms.

如果参数distType设为CV_DIST_L2,然后一个标准未加权最小二乘拟合的被使用。

If the parameter distType is set to CV_DIST_L2, then a standard unweighted least squares fit is used.

如果使用的其它distTypes之一(CV_DIST_L1,CV_DIST_L12,CV_DIST_FAIR,CV_DIST_WELSCH,CV_DIST_HUBER),那么该过程是某种 RANSAC 适合:

If one of the other distTypes is used (CV_DIST_L1, CV_DIST_L12, CV_DIST_FAIR, CV_DIST_WELSCH, CV_DIST_HUBER) then the procedure is some sort of RANSAC fit:

在重复最多的20倍: 在挑选10个随机点,做一个最小二乘法只适合它们 在重复最多的30倍​​: 计算的权重的所有点,使用当前发现线和所选distType 请加权最小适合所有点的广场 (这是一个迭代重加权最小二乘法拟合或的