2

According to this answer, cv::fitLine with distType set to CV_DIST_L2 is a standard least squares method. However, looking at the code it's seems to use a different formula:

origin = (mean(x), mean(y)); // this is as in standard ls

angle = 0.5 * atan2( 2 * cov(x, y), (var(x) - var(y)));

can someone explain me the last formula?

Edit: this is actually a total least squares. For more information read here.

E. KOW
  • 121
  • 1
  • 4
  • 1
    Have you tried reading [the documentation](https://docs.opencv.org/2.4/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html) ? – Jesper Juhl Nov 20 '17 at 20:27
  • Of course, it's also says that the first method uses the simple least squares method. – E. KOW Nov 20 '17 at 20:31
  • how should the formula look instead? Maybe it is transformed with some properties of covariances? atan2 is used to get the angle formed by x and y components. – Micka Nov 20 '17 at 21:47
  • 1
    The common formula (see for example here: mathworld.wolfram.com/LeastSquaresFitting.html) when using the line representation y = a + b * x is b = cov(x, y) / var(x), so in origin-direction representation it's becomes angle = atan2(cov(x, y), var(x)). I can't see how this is a transformation of the first formula but I would be happy to see an explanation in case it is. – E. KOW Nov 20 '17 at 22:14

0 Answers0