improved convergence of minEnclosingCircle algorithm, patch #947 (thanks to Hannes Sommer)
This commit is contained in:
parent
29077f11f8
commit
7a59d6c77e
@ -371,9 +371,11 @@ cvMinEnclosingCircle( const void* array, CvPoint2D32f * _center, float *_radius
|
|||||||
for( k = 0; k < max_iters; k++ )
|
for( k = 0; k < max_iters; k++ )
|
||||||
{
|
{
|
||||||
double min_delta = 0, delta;
|
double min_delta = 0, delta;
|
||||||
CvPoint2D32f ptfl;
|
CvPoint2D32f ptfl, farAway = { 0, 0};
|
||||||
|
/*only for first iteration because the alg is repared at the loop's foot*/
|
||||||
icvFindEnslosingCicle4pts_32f( pts, ¢er, &radius );
|
if(k==0)
|
||||||
|
icvFindEnslosingCicle4pts_32f( pts, ¢er, &radius );
|
||||||
|
|
||||||
cvStartReadSeq( sequence, &reader, 0 );
|
cvStartReadSeq( sequence, &reader, 0 );
|
||||||
|
|
||||||
for( i = 0; i < count; i++ )
|
for( i = 0; i < count; i++ )
|
||||||
@ -393,12 +395,29 @@ cvMinEnclosingCircle( const void* array, CvPoint2D32f * _center, float *_radius
|
|||||||
if( delta < min_delta )
|
if( delta < min_delta )
|
||||||
{
|
{
|
||||||
min_delta = delta;
|
min_delta = delta;
|
||||||
pts[3] = ptfl;
|
farAway = ptfl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = min_delta >= 0;
|
result = min_delta >= 0;
|
||||||
if( result )
|
if( result )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
CvPoint2D32f ptsCopy[4];
|
||||||
|
/* find good replacement partner for the point which is at most far away,
|
||||||
|
starting with the one that lays in the actual circle (i=3) */
|
||||||
|
for(int i = 3; i >=0; i-- )
|
||||||
|
{
|
||||||
|
for(int j = 0; j < 4; j++ )
|
||||||
|
{
|
||||||
|
ptsCopy[j]=(i != j)? pts[j]: farAway;
|
||||||
|
}
|
||||||
|
|
||||||
|
icvFindEnslosingCicle4pts_32f(ptsCopy, ¢er, &radius );
|
||||||
|
if( icvIsPtInCircle( pts[i], center, radius )>=0){ // replaced one again in the new circle?
|
||||||
|
pts[i] = farAway;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !result )
|
if( !result )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user