📄 afloodfill8.cpp
字号:
}
ij1=ij-step;
if((j>0) && (!b[ijb-nx]) && (pImage[ij1]>=q1) && (pImage[ij1]<=q2))
{
mNew++;
b[ijb-nx]++;
}
ij1=ij+step;
if((j<ny1) && (!b[ijb+nx]) && (pImage[ij1]>=q1) && (pImage[ij1]<=q2))
{
mNew++;
b[ijb+nx]++;
}
/*------------------------- */
ij1=ij-step-1;
if((i>0)&&(j>0))
if((!b[ijb-nx-1])&&(pImage[ij1]>=q1)&&(pImage[ij1]<=q2))
{
mNew++;
b[ijb-nx-1]++;
}
ij1=ij-step+1;
if((i<nx1)&&(j>0))
if((!b[ijb-nx+1])&&(pImage[ij1]>=q1)&&(pImage[ij1]<=q2))
{
mNew++;
b[ijb-nx+1]++;
}
ij1=ij+step-1;
if((i>0)&&(j<ny1))
if((!b[ijb+nx-1])&&(pImage[ij1]>=q1)&&(pImage[ij1]<=q2))
{
mNew++;
b[ijb+nx-1]++;
}
ij1=ij+step+1;
if((i<nx1)&&(j<ny1))
if((!b[ijb+nx+1])&&(pImage[ij1]>=q1)&&(pImage[ij1]<=q2))
{
mNew++;
b[ijb+nx+1]++;
}
/*------------------------- */
} /* i */
} /* j */
} while(mNew);
icvFree((void**)&b);
return CV_NO_ERR;
} /* _ipcvFloodFill32fC1R_slow8 */
/*=================================================== Test body ========================== */
static int fmaFloodFill8( void )
{
/* Some Variables */
int nx, ny, stepX, stepY, numTest, ROI_offset, mp=0, mp4=0;
int i, j, k, ij, it, n, n4, ov, d1, d2, ntest2, nerr=0;
int step, step4;
uchar *pI0, *pI1, *pI2;
float* pI3, *pI4;
IplImage *I0, *I1, *I2, *I3, *I4;
CvSize size;
CvPoint seed;
CvConnectedComp Comp;
CvStatus r;
/* Reading test parameters */
trsiRead( &nx, "64", "Image width" );
trsiRead( &stepX, "16", "Seed point horizontal step" );
trsiRead( &numTest, "32", "Number of each seed point tests" );
trsiRead( &ROI_offset, "0", "ROI offset" );
ny = nx;
stepY = stepX;
n = nx*ny;
ntest2 = numTest/2;
size.width = nx;
size.height = ny;
I0 = cvCreateImage( size, IPL_DEPTH_8U, 1 );
I1 = cvCreateImage( size, IPL_DEPTH_8U, 1 );
I2 = cvCreateImage( size, IPL_DEPTH_8U, 1 );
I3 = cvCreateImage( size, IPL_DEPTH_32F,1 );
I4 = cvCreateImage( size, IPL_DEPTH_32F,1 );
pI0 = (uchar*)I0->imageData;
pI1 = (uchar*)I1->imageData;
pI2 = (uchar*)I2->imageData;
pI3 = (float*)I3->imageData;
pI4 = (float*)I4->imageData;
step = I1->widthStep; step4 = I3->widthStep;
n = step*ny; n4 = (step4/4)*ny;
if(ROI_offset)
{
mp = ROI_offset + ROI_offset*step;
mp4= ROI_offset + ROI_offset*step4;
size.width = nx - 2*ROI_offset;
size.height = ny - 2*ROI_offset;
I1->roi->xOffset = I1->roi->yOffset = ROI_offset;
I1->roi->height = size.height; I1->roi->width = size.width;
I3->roi->xOffset = I3->roi->yOffset = ROI_offset;
I3->roi->height = size.height; I3->roi->width = size.width;
}
/* T E S T I N G */
/* Zero interval */
d1 = d2 = 0;
ats1bInitRandom ( 0, 1.5, pI0, n );
/*for(i=0;i<n;i++)printf(" %d",pI0[i]);getchar(); */
for(j=0; j<size.height; j=j+stepY)
{
seed.y = j;
for(i=0; i<size.width; i=i+stepX)
{
seed.x = i;
for(k=0; k<n; k++) pI1[k]=pI2[k]=pI0[k];
for(k=0; k<n4; k++) pI3[k]=pI4[k]=(float)pI0[k];
/* 8U */
Counter8 = 0; X1 = X2 = i; Y1 = Y2 = j;
/* Run CVL function */
cvFloodFill ( I1, seed, 10.0, (double)d1, (double)d2, &Comp, 8 );
/* Run test function */
r = _cvFloodFill8uC1R_slow8 (pI2+mp, step, size, seed, 10, d1, d2 );
/* Comparison */
for(k=0; k<n; k++) if( (pI1[k]-pI2[k]) ) nerr++;
if( Comp.area!=Counter8 ) nerr++;
if(X1!=Comp.rect.x) nerr++;
if(Y1!=Comp.rect.y) nerr++;
if((X2-X1+1)!=Comp.rect.width) nerr++;
if((Y2-Y1+1)!=Comp.rect.height) nerr++;
/* 32F */
Counter8 = 0; X1 = X2 = i; Y1 = Y2 = j;
/* Run CVL function */
cvFloodFill ( I3, seed, 10.0, (double)d1, (double)d2, &Comp, 8 );
/* Run test function */
r = _cvFloodFill32fC1R_slow8 (pI4+mp4, step4, size, seed, 10.0, (float)d1, (float)d2 );
/* Comparison */
for(k=0; k<n4; k++) if( (pI3[k]-pI4[k]) ) nerr++;
if( Comp.area!=Counter8 ) nerr++;
if(X1!=Comp.rect.x) nerr++;
if(Y1!=Comp.rect.y) nerr++;
if((X2-X1+1)!=Comp.rect.width) nerr++;
if((Y2-Y1+1)!=Comp.rect.height) nerr++;
if( nerr != 0 )
break;
}
}
/* Non-zero interval */
ats1bInitRandom ( 0, 254.99, pI0, n );
for(j=1; j<size.height; j=j+stepY)
{
seed.y = j;
for(i=1; i<size.width; i=i+stepX)
{
ij=i+step*j; ov=pI0[ij+mp];
seed.x = i;
for(it=0; it<numTest; it++)
{
for(k=0; k<n; k++) pI1[k]=pI2[k]=pI0[k];
for(k=0; k<n4; k++) pI3[k]=pI4[k]=(float)pI0[k];
if(it<ntest2) /* sequential increase interval */
{ d1=(ov*(it+1))/ntest2; d2=((255-ov)*(it+1))/ntest2; }
else /* random interval */
{
d1 = (int)atsInitRandom(1.0, 127);
d2 = (int)atsInitRandom(1.0, 127);
if(it>(3*numTest)/4){d1/=2; d2/=2;}
}
/* 8U */
Counter8 = 0; X1 = X2 = i; Y1 = Y2 = j;
/* Run CVL function */
cvFloodFill ( I1, seed, 255.0, (double)d1, (double)d2, &Comp, 8 );
/* Run test function */
r = _cvFloodFill8uC1R_slow8 (pI2+mp, step, size, seed, 255, d1, d2 );
/* Comparison */
for(k=0; k<n; k++) if( (pI1[k]-pI2[k]) ) nerr++;
if( Comp.area!=Counter8 ) nerr++;
if(X1!=Comp.rect.x) nerr++;
if(Y1!=Comp.rect.y) nerr++;
if((X2-X1+1)!=Comp.rect.width) nerr++;
if((Y2-Y1+1)!=Comp.rect.height) nerr++;
/* 32F */
Counter8 = 0; X1 = X2 = i; Y1 = Y2 = j;
/* Run CVL function */
cvFloodFill ( I3, seed, 255.0, (double)d1, (double)d2, &Comp, 8 );
/* Run test function */
r = _cvFloodFill32fC1R_slow8 (pI4+mp4, step4, size, seed, 255.0, (float)d1, (float)d2 );
/* Comparison */
for(k=0; k<n4; k++) if( (pI3[k]-pI4[k]) ) nerr++;
if( Comp.area!=Counter8 ) nerr++;
if(X1!=Comp.rect.x) nerr++;
if(Y1!=Comp.rect.y) nerr++;
if((X2-X1+1)!=Comp.rect.width) nerr++;
if((Y2-Y1+1)!=Comp.rect.height) nerr++;
if( nerr != 0 )
break;
}
}
trsWrite(TW_RUN|TW_CON, " %d%% ", ((j+stepY)*100)/size.height);
}
cvReleaseImage( &I0 );
cvReleaseImage( &I1 );
cvReleaseImage( &I2 );
cvReleaseImage( &I3 );
cvReleaseImage( &I4 );
trsWrite(TW_RUN|TW_CON|TW_SUM, " Nerr = %d\n", nerr);
if( nerr == 0 ) return trsResult( TRS_OK, "No errors fixed by this test" );
else return trsResult( TRS_FAIL, "Total fixed %d errors", nerr );
} /*fma*/
/*------------------------------------------------ Initialize function ------------------- */
void InitAFloodFill8( void )
{
trsReg( FuncName, TestName, TestClass, fmaFloodFill8 );
} /* InitAFloodFill8 */
/* End of file. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -