[][src]Function opencv::imgproc::fit_ellipse_ams

pub fn fit_ellipse_ams(points: &dyn ToInputArray) -> Result<RotatedRect>

Fits an ellipse around a set of 2D points.

The function calculates the ellipse that fits a set of 2D points. It returns the rotated rectangle in which the ellipse is inscribed. The Approximate Mean Square (AMS) proposed by Taubin1991 is used.

For an ellipse, this basis set is inline formula, which is a set of six free coefficients inline formula. However, to specify an ellipse, all that is needed is five numbers; the major and minor axes lengths inline formula, the position inline formula, and the orientation inline formula. This is because the basis set includes lines, quadratics, parabolic and hyperbolic functions as well as elliptical functions as possible fits. If the fit is found to be a parabolic or hyperbolic function then the standard #fitEllipse method is used. The AMS method restricts the fit to parabolic, hyperbolic and elliptical curves by imposing the condition that inline formula where the matrices inline formula and inline formula are the partial derivatives of the design matrix inline formula with respect to x and y. The matrices are formed row by row applying the following to each of the points in the set: \f{align*}{ D(i,:)&=\left{x_i^2, x_i y_i, y_i^2, x_i, y_i, 1\right} & D_x(i,:)&=\left{2 x_i,y_i,0,1,0,0\right} & D_y(i,:)&=\left{0,x_i,2 y_i,0,1,0\right} \f} The AMS method minimizes the cost function \f{equation*}{ \epsilon ^2=\frac{ A^T D^T D A }{ A^T (D_x^T D_x + D_y^T D_y) A^T } \f}

The minimum cost is found by solving the generalized eigenvalue problem.

\f{equation*}{ D^T D A = \lambda \left( D_x^T D_x + D_y^T D_y\right) A \f}

Parameters

  • points: Input 2D point set, stored in std::vector<> or Mat