cvpyramids.cpp.svn-base
来自「非结构化路识别」· SVN-BASE 代码 · 共 1,010 行 · 第 1/5 页
SVN-BASE
1,010 行
{ \
for( x = 0; x < Wdn; x++, x1++ ) \
dst[x] = (type)_pd_scale_( PD_SINGULAR( row01[x], row01[x1] )); \
} \
fst = PD_SZ - 2; \
} \
\
lst = y + 2 + PD_SZ/2 < size.height ? PD_SZ : size.height - y; \
} \
\
return CV_OK; \
}
ICV_DEF_PYR_DOWN_FUNC( 8u, uchar, int, PD_SCALE_INT )
ICV_DEF_PYR_DOWN_FUNC( 8s, char, int, PD_SCALE_INT )
ICV_DEF_PYR_DOWN_FUNC( 32f, float, float, PD_SCALE_FLT )
ICV_DEF_PYR_DOWN_FUNC( 64f, double, double, PD_SCALE_FLT )
/****************************************************************************************\
Up-sampling pyramids core functions
\****************************************************************************************/
/////////// filtering macros //////////////
/* COMMON CASE: NON ZERO */
/* 1/16[1 4 6 4 1] */
/* ...| x0 | 0 | x1 | 0 | x2 |... */
#define PU_FILTER( x0, x1, x2 ) ((x1)*6 + (x0) + (x2))
/* ZERO POINT AT CENTER */
/* 1/16[1 4 6 4 1] */
/* ...| 0 | x0 | 0 | x1 | 0 |... */
#define PU_FILTER_ZI( x0, x1 ) (((x0) + (x1))*4)
/* MACROS FOR BORDERS */
/* | b I a | b | reflection */
/* LEFT/TOP */
/* 1/16[1 4 6 4 1] */
/* | x1 | 0 I x0 | 0 | x1 |... */
#define PU_LT( x0, x1 ) ((x0)*6 + (x1)*2)
/* 1/16[1 4 6 4 1] */
/* | 0 I x0 | 0 | x1 | 0 |... */
#define PU_LT_ZI( x0, x1 ) PU_FILTER_ZI((x0),(x1))
/* RIGHT/BOTTOM: NON ZERO */
/* 1/16[1 4 6 4 1] */
/* ...| x0 | 0 | x1 | 0 I x1 | */
#define PU_RB( x0, x1 ) ((x0) + (x1)*7)
/* RIGHT/BOTTOM: ZERO POINT AT CENTER */
/* 1/16[1 4 6 4 1] */
/* ...| 0 | x0 | 0 I x0 | 0 | */
#define PU_RB_ZI( x0 ) ((x0)*8)
/* SINGULAR CASE */
/* 1/16[1 4 6 4 1] */
/* | x0 | 0 I x0 | 0 I x0 | */
#define PU_SINGULAR( x0 ) PU_RB_ZI((x0)) /* <--| the same formulas */
#define PU_SINGULAR_ZI( x0 ) PU_RB_ZI((x0)) /* <--| */
/* x/64 - scaling in up-sampling functions */
#define PU_SCALE_INT(x) (((x) + (1<<5)) >> 6)
#define PU_SCALE_FLT(x) ((x)*0.015625f)
#define PU_SZ 3
//////////// generic macro /////////////
#define ICV_DEF_PYR_UP_FUNC( flavor, type, worktype, _pu_scale_ ) \
static CvStatus \
icvPyrUpG5x5_##flavor( const type* src, int srcstep, type* dst, int dststep, \
CvSize size, void *buf, int Cs ) \
{ \
worktype *buffer = (worktype*)buf; \
worktype *rows[PU_SZ]; \
int y, top_row = 0; \
int Wd = size.width * 2, Wdn = Wd * Cs, Wn = size.width * Cs; \
int buffer_step = Wdn; \
int pu_sz = PU_SZ*buffer_step; \
int fst = 0, lst = size.height <= PU_SZ/2 ? size.height : PU_SZ/2 + 1; \
\
assert( Cs == 1 || Cs == 3 ); \
\
/* main loop */ \
for( y = 0; y < size.height; y++, (char*&)dst += 2 * dststep ) \
{ \
int x, y1, k = top_row; \
worktype *row0, *row1, *row2; \
type *dst1; \
\
/* assign rows pointers */ \
for( y1 = 0; y1 < PU_SZ; y1++ ) \
{ \
rows[y1] = buffer + k; \
k += buffer_step; \
k &= k < pu_sz ? -1 : 0; \
} \
\
row0 = rows[0]; \
row1 = rows[1]; \
row2 = rows[2]; \
dst1 = (type*)((char*)dst + dststep); \
\
/* fill new buffer rows with filtered source (horizontal conv) */ \
if( Cs == 1 ) \
if( size.width > PU_SZ / 2 ) \
for( y1 = fst; y1 < lst; y1++, (char*&)src += srcstep ) \
{ \
worktype *row = rows[y1]; \
\
/* process left & right bounds */ \
row[0] = PU_LT( src[0], src[1] ); \
row[1] = PU_LT_ZI( src[0], src[1] ); \
row[size.width * 2 - 2] = PU_RB( src[size.width - 2], \
src[size.width - 1] ); \
row[size.width * 2 - 1] = PU_RB_ZI( src[size.width - 1] ); \
/* other points */ \
for( x = 1; x < size.width - 1; x++ ) \
{ \
row[2 * x] = PU_FILTER( src[x - 1], src[x], src[x + 1] ); \
row[2 * x + 1] = PU_FILTER_ZI( src[x], src[x + 1] ); \
} \
} \
else /* size.width <= PU_SZ/2 */ \
for( y1 = fst; y1 < lst; y1++, (char*&)src += srcstep ) \
{ \
worktype *row = rows[y1]; \
worktype val = src[0]; \
\
row[0] = PU_SINGULAR( val ); \
row[1] = PU_SINGULAR_ZI( val ); \
} \
else /* Cs == 3 */ \
for( y1 = fst; y1 < lst; y1++, (char*&)src += srcstep ) \
{ \
worktype *row = rows[y1]; \
\
if( size.width > PU_SZ / 2 ) \
{ \
int c; \
\
for( c = 0; c < 3; c++ ) \
{ \
/* process left & right bounds */ \
row[c] = PU_LT( src[c], src[3 + c] ); \
row[3 + c] = PU_LT_ZI( src[c], src[3 + c] ); \
row[Wn * 2 - 6 + c] = PU_RB( src[Wn - 6 + c], src[Wn - 3 + c]); \
row[Wn * 2 - 3 + c] = PU_RB_ZI( src[Wn - 3 + c] ); \
} \
/* other points */ \
for( x = 3; x < Wn - 3; x += 3 ) \
{ \
row[2 * x] = PU_FILTER( src[x - 3], src[x], src[x + 3] ); \
row[2 * x + 3] = PU_FILTER_ZI( src[x], src[x + 3] ); \
\
row[2 * x + 1] = PU_FILTER( src[x - 2], src[x + 1], src[x + 4]);\
row[2 * x + 4] = PU_FILTER_ZI( src[x + 1], src[x + 4] ); \
\
row[2 * x + 2] = PU_FILTER( src[x - 1], src[x + 2], src[x + 5]);\
row[2 * x + 5] = PU_FILTER_ZI( src[x + 2], src[x + 5] ); \
} \
} \
else /* size.width <= PU_SZ/2 */ \
{ \
int c; \
\
for( c = 0; c < 3; c++ ) \
{ \
row[c] = PU_SINGULAR( src[c] ); \
row[3 + c] = PU_SINGULAR_ZI( src[c] ); \
} \
} \
} \
\
/* second pass. Do vertical conv and write results do destination image */ \
if( y > 0 ) \
{ \
if( y < size.height - PU_SZ / 2 ) \
{ \
for( x = 0; x < Wdn; x++ ) \
{ \
dst[x] = (type)_pu_scale_( PU_FILTER( row0[x], row1[x], row2[x] )); \
dst1[x] = (type)_pu_scale_( PU_FILTER_ZI( row1[x], row2[x] )); \
} \
top_row += buffer_step; \
top_row &= top_row < pu_sz ? -1 : 0; \
} \
else /* bottom */ \
for( x = 0; x < Wdn; x++ ) \
{ \
dst[x] = (type)_pu_scale_( PU_RB( row0[x], row1[x] )); \
dst1[x] = (type)_pu_scale_( PU_RB_ZI( row1[x] )); \
} \
} \
else \
{ \
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?