rewritten floodfill in generic style; added CV_32S flavor (ticket #1482)

pull/13383/head
Vadim Pisarevsky 13 years ago
parent 554e0051e8
commit 0b234b7a69
  1. 984
      modules/imgproc/src/floodfill.cpp
  2. 33
      modules/imgproc/test/test_floodfill.cpp

File diff suppressed because it is too large Load Diff

@ -97,8 +97,8 @@ void CV_FloodFillTest::get_test_array_types_and_sizes( int test_case_idx,
double buf[8]; double buf[8];
cvtest::ArrayTest::get_test_array_types_and_sizes( test_case_idx, sizes, types ); cvtest::ArrayTest::get_test_array_types_and_sizes( test_case_idx, sizes, types );
depth = cvtest::randInt(rng) % 2; depth = cvtest::randInt(rng) % 3;
depth = depth == 0 ? CV_8U : CV_32F; depth = depth == 0 ? CV_8U : depth == 1 ? CV_32S : CV_32F;
cn = cvtest::randInt(rng) & 1 ? 3 : 1; cn = cvtest::randInt(rng) & 1 ? 3 : 1;
use_mask = (cvtest::randInt(rng) & 1) != 0; use_mask = (cvtest::randInt(rng) & 1) != 0;
@ -256,7 +256,7 @@ cvTsFloodFill( CvMat* _img, CvPoint seed_pt, CvScalar new_val,
int u0 = 0, u1 = 0, u2 = 0; int u0 = 0, u1 = 0, u2 = 0;
double s0 = 0, s1 = 0, s2 = 0; double s0 = 0, s1 = 0, s2 = 0;
if( CV_MAT_DEPTH(_img->type) == CV_8U ) if( CV_MAT_DEPTH(_img->type) == CV_8U || CV_MAT_DEPTH(_img->type) == CV_32S )
{ {
tmp = cvCreateMat( rows, cols, CV_MAKETYPE(CV_32F,CV_MAT_CN(_img->type)) ); tmp = cvCreateMat( rows, cols, CV_MAKETYPE(CV_32F,CV_MAT_CN(_img->type)) );
cvTsConvert(_img, tmp); cvTsConvert(_img, tmp);
@ -428,7 +428,6 @@ cvTsFloodFill( CvMat* _img, CvPoint seed_pt, CvScalar new_val,
float* ptr = img + i*step; float* ptr = img + i*step;
ushort* mptr = m + i*mstep; ushort* mptr = m + i*mstep;
uchar* dmptr = _mask ? _mask->data.ptr + (i+1)*_mask->step + 1 : 0; uchar* dmptr = _mask ? _mask->data.ptr + (i+1)*_mask->step + 1 : 0;
uchar* dptr = tmp != _img ? _img->data.ptr + i*_img->step : 0;
double area0 = area; double area0 = area;
for( j = 0; j < cols; j++ ) for( j = 0; j < cols; j++ )
@ -440,26 +439,12 @@ cvTsFloodFill( CvMat* _img, CvPoint seed_pt, CvScalar new_val,
if( !mask_only ) if( !mask_only )
{ {
if( cn == 1 ) if( cn == 1 )
{ ptr[j] = (float)s0;
if( dptr )
dptr[j] = (uchar)u0;
else
ptr[j] = (float)s0;
}
else else
{ {
if( dptr ) ptr[j*3] = (float)s0;
{ ptr[j*3+1] = (float)s1;
dptr[j*3] = (uchar)u0; ptr[j*3+2] = (float)s2;
dptr[j*3+1] = (uchar)u1;
dptr[j*3+2] = (uchar)u2;
}
else
{
ptr[j*3] = (float)s0;
ptr[j*3+1] = (float)s1;
ptr[j*3+2] = (float)s2;
}
} }
} }
else else
@ -494,7 +479,11 @@ cvTsFloodFill( CvMat* _img, CvPoint seed_pt, CvScalar new_val,
_exit_: _exit_:
cvReleaseMat( &mask ); cvReleaseMat( &mask );
if( tmp != _img ) if( tmp != _img )
{
if( !mask_only )
cvTsConvert(tmp, _img);
cvReleaseMat( &tmp ); cvReleaseMat( &tmp );
}
comp[0] = area; comp[0] = area;
comp[1] = r.x; comp[1] = r.x;

Loading…
Cancel
Save