cvderiv.cpp.svn-base
来自「非结构化路识别」· SVN-BASE 代码 · 共 1,921 行 · 第 1/5 页
SVN-BASE
1,921 行
break;
tdst2 = dst;
trow = rows[ker_y];
if( ker_height > 1 )
{
if( width_rest )
{
need_copy = width < CV_MORPH_ALIGN || y == dst_height - 1;
if( need_copy )
tdst2 = tbufw;
else
CV_COPY( tbufw + width, dst + width, CV_MORPH_ALIGN, x );
}
if( y_asymm )
{
if( y_type == ICV_m1_0_1_KERNEL )
{
int *trow1 = rows[origin*2], *trow2 = rows[(origin^1)*2];
for( x = 0; x < width; x += CV_MORPH_ALIGN )
{
int val0, val1;
val0 = trow2[x] - trow1[x];
val1 = trow2[x + 1] - trow1[x + 1];
tdst2[x + 0] = (short)val0;
tdst2[x + 1] = (short)val1;
val0 = trow2[x + 2] - trow1[x + 2];
val1 = trow2[x + 3] - trow1[x + 3];
tdst2[x + 2] = (short)val0;
tdst2[x + 3] = (short)val1;
}
}
else
{
for( x = 0; x < width; x += CV_MORPH_ALIGN )
{
int val0, val1, val2, val3;
val0 = trow[x]*fmY0;
val1 = trow[x + 1]*fmY0;
val2 = trow[x + 2]*fmY0;
val3 = trow[x + 3]*fmY0;
for( i = 1; i <= ker_y; i++ )
{
int *trow1, *trow2;
int m = fmaskY[i];
trow1 = rows[ker_y - i];
trow2 = rows[ker_y + i];
val0 += (trow2[x] - trow1[x])*m;
val1 += (trow2[x+1] - trow1[x+1])*m;
val2 += (trow2[x+2] - trow1[x+2])*m;
val3 += (trow2[x+3] - trow1[x+3])*m;
}
tdst2[x + 0] = CV_CAST_16S(val0);
tdst2[x + 1] = CV_CAST_16S(val1);
tdst2[x + 2] = CV_CAST_16S(val2);
tdst2[x + 3] = CV_CAST_16S(val3);
}
}
}
else
{
if( y_type == ICV_1_2_1_KERNEL )
{
int *trow1 = rows[0], *trow2 = rows[2];
for( x = 0; x < width; x += CV_MORPH_ALIGN )
{
int val0, val1;
val0 = trow[x]*2 + trow1[x] + trow2[x];
val1 = trow[x + 1]*2 + trow1[x+1] + trow2[x+1];
tdst2[x + 0] = (short)val0;
tdst2[x + 1] = (short)val1;
val0 = trow[x + 2]*2 + trow1[x+2] + trow2[x+2];
val1 = trow[x + 3]*2 + trow1[x+3] + trow2[x+3];
tdst2[x + 2] = (short)val0;
tdst2[x + 3] = (short)val1;
}
}
else if( y_type == ICV_3_10_3_KERNEL )
{
int *trow1 = rows[0], *trow2 = rows[2];
for( x = 0; x < width; x += CV_MORPH_ALIGN )
{
int val0, val1;
val0 = trow[x]*10 + (trow1[x] + trow2[x])*3;
val1 = trow[x + 1]*10 + (trow1[x+1] + trow2[x+1])*3;
tdst2[x + 0] = (short)val0;
tdst2[x + 1] = (short)val1;
val0 = trow[x + 2]*10 + (trow1[x+2] + trow2[x+2])*3;
val1 = trow[x + 3]*10 + (trow1[x+3] + trow2[x+3])*3;
tdst2[x + 2] = (short)val0;
tdst2[x + 3] = (short)val1;
}
}
else
{
for( x = 0; x < width; x += CV_MORPH_ALIGN )
{
int val0, val1, val2, val3;
val0 = trow[x]*fmY0;
val1 = trow[x + 1]*fmY0;
val2 = trow[x + 2]*fmY0;
val3 = trow[x + 3]*fmY0;
for( i = 1; i <= ker_y; i++ )
{
int *trow1, *trow2;
int m = fmaskY[i];
trow1 = rows[ker_y - i];
trow2 = rows[ker_y + i];
val0 += (trow2[x] + trow1[x])*m;
val1 += (trow2[x+1] + trow1[x+1])*m;
val2 += (trow2[x+2] + trow1[x+2])*m;
val3 += (trow2[x+3] + trow1[x+3])*m;
}
tdst2[x + 0] = CV_CAST_16S(val0);
tdst2[x + 1] = CV_CAST_16S(val1);
tdst2[x + 2] = CV_CAST_16S(val2);
tdst2[x + 3] = CV_CAST_16S(val3);
}
}
}
if( width_rest )
{
if( need_copy )
CV_COPY( dst, tbufw, width, x );
else
CV_COPY( dst + width, tbufw + width, CV_MORPH_ALIGN, x );
}
}
else
{
for( x = 0; x < width; x++ )
dst[x] = (short)trow[x];
}
rows[ker_y] = saved_row;
/* rotate buffer */
{
int *t = rows[0];
CV_COPY( rows, rows + 1, ker_height - 1, i );
rows[i] = t;
crows--;
dst += dstStep;
}
}
while( ++y < dst_height );
roiSize->height = y;
state->crows = crows;
return CV_OK;
}
IPCVAPI_IMPL( CvStatus, icvSobel_8s16s_C1R,(
const char* pSrc, int srcStep,
short* dst, int dstStep, CvSize* roiSize,
CvFilterState* state, int stage ))
{
char* src = (char*)pSrc;
int width = roiSize->width;
int src_height = roiSize->height;
int dst_height = src_height;
int x, y = 0, i;
int ker_width = state->ker_width;
int ker_height = state->ker_height;
int ker_x = ker_width/2;
int ker_y = ker_height/2;
int ker_right = ker_width - ker_x;
int crows = state->crows;
int **rows = (int**)(state->rows);
short *tbufw = (short*)(state->tbuf);
int *trow = 0;
int* fmaskX = (int*)(state->ker0) + ker_x;
int* fmaskY = (int*)(state->ker1) + ker_y;
int fmX0 = fmaskX[0], fmY0 = fmaskY[0];
int is_small_width = width < MAX( ker_x, ker_right );
int starting_flag = 0;
int width_rest = width & (CV_MORPH_ALIGN - 1);
int origin = state->origin;
int x_type = ICV_X_KERNEL_TYPE(state->kerType),
y_type = ICV_Y_KERNEL_TYPE(state->kerType);
int x_asymm = (x_type & 3) - 1, /* <0 - general kind (not used),
0-symmetric, 1-asymmetric*/
y_asymm = (y_type & 3) - 1;
/* initialize cyclic buffer when starting */
if( stage == CV_WHOLE || stage == CV_START )
{
for( i = 0; i < ker_height; i++ )
rows[i] = (int*)(state->buffer + state->buffer_step * i);
crows = ker_y;
if( stage != CV_WHOLE )
dst_height -= ker_height - ker_y - 1;
starting_flag = 1;
}
if( stage == CV_END )
dst_height += ker_height - ker_y - 1;
dstStep /= sizeof(dst[0]);
do
{
int need_copy = is_small_width | (y == 0);
char *tsrc;
int *tdst;
short *tdst2;
int *saved_row = rows[ker_y];
/* fill cyclic buffer - horizontal filtering */
for( ; crows < ker_height; crows++ )
{
tsrc = src - ker_x;
tdst = rows[crows];
if( src_height-- <= 0 )
{
if( stage != CV_WHOLE && stage != CV_END )
break;
/* duplicate last row */
trow = rows[crows - 1];
CV_COPY( tdst, trow, width, x );
continue;
}
need_copy |= src_height == 1;
if( ker_width > 1 )
{
char* tbufc = (char*)tbufw;
if( need_copy )
{
tsrc = tbufc - ker_x;
CV_COPY( tbufc, src, width, x );
}
else
{
CV_COPY( tbufc - ker_x, src - ker_x, ker_x, x );
CV_COPY( tbufc, src + width, ker_right, x );
}
/* make replication borders */
{
char pix = tsrc[ker_x];
CV_SET( tsrc, pix, ker_x, x );
pix = tsrc[width + ker_x - 1];
CV_SET( tsrc + width + ker_x, pix, ker_right, x );
}
if( x_asymm )
{
/* horizontal filter: asymmetric case */
if( x_type == ICV_m1_0_1_KERNEL )
{
for( i = 0; i < width; i++ )
tdst[i] = tsrc[i+2] - tsrc[i];
}
else
{
for( i = 0; i < width; i++ )
{
int j;
int t0 = tsrc[i + ker_x]*fmX0;
for( j = 1; j <= ker_x; j++ )
t0 += (tsrc[i+ker_x+j] - tsrc[i+ker_x-j])*fmaskX[j];
tdst[i] = t0;
}
}
}
else
{
if( x_type == ICV_1_2_1_KERNEL )
{
for( i = 0; i < width; i++ )
tdst[i] = tsrc[i+1]*2 + tsrc[i] + tsrc[i+2];
}
else if( x_type == ICV_3_10_3_KERNEL )
{
for( i = 0; i < width; i++ )
tdst[i] = tsrc[i+1]*10 + (tsrc[i] + tsrc[i+2])*3;
}
else
{
/* horizontal filter: symmetric case */
for( i = 0; i < width; i++ )
{
int j;
int t0 = tsrc[i + ker_x]*fmX0;
for( j = 1; j <= ker_x; j++ )
t0 += (tsrc[i+ker_x+j] + tsrc[i+ker_x-j])*fmaskX[j];
tdst[i] = t0;
}
}
}
if( !need_copy )
{
/* restore borders */
CV_COPY( src - ker_x, tbufc - ker_x, ker_x, x );
CV_COPY( src + width, tbufc, ker_right, x );
}
}
else
{
CV_COPY( tdst, tsrc + ker_x, width, x );
}
if( crows < ker_height )
src += srcStep;
}
if( starting_flag )
{
starting_flag = 0;
trow = rows[ker_y];
for( i = 0; i < ker_y; i++ )
{
tdst = rows[i];
CV_COPY( tdst, trow, width, x );
}
}
/* vertical convolution */
if( crows != ker_height )
break;
tdst2 = dst;
trow = rows[ker_y];
if( ker_height > 1 )
{
if( width_rest )
{
need_copy = width < CV_MORPH_ALIGN || y == dst_height - 1;
if( need_copy )
tdst2 = tbufw;
else
CV_COPY( tbufw + width, dst + width, CV_MORPH_ALIGN, x );
}
if( y_asymm )
{
if( y_type == ICV_m1_0_1_KERNEL )
{
int *trow1 = rows[origin*2], *trow2 = rows[(origin^1)*2];
for( x = 0; x < width; x += CV_MORPH_ALIGN )
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?