[][src]Function opencv::imgproc::fit_ellipse_direct

pub fn fit_ellipse_direct(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 Direct least square (Direct) method by Fitzgibbon1999 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. The Direct method confines the fit to ellipses by ensuring that inline formula. The condition imposed is that inline formula which satisfies the inequality and as the coefficients can be arbitrarily scaled is not overly restrictive.

\f{equation*}{ \epsilon ^2= A^T D^T D A \quad \text{with} \quad A^T C A =1 \quad \text{and} \quad C=\left(\begin{matrix} 0 & 0 & 2 & 0 & 0 & 0 \ 0 & -1 & 0 & 0 & 0 & 0 \ 2 & 0 & 0 & 0 & 0 & 0 \ 0 & 0 & 0 & 0 & 0 & 0 \ 0 & 0 & 0 & 0 & 0 & 0 \ 0 & 0 & 0 & 0 & 0 & 0 \end{matrix} \right) \f}

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

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

The system produces only one positive eigenvalue inline formula which is chosen as the solution with its eigenvector inline formula. These are used to find the coefficients

\f{equation*}{ A = \sqrt{\frac{1}{\mathbf{u}^T C \mathbf{u}}} \mathbf{u} \f} The scaling factor guarantees that inline formula.

Parameters

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