samples/cpp/fitellipse.cpp
Примеры с cv2.imshow требуют сборки OpenCV с GUI. В ноутбуке с headless-версией используйте вывод изображений через Matplotlib.
Loading...
Searching...
No Matches
samples/cpp/fitellipse.cpp
An example using the fitEllipse technique
/********************************************************************************
*
*
* This program is demonstration for ellipse fitting. Program finds
* contours and approximate it by ellipses using three methods.
* 1: OpenCV's original method fitEllipse which implements Fitzgibbon 1995 method.
* 2: The Approximate Mean Square (AMS) method fitEllipseAMS proposed by Taubin 1991
* 3: The Direct least square (Direct) method fitEllipseDirect proposed by oy1998NumericallySD.
*
* Trackbar specify threshold parameter.
*
* White lines is contours/input points and the true ellipse used to generate the data.
* 1: Blue lines is fitting ellipses using openCV's original method.
* 2: Green lines is fitting ellipses using the AMS method.
* 3: Red lines is fitting ellipses using the Direct method.
*
*
* Original Author: Denis Burenkov
* AMS and Direct Methods Author: Jasper Shemilt
*
*
********************************************************************************/
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include <iostream>
using ;
;
{
:
;
:: ;
:: ;
,;
;
, ;
:: ;
( , ){
= ; = ;
= ::(,);
= ::(,);
= ;
= ;
= ;
= ;
}
(:: , :: ){
(){
(. < .){. = ()(. + );};
(. < .){. = ()(. + );};
(. > .){. = () .;};
(. > .){. = () .;};
} {
= ::(()., ().);
= ::(()(. + ), ()(. + ));
}
= ()(*((. + ) - .));
(<){
= * ()/();
} {
(>){
= * ()/();
}
}
= ()(*((. + ) - .));
(<){
= * ()/();
} {
(>){
= * ()/();
}
}
= ()(*((. + ) - .));
= ()(*((. + ) - .));
= ;
}
(<> )
{
:: = [];
:: = [];
( =; < .(); ++){
= [];
(. < .){. = .;};
(. < .){. = .;};
(. > .){. = .;};
(. > .){. = .;};
};
(, );
}
(:: )
{
:: = .;
:: = .;
:: [];
.();
( = ; < ; ++ ){
:: = [];
(. < .){. = .;};
(. < .){. = .;};
(. > .){. = .;};
(. > .){. = .;};
}
(, );
}
(:: , :: , )
{
(.()){
();
= ::::(,,);
}
. = * ::(.. - ., .. - .);
.. = ()( * ..);
.. = ()( * ..);
(, , , , );
[];
.();
( = ; < ; ++ ){
(, [], [(+)%], , , );
}
}
(<> , :: )
{
(.()){
();
= ::::(,,);
}
( =; < .(); ++){
= * ::([]. - ., []. - .);
.<::>((.), (.))[] = ()[];
.<::>((.), (.))[] = ()[];
.<::>((.), (.))[] = ()[];
};
}
( ::<::> , ::<::> )
{
(.()){
= ::::(,,);
}
= ;
( =; < .(); ++) {
:: = [];
:: = [];
= (, , , , );
+= ()( * .);
((. - .), );
::(, , , , , , , );
}
}
};
(** )
{
<<
<< [] << << ;
}
= ;
;
, , ;
:: = (, , );
:: = ( ,, );
:: = ( , ,);
:: = (,,);
(, *);
( , ** )
{
= ;
= ;
= ;
:: (, ,);
(.())
{
();
;
}
= .<>();
= (::(), );
( .() )
{
<< << << ;
;
}
(, );
(, );
( , , &, , );
(, );
();
;
}
( & ) {
(.. <= .. * ) && (.. > );
}
( , *)
{
, , ;
<<> > ;
= >= ;
(, , , );
;
.((*(., .)), (*(., .)));
.(::(.0f, .0f), ::(()(.+), ()(.+)));
::<::> ;
::<::> ;
() {
.();
.();
}
() {
.();
.();
}
() {
.();
.();
}
.(, );
= ;
< <> > ;
( = ; < .(); ++)
{
= [].();
( < )
;
;
([]).(, );
<>;
( = ; < .; ++) {
= (.<>(,), .<>(,));
((. > && . > && . < .- && . < .-)) {
(%==){
.();
}
}
}
.();
}
( = ; < .(); ++)
{
<> = [];
(.()<) {
;
}
() {
= ();
(()) {
.(, , );
}
}
() {
= ();
(()) {
.(, , );
}
}
() {
= ();
(()){
.(, , );
}
}
.(, );
}
(, .);
}