cv.fitLine - MATLAB File Help |
Fits a line to a 2D or 3D point set
lin = cv.fitLine(points)
lin = cv.fitLine(points, 'OptionName',optionValue, ...)
{[x,y], [x,y], ...}
or a
Nx2/Nx1x2/1xNx2 numeric array. 3D points stored in a cell array of
3-element vectors in the form {[x,y,z], [x,y,z], ...}
or a
Nx3/Nx1x3/1xNx3 numeric array.[vx,vy, x0,y0]
, where [vx,vy]
is a normalized vector
collinear to the line and [x0,y0]
is a point on the line. In case of 3D
fitting, it is a 6-elements vector [vx,vy,vz, x0,y0,z0]
, where
[vx,vy,vz]
is a normalized vector collinear to the line and [x0,y0,z0]
is a point on the line.C
) for some types of distances. If it is
0, an optimal value is chosen. default 0.The function cv.fitLine fits a line to a 2D or 3D point set by minimizing
sum_{i}(rho(r_i))
where r_i
is a distance between the i-th point and the
line, and rho(r)
is a distance function, one of the following:
L2
rho(r) = r^2/2 (the simplest and the fastest least-squares method)
L1
rho(r) = r
L12
rho(r) = 2 * (sqrt(1+r^2/2) - 1)
Fair
rho(r) = C^2 * (r/C - log(1 + r/c)), where C = 1.3998
Welsch
rho(r) = C^2/2 * (1 - exp(-(r/c)^2)), where C = 2.9846
Huber
| r^2/2 if r<C
rho(r) = | , where C = 1.345
| C * (r - C/2) otherwise
The algorithm is based on the
M-estimator technique that
iteratively fits the line using the weighted least-squares algorithm. After
each iteration the weights w_i
are adjusted to be inversely proportional
to rho(r_i)
.