📄 cvsamplers.cpp
字号:
\
if( i < r.y || i >= r.height ) \
src2 -= src_step; \
\
for( j = 0; j < r.x; j++ ) \
{ \
worktype s0 = cast_macro(src[r.x])*b1 + \
cast_macro(src2[r.x])*b2; \
\
dst[j] = (dsttype)cast_macro2(s0); \
} \
\
for( ; j < r.width; j++ ) \
{ \
worktype s0 = cast_macro(src[j])*a11 + \
cast_macro(src[j+1])*a12 + \
cast_macro(src2[j])*a21 + \
cast_macro(src2[j+1])*a22; \
\
dst[j] = (dsttype)cast_macro2(s0); \
} \
\
for( ; j < win_size.width; j++ ) \
{ \
worktype s0 = cast_macro(src[r.width])*b1 + \
cast_macro(src2[r.width])*b2; \
\
dst[j] = (dsttype)cast_macro2(s0); \
} \
\
if( i < r.height ) \
src = src2; \
} \
} \
\
return CV_OK; \
}
#define ICV_DEF_GET_RECT_SUB_PIX_FUNC_C3( flavor, srctype, dsttype, worktype, \
cast_macro, scale_macro, mul_macro )\
static CvStatus CV_STDCALL icvGetRectSubPix_##flavor##_C3R \
( const srctype* src, int src_step, CvSize src_size, \
dsttype* dst, int dst_step, CvSize win_size, CvPoint2D32f center ) \
{ \
CvPoint ip; \
worktype a, b; \
int i, j; \
\
center.x -= (win_size.width-1)*0.5f; \
center.y -= (win_size.height-1)*0.5f; \
\
ip.x = cvFloor( center.x ); \
ip.y = cvFloor( center.y ); \
\
a = scale_macro( center.x - ip.x ); \
b = scale_macro( center.y - ip.y ); \
\
src_step /= sizeof( src[0] ); \
dst_step /= sizeof( dst[0] ); \
\
if( 0 <= ip.x && ip.x + win_size.width < src_size.width && \
0 <= ip.y && ip.y + win_size.height < src_size.height ) \
{ \
/* extracted rectangle is totally inside the image */ \
src += ip.y * src_step + ip.x*3; \
\
for( i = 0; i < win_size.height; i++, src += src_step, \
dst += dst_step ) \
{ \
for( j = 0; j < win_size.width; j++ ) \
{ \
worktype s0 = cast_macro(src[j*3]); \
worktype s1 = cast_macro(src[j*3 + src_step]); \
s0 += mul_macro( a, (cast_macro(src[j*3+3]) - s0)); \
s1 += mul_macro( a, (cast_macro(src[j*3+3+src_step]) - s1));\
dst[j*3] = (dsttype)(s0 + mul_macro( b, (s1 - s0))); \
\
s0 = cast_macro(src[j*3+1]); \
s1 = cast_macro(src[j*3+1 + src_step]); \
s0 += mul_macro( a, (cast_macro(src[j*3+4]) - s0)); \
s1 += mul_macro( a, (cast_macro(src[j*3+4+src_step]) - s1));\
dst[j*3+1] = (dsttype)(s0 + mul_macro( b, (s1 - s0))); \
\
s0 = cast_macro(src[j*3+2]); \
s1 = cast_macro(src[j*3+2 + src_step]); \
s0 += mul_macro( a, (cast_macro(src[j*3+5]) - s0)); \
s1 += mul_macro( a, (cast_macro(src[j*3+5+src_step]) - s1));\
dst[j*3+2] = (dsttype)(s0 + mul_macro( b, (s1 - s0))); \
} \
} \
} \
else \
{ \
CvRect r; \
\
src = (const srctype*)icvAdjustRect( src, src_step*sizeof(*src), \
sizeof(*src)*3, src_size, win_size, ip, &r ); \
\
for( i = 0; i < win_size.height; i++, dst += dst_step ) \
{ \
const srctype *src2 = src + src_step; \
\
if( i < r.y || i >= r.height ) \
src2 -= src_step; \
\
for( j = 0; j < r.x; j++ ) \
{ \
worktype s0 = cast_macro(src[r.x*3]); \
worktype s1 = cast_macro(src2[r.x*3]); \
dst[j*3] = (dsttype)(s0 + mul_macro( b, (s1 - s0))); \
\
s0 = cast_macro(src[r.x*3+1]); \
s1 = cast_macro(src2[r.x*3+1]); \
dst[j*3+1] = (dsttype)(s0 + mul_macro( b, (s1 - s0))); \
\
s0 = cast_macro(src[r.x*3+2]); \
s1 = cast_macro(src2[r.x*3+2]); \
dst[j*3+2] = (dsttype)(s0 + mul_macro( b, (s1 - s0))); \
} \
\
for( ; j < r.width; j++ ) \
{ \
worktype s0 = cast_macro(src[j*3]); \
worktype s1 = cast_macro(src2[j*3]); \
s0 += mul_macro( a, (cast_macro(src[j*3 + 3]) - s0)); \
s1 += mul_macro( a, (cast_macro(src2[j*3 + 3]) - s1)); \
dst[j*3] = (dsttype)(s0 + mul_macro( b, (s1 - s0))); \
\
s0 = cast_macro(src[j*3+1]); \
s1 = cast_macro(src2[j*3+1]); \
s0 += mul_macro( a, (cast_macro(src[j*3 + 4]) - s0)); \
s1 += mul_macro( a, (cast_macro(src2[j*3 + 4]) - s1)); \
dst[j*3+1] = (dsttype)(s0 + mul_macro( b, (s1 - s0))); \
\
s0 = cast_macro(src[j*3+2]); \
s1 = cast_macro(src2[j*3+2]); \
s0 += mul_macro( a, (cast_macro(src[j*3 + 5]) - s0)); \
s1 += mul_macro( a, (cast_macro(src2[j*3 + 5]) - s1)); \
dst[j*3+2] = (dsttype)(s0 + mul_macro( b, (s1 - s0))); \
} \
\
for( ; j < win_size.width; j++ ) \
{ \
worktype s0 = cast_macro(src[r.width*3]); \
worktype s1 = cast_macro(src2[r.width*3]); \
dst[j*3] = (dsttype)(s0 + mul_macro( b, (s1 - s0))); \
\
s0 = cast_macro(src[r.width*3+1]); \
s1 = cast_macro(src2[r.width*3+1]); \
dst[j*3+1] = (dsttype)(s0 + mul_macro( b, (s1 - s0))); \
\
s0 = cast_macro(src[r.width*3+2]); \
s1 = cast_macro(src2[r.width*3+2]); \
dst[j*3+2] = (dsttype)(s0 + mul_macro( b, (s1 - s0))); \
} \
\
if( i < r.height ) \
src = src2; \
} \
} \
\
return CV_OK; \
}
CvStatus CV_STDCALL icvGetRectSubPix_8u32f_C1R
( const uchar* src, int src_step, CvSize src_size,
float* dst, int dst_step, CvSize win_size, CvPoint2D32f center )
{
CvPoint ip;
float a12, a22, b1, b2;
float a, b;
double s = 0;
int i, j;
center.x -= (win_size.width-1)*0.5f;
center.y -= (win_size.height-1)*0.5f;
ip.x = cvFloor( center.x );
ip.y = cvFloor( center.y );
if( win_size.width <= 0 || win_size.height <= 0 )
return CV_BADRANGE_ERR;
a = center.x - ip.x;
b = center.y - ip.y;
a = MAX(a,0.0001f);
a12 = a*(1.f-b);
a22 = a*b;
b1 = 1.f - b;
b2 = b;
s = (1. - a)/a;
src_step /= sizeof(src[0]);
dst_step /= sizeof(dst[0]);
if( 0 <= ip.x && ip.x + win_size.width < src_size.width &&
0 <= ip.y && ip.y + win_size.height < src_size.height )
{
// extracted rectangle is totally inside the image
src += ip.y * src_step + ip.x;
#if 0
if( icvCopySubpix_8u32f_C1R_p &&
icvCopySubpix_8u32f_C1R_p( src, src_step, dst,
dst_step*sizeof(dst[0]), win_size, a, b ) >= 0 )
return CV_OK;
#endif
for( ; win_size.height--; src += src_step, dst += dst_step )
{
float prev = (1 - a)*(b1*CV_8TO32F(src[0]) + b2*CV_8TO32F(src[src_step]));
for( j = 0; j < win_size.width; j++ )
{
float t = a12*CV_8TO32F(src[j+1]) + a22*CV_8TO32F(src[j+1+src_step]);
dst[j] = prev + t;
prev = (float)(t*s);
}
}
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -