📄 cvsamplers.cpp
字号:
}
#define ICV_DEF_GET_QUADRANGLE_SUB_PIX_FUNC_C3( flavor, srctype, dsttype, \
worktype, cast_macro, cvt ) \
static CvStatus CV_STDCALL \
icvGetQuadrangleSubPix_##flavor##_C3R \
( const srctype * src, int src_step, CvSize src_size, \
dsttype *dst, int dst_step, CvSize win_size, const float *matrix ) \
{ \
int x, y; \
double dx = (win_size.width - 1)*0.5; \
double dy = (win_size.height - 1)*0.5; \
double A11 = matrix[0], A12 = matrix[1], A13 = matrix[2]-A11*dx-A12*dy; \
double A21 = matrix[3], A22 = matrix[4], A23 = matrix[5]-A21*dx-A22*dy; \
\
src_step /= sizeof(srctype); \
dst_step /= sizeof(dsttype); \
\
for( y = 0; y < win_size.height; y++, dst += dst_step ) \
{ \
double xs = A12*y + A13; \
double ys = A22*y + A23; \
double xe = A11*(win_size.width-1) + A12*y + A13; \
double ye = A21*(win_size.width-1) + A22*y + A23; \
\
if( (unsigned)(cvFloor(xs)-1) < (unsigned)(src_size.width - 3) && \
(unsigned)(cvFloor(ys)-1) < (unsigned)(src_size.height - 3) && \
(unsigned)(cvFloor(xe)-1) < (unsigned)(src_size.width - 3) && \
(unsigned)(cvFloor(ye)-1) < (unsigned)(src_size.height - 3)) \
{ \
for( x = 0; x < win_size.width; x++ ) \
{ \
int ixs = cvFloor( xs ); \
int iys = cvFloor( ys ); \
const srctype *ptr = src + src_step*iys + ixs*3; \
double a = xs - ixs, b = ys - iys, a1 = 1.f - a; \
worktype p0, p1; \
xs += A11; \
ys += A21; \
\
p0 = cvt(ptr[0])*a1 + cvt(ptr[3])*a; \
p1 = cvt(ptr[src_step])*a1 + cvt(ptr[src_step+3])*a; \
dst[x*3] = cast_macro(p0 + b * (p1 - p0)); \
\
p0 = cvt(ptr[1])*a1 + cvt(ptr[4])*a; \
p1 = cvt(ptr[src_step+1])*a1 + cvt(ptr[src_step+4])*a; \
dst[x*3+1] = cast_macro(p0 + b * (p1 - p0)); \
\
p0 = cvt(ptr[2])*a1 + cvt(ptr[5])*a; \
p1 = cvt(ptr[src_step+2])*a1 + cvt(ptr[src_step+5])*a; \
dst[x*3+2] = cast_macro(p0 + b * (p1 - p0)); \
} \
} \
else \
{ \
for( x = 0; x < win_size.width; x++ ) \
{ \
int ixs = cvFloor(xs), iys = cvFloor(ys); \
double a = xs - ixs, b = ys - iys; \
const srctype *ptr0, *ptr1; \
xs += A11; ys += A21; \
\
if( (unsigned)iys < (unsigned)(src_size.height-1) ) \
ptr0 = src + src_step*iys, ptr1 = ptr0 + src_step; \
else \
ptr0 = ptr1 = src + (iys < 0 ? 0 : src_size.height-1)*src_step; \
\
if( (unsigned)ixs < (unsigned)(src_size.width - 1) ) \
{ \
double a1 = 1.f - a; \
worktype p0, p1; \
ptr0 += ixs*3; ptr1 += ixs*3; \
p0 = cvt(ptr0[0])*a1 + cvt(ptr0[3])*a; \
p1 = cvt(ptr1[0])*a1 + cvt(ptr1[3])*a; \
dst[x*3] = cast_macro(p0 + b * (p1 - p0)); \
\
p0 = cvt(ptr0[1])*a1 + cvt(ptr0[4])*a; \
p1 = cvt(ptr1[1])*a1 + cvt(ptr1[4])*a; \
dst[x*3+1] = cast_macro(p0 + b * (p1 - p0)); \
\
p0 = cvt(ptr0[2])*a1 + cvt(ptr0[5])*a; \
p1 = cvt(ptr1[2])*a1 + cvt(ptr1[5])*a; \
dst[x*3+2] = cast_macro(p0 + b * (p1 - p0)); \
} \
else \
{ \
double b1 = 1.f - b; \
ixs = ixs < 0 ? 0 : src_size.width - 1; \
ptr0 += ixs*3; ptr1 += ixs*3; \
\
dst[x*3] = cast_macro(cvt(ptr0[0])*b1 + cvt(ptr1[0])*b);\
dst[x*3+1]=cast_macro(cvt(ptr0[1])*b1 + cvt(ptr1[1])*b);\
dst[x*3+2]=cast_macro(cvt(ptr0[2])*b1 + cvt(ptr1[2])*b);\
} \
} \
} \
} \
\
return CV_OK; \
}
/*#define srctype uchar
#define dsttype uchar
#define worktype float
#define cvt CV_8TO32F
#define cast_macro ICV_32F8U
#undef srctype
#undef dsttype
#undef worktype
#undef cvt
#undef cast_macro*/
ICV_DEF_GET_QUADRANGLE_SUB_PIX_FUNC( 8u, uchar, uchar, double, ICV_32F8U, CV_8TO32F )
ICV_DEF_GET_QUADRANGLE_SUB_PIX_FUNC( 32f, float, float, double, CV_CAST_32F, CV_NOP )
ICV_DEF_GET_QUADRANGLE_SUB_PIX_FUNC( 8u32f, uchar, float, double, CV_CAST_32F, CV_8TO32F )
ICV_DEF_GET_QUADRANGLE_SUB_PIX_FUNC_C3( 8u, uchar, uchar, double, ICV_32F8U, CV_8TO32F )
ICV_DEF_GET_QUADRANGLE_SUB_PIX_FUNC_C3( 32f, float, float, double, CV_CAST_32F, CV_NOP )
ICV_DEF_GET_QUADRANGLE_SUB_PIX_FUNC_C3( 8u32f, uchar, float, double, CV_CAST_32F, CV_8TO32F )
ICV_DEF_INIT_SUBPIX_TAB( GetQuadrangleSubPix, C1R )
ICV_DEF_INIT_SUBPIX_TAB( GetQuadrangleSubPix, C3R )
typedef CvStatus (CV_STDCALL *CvGetQuadrangleSubPixFunc)(
const void* src, int src_step,
CvSize src_size, void* dst,
int dst_step, CvSize win_size,
const float* matrix );
CV_IMPL void
cvGetQuadrangleSubPix( const void* srcarr, void* dstarr, const CvMat* mat )
{
static CvFuncTable gq_tab[2];
static int inittab = 0;
CV_FUNCNAME( "cvGetQuadrangleSubPix" );
__BEGIN__;
CvMat srcstub, *src = (CvMat*)srcarr;
CvMat dststub, *dst = (CvMat*)dstarr;
CvSize src_size, dst_size;
CvGetQuadrangleSubPixFunc func;
float m[6];
int k, cn;
if( !inittab )
{
icvInitGetQuadrangleSubPixC1RTable( gq_tab + 0 );
icvInitGetQuadrangleSubPixC3RTable( gq_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 ));
if( !CV_IS_MAT(mat))
CV_ERROR( CV_StsBadArg, "map matrix is not valid" );
cn = CV_MAT_CN( src->type );
if( (cn != 1 && cn != 3) || !CV_ARE_CNS_EQ( src, dst ))
CV_ERROR( CV_StsUnsupportedFormat, "" );
src_size = cvGetMatSize( src );
dst_size = cvGetMatSize( dst );
/*if( dst_size.width > src_size.width || dst_size.height > src_size.height )
CV_ERROR( CV_StsBadSize, "destination ROI must not be larger than source ROI" );*/
if( mat->rows != 2 || mat->cols != 3 )
CV_ERROR( CV_StsBadArg,
"Transformation matrix must be 2x3" );
if( CV_MAT_TYPE( mat->type ) == CV_32FC1 )
{
for( k = 0; k < 3; k++ )
{
m[k] = mat->data.fl[k];
m[3 + k] = ((float*)(mat->data.ptr + mat->step))[k];
}
}
else if( CV_MAT_TYPE( mat->type ) == CV_64FC1 )
{
for( k = 0; k < 3; k++ )
{
m[k] = (float)mat->data.db[k];
m[3 + k] = (float)((double*)(mat->data.ptr + mat->step))[k];
}
}
else
CV_ERROR( CV_StsUnsupportedFormat,
"The transformation matrix should have 32fC1 or 64fC1 type" );
if( CV_ARE_DEPTHS_EQ( src, dst ))
{
func = (CvGetQuadrangleSubPixFunc)(gq_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 = (CvGetQuadrangleSubPixFunc)(gq_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, m ));
__END__;
}
/* End of file. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -