cvsamplers.cpp.svn-base
来自「非结构化路识别」· SVN-BASE 代码 · 共 1,027 行 · 第 1/4 页
SVN-BASE
1,027 行
} \
\
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; \
}
#define ICV_SHIFT 16
#define ICV_SCALE(x) cvRound((x)*(1 << ICV_SHIFT))
#define ICV_MUL_SCALE(x,y) (((x)*(y) + (1 << (ICV_SHIFT-1))) >> ICV_SHIFT)
#define ICV_DESCALE(x) (((x)+(1 << (ICV_SHIFT-1))) >> ICV_SHIFT)
ICV_DEF_GET_RECT_SUB_PIX_FUNC( 8u, uchar, uchar, int, CV_NOP, ICV_SCALE, ICV_DESCALE )
ICV_DEF_GET_RECT_SUB_PIX_FUNC( 32f, float, float, float, CV_NOP, CV_NOP, CV_NOP )
ICV_DEF_GET_RECT_SUB_PIX_FUNC( 8u32f, uchar, float, float, CV_8TO32F, CV_NOP, CV_NOP )
ICV_DEF_GET_RECT_SUB_PIX_FUNC_C3( 8u, uchar, uchar, int, CV_NOP, ICV_SCALE, ICV_MUL_SCALE )
ICV_DEF_GET_RECT_SUB_PIX_FUNC_C3( 32f, float, float, float, CV_NOP, CV_NOP, CV_MUL )
ICV_DEF_GET_RECT_SUB_PIX_FUNC_C3( 8u32f, uchar, float, float, CV_8TO32F, CV_NOP, CV_MUL )
#define ICV_DEF_INIT_SUBPIX_TAB( FUNCNAME, FLAG ) \
static void icvInit##FUNCNAME##FLAG##Table( CvFuncTable* tab ) \
{ \
tab->fn_2d[CV_8U] = (void*)icv##FUNCNAME##_8u_##FLAG; \
tab->fn_2d[CV_32F] = (void*)icv##FUNCNAME##_32f_##FLAG; \
\
tab->fn_2d[1] = (void*)icv##FUNCNAME##_8u32f_##FLAG; \
}
ICV_DEF_INIT_SUBPIX_TAB( GetRectSubPix, C1R )
ICV_DEF_INIT_SUBPIX_TAB( GetRectSubPix, C3R )
typedef CvStatus (CV_STDCALL *CvGetRectSubPixFunc)( const void* src, int src_step,
CvSize src_size, void* dst,
int dst_step, CvSize win_size,
CvPoint2D32f center );
CV_IMPL void
cvGetRectSubPix( const void* srcarr, void* dstarr, CvPoint2D32f center )
{
static CvFuncTable gr_tab[2];
static int inittab = 0;
CV_FUNCNAME( "cvGetRectSubPix" );
__BEGIN__;
CvMat srcstub, *src = (CvMat*)srcarr;
CvMat dststub, *dst = (CvMat*)dstarr;
CvSize src_size, dst_size;
CvGetRectSubPixFunc func;
int cn;
if( !inittab )
{
icvInitGetRectSubPixC1RTable( gr_tab + 0 );
icvInitGetRectSubPixC3RTable( gr_tab + 1 );
inittab = 1;
}
if( !CV_IS_MAT(src))
CV_CALL( src = cvGetMat( src, &srcstub ));
if( !CV_IS_MAT(dst))
CV_CALL( dst = cvGetMat( dst, &dststub ));
cn = CV_MAT_CN( src->type );
if( (cn != 1 && cn != 3) || !CV_ARE_CNS_EQ( src, dst ))
CV_ERROR( CV_StsUnsupportedFormat, "" );
src_size = icvGetMatSize( src );
dst_size = icvGetMatSize( dst );
if( dst_size.width > src_size.width || dst_size.height > src_size.height )
CV_ERROR( CV_StsBadSize, "destination ROI must be smaller than source ROI" );
if( CV_ARE_DEPTHS_EQ( src, dst ))
{
func = (CvGetRectSubPixFunc)(gr_tab[cn != 1].fn_2d[CV_MAT_DEPTH(src->type)]);
}
else
{
if( CV_MAT_DEPTH( src->type ) != CV_8U || CV_MAT_DEPTH( dst->type ) != CV_32F )
CV_ERROR( CV_StsUnsupportedFormat, "" );
func = (CvGetRectSubPixFunc)(gr_tab[cn != 1].fn_2d[1]);
}
if( !func )
CV_ERROR( CV_StsUnsupportedFormat, "" );
IPPI_CALL( func( src->data.ptr, src->step, src_size,
dst->data.ptr, dst->step, dst_size, center ));
__END__;
}
#define GET_X(X,Y) ((X)*A11 + (Y)*A12 + b1)
#define GET_Y(X,Y) ((X)*A21 + (Y)*A22 + b2)
#define PTR_AT(X,Y) (src + (Y)*srcStep + (X))
#define CLIP_X(x) (unsigned)(x) < (unsigned)src_size.width ? \
(x) : (x) < 0 ? 0 : src_size.width - 1
#define CLIP_Y(y) (unsigned)(y) < (unsigned)src_size.height ? \
(y) : (y) < 0 ? 0 : src_size.height - 1
#define ICV_DEF_GET_QUADRANGLE_SUB_PIX_FUNC( flavor, srctype, dsttype, \
worktype, cast_macro, cvt ) \
IPCVAPI_IMPL( CvStatus, icvGetQuadrangleSubPix_##flavor##_C1R, \
( const srctype * src, int srcStep, CvSize src_size, \
dsttype *dst, int dstStep, CvSize win_size, \
const float *matrix, int fill_outliers, \
dsttype* fillval )) \
{ \
int x, y, x0, y0, x1, y1; \
float A11 = matrix[0], A12 = matrix[1], b1 = matrix[2]; \
float A21 = matrix[3], A22 = matrix[4], b2 = matrix[5]; \
dsttype fv = *fillval; \
int left = -(win_size.width >> 1), right = win_size.width + left - 1; \
int top = -(win_size.height >> 1), bottom = win_size.height + top - 1; \
\
srcStep /= sizeof(srctype); \
dstStep /= sizeof(dsttype); \
\
dst -= left; \
\
for( y = top; y <= bottom; y++, dst += dstStep ) \
{ \
float xs = GET_X( left, y ); \
float ys = GET_Y( left, y ); \
float xe = GET_X( right, y ); \
float ye = GET_Y( right, y ); \
\
if( (unsigned)cvFloor(xs) < (unsigned)(src_size.width - 1) && \
(unsigned)cvFloor(ys) < (unsigned)(src_size.height - 1) && \
(unsigned)cvFloor(xe) < (unsigned)(src_size.width - 1) && \
(unsigned)cvFloor(ye) < (unsigned)(src_size.height - 1)) \
{ \
for( x = left; x <= right; x++ ) \
{ \
worktype p0, p1; \
float a, b; \
\
int ixs = cvFloor( xs ); \
int iys = cvFloor( ys ); \
const srctype *ptr = PTR_AT( ixs, iys ); \
\
a = xs - ixs; \
b = ys - iys; \
\
xs += A11; \
ys += A21; \
\
p0 = cvt(ptr[0]) + a * (cvt(ptr[1]) - cvt(ptr[0])); \
p1 = cvt(ptr[srcStep]) + a * (cvt(ptr[srcStep + 1]) - \
cvt(ptr[srcStep])); \
dst[x] = cast_macro(p0 + b * (p1 - p0)); \
} \
} \
else \
{ \
for( x = left; x <= right; x++ ) \
{ \
worktype p0, p1; \
float a, b; \
\
int ixs = cvFloor( xs ); \
int iys = cvFloor( ys ); \
\
a = xs - ixs; \
b = ys - iys; \
\
xs += A11; \
ys += A21; \
\
if( (unsigned)ixs < (unsigned)(src_size.width - 1) && \
(unsigned)iys < (unsigned)(src_size.height - 1) ) \
{ \
const srctype *ptr = PTR_AT( ixs, iys ); \
\
p0 = cvt(ptr[0]) + a * (cvt(ptr[1]) - cvt(ptr[0])); \
p1 = cvt(ptr[srcStep]) + a * (cvt(ptr[srcStep + 1]) - \
cvt(ptr[srcStep])); \
\
dst[x] = cast_macro(p0 + b * (p1 - p0)); \
} \
else if( !fill_outliers ) \
{ \
/* the slowest branch */ \
worktype t0, t1; \
\
x0 = CLIP_X( ixs ); \
y0 = CLIP_Y( iys ); \
x1 = CLIP_X( ixs + 1 ); \
y1 = CLIP_Y( iys + 1 ); \
\
t0 = cvt(*PTR_AT( x0, y0 )); \
t1 = cvt(*PTR_AT( x1, y0 )); \
p0 = t0 + a * (t1 - t0); \
\
t0 = cvt(*PTR_AT( x0, y1 )); \
t1 = cvt(*PTR_AT( x1, y1 )); \
p1 = t0 + a * (t1 - t0); \
p0 = p0 + b * (p1 - p0); \
dst[x] = cast_macro(p0); \
} \
else \
{ \
dst[x] = fv; \
} \
} \
} \
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?