842 |
842 |
acols = accum->cols - 2;
|
843 |
843 |
adata = accum->data.i;
|
844 |
844 |
astep = accum->step/sizeof(adata[0]);
|
845 |
|
|
|
845 |
// Accumulate circle evidence for each edge pixel
|
846 |
846 |
for( y = 0; y < rows; y++ )
|
847 |
847 |
{
|
848 |
848 |
const uchar* edges_row = edges->data.ptr + y*edges->step;
|
... | ... | |
868 |
868 |
|
869 |
869 |
x0 = cvRound((x*idp)*ONE);
|
870 |
870 |
y0 = cvRound((y*idp)*ONE);
|
871 |
|
|
|
871 |
// Step from min_radius to max_radius in both directions of the gradient
|
872 |
872 |
for( k = 0; k < 2; k++ )
|
873 |
873 |
{
|
874 |
874 |
x1 = x0 + min_radius * sx;
|
... | ... | |
894 |
894 |
nz_count = nz->total;
|
895 |
895 |
if( !nz_count )
|
896 |
896 |
return;
|
897 |
|
|
|
897 |
//Find possible circle centers
|
898 |
898 |
for( y = 1; y < arows - 1; y++ )
|
899 |
899 |
{
|
900 |
900 |
for( x = 1; x < acols - 1; x++ )
|
... | ... | |
924 |
924 |
dr = dp;
|
925 |
925 |
min_dist = MAX( min_dist, dp );
|
926 |
926 |
min_dist *= min_dist;
|
927 |
|
|
|
927 |
// For each found possible center
|
|
928 |
// Estimate radius and check support
|
928 |
929 |
for( i = 0; i < centers->total; i++ )
|
929 |
930 |
{
|
930 |
931 |
int ofs = *(int*)cvGetSeqElem( centers, i );
|
931 |
|
y = ofs/(acols+2) - 1;
|
932 |
|
x = ofs - (y+1)*(acols+2) - 1;
|
933 |
|
float cx = (float)(x*dp), cy = (float)(y*dp);
|
|
932 |
y = ofs/(acols+2);
|
|
933 |
x = ofs - (y)*(acols+2);
|
|
934 |
//Calculate circle's center in pixels
|
|
935 |
float cx = (float)((x + 0.5f)*dp), cy = (float)(( y + 0.5f )*dp);
|
934 |
936 |
float start_dist, dist_sum;
|
935 |
937 |
float r_best = 0, c[3];
|
936 |
|
int max_count = R_THRESH;
|
937 |
|
|
|
938 |
int max_count = 0;
|
|
939 |
// Check distance with previously detected circles
|
938 |
940 |
for( j = 0; j < circles->total; j++ )
|
939 |
941 |
{
|
940 |
942 |
float* c = (float*)cvGetSeqElem( circles, j );
|
... | ... | |
944 |
946 |
|
945 |
947 |
if( j < circles->total )
|
946 |
948 |
continue;
|
947 |
|
|
|
949 |
// Estimate best radius
|
948 |
950 |
cvStartReadSeq( nz, &reader );
|
949 |
951 |
for( j = k = 0; j < nz_count; j++ )
|
950 |
952 |
{
|
... | ... | |
991 |
993 |
}
|
992 |
994 |
dist_sum += d;
|
993 |
995 |
}
|
994 |
|
|
995 |
|
if( max_count > R_THRESH )
|
|
996 |
// Check if the circle has enough support
|
|
997 |
if( max_count > acc_threshold )
|
996 |
998 |
{
|
997 |
999 |
c[0] = cx;
|
998 |
1000 |
c[1] = cy;
|