下图是OpenCV官方文档中,对直线拟合函数的详细介绍:

OpenCV fitline直线拟合函数学习

fitLine()函数用于,对二维或三维空间中的点集进行直线拟合。共有六个参数:

param 1:输入的点集,可以是Mat或者vector<>,可以是二维点集或三维点集。

例如:

vector<Point> points;

param 2:拟合结果,即一条直线。在二维空间中,直线可以定义为

Vec4f line;

在二维平面中,(line[0],line[1])表示直线的方向向量,(line[2],line[3])表示直线上的一个点。 

param 3:拟合算法,CV_DIST_L2为最简单快速的最小二乘法,推荐使用。

定义在源文件中的枚举类型:

 1 //! Distance types for Distance Transform and M-estimators
 2 enum { DIST_USER = -1, // User defined distance
 3 DIST_L1 = 1, // distance = |x1-x2| + |y1-y2|
 4 DIST_L2 = 2, // the simple euclidean distance
 5 DIST_C = 3, // distance = max(|x1-x2|,|y1-y2|)
 6 DIST_L12 = 4, // L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1))
 7 DIST_FAIR = 5, // distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998
 8 DIST_WELSCH = 6, // distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846
 9 DIST_HUBER = 7 // distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345
10 };
View Code

相关文章:

  • 2021-12-27
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-06
  • 2021-11-08
猜你喜欢
  • 2021-06-13
  • 2022-12-23
  • 2021-11-08
  • 2022-01-13
  • 2021-12-19
  • 2021-10-03
  • 2021-07-27
相关资源
相似解决方案