cvpyramids.cpp.svn-base

来自「非结构化路识别」· SVN-BASE 代码 · 共 1,010 行 · 第 1/5 页

SVN-BASE
1,010
字号
}

ICV_DEF_PYR_BORDER_FUNC( 8u, uchar, int, PD_SCALE_INT )
ICV_DEF_PYR_BORDER_FUNC( 8s, char, int, PD_SCALE_INT )
ICV_DEF_PYR_BORDER_FUNC( 32f, float, float, PD_SCALE_FLT )
ICV_DEF_PYR_BORDER_FUNC( 64f, double, double, PD_SCALE_FLT )


#define ICV_DEF_INIT_PYR_TABLE( FUNCNAME, FLAG )                    \
static void icvInit##FUNCNAME##FLAG##Table( CvBigFuncTable* tab )   \
{                                                                   \
    tab->fn_2d[CV_8UC1] = (void*)icv##FUNCNAME##_8u_C1##FLAG;       \
    tab->fn_2d[CV_8UC3] = (void*)icv##FUNCNAME##_8u_C3##FLAG;       \
    tab->fn_2d[CV_8SC1] = (void*)icv##FUNCNAME##_8s_C1##FLAG;       \
    tab->fn_2d[CV_8SC3] = (void*)icv##FUNCNAME##_8s_C3##FLAG;       \
    tab->fn_2d[CV_32FC1] = (void*)icv##FUNCNAME##_32f_C1##FLAG;     \
    tab->fn_2d[CV_32FC3] = (void*)icv##FUNCNAME##_32f_C3##FLAG;     \
    tab->fn_2d[CV_64FC1] = (void*)icv##FUNCNAME##_64f_C1##FLAG;     \
    tab->fn_2d[CV_64FC3] = (void*)icv##FUNCNAME##_64f_C3##FLAG;     \
}

#define ICV_DEF_INIT_PYR_BORDER_TABLE( FUNCNAME, FLAG )             \
static void icvInit##FUNCNAME##FLAG##Table( CvFuncTable* tab )      \
{                                                                   \
    tab->fn_2d[CV_8U] = (void*)icv##FUNCNAME##_8u_Cn##FLAG;         \
    tab->fn_2d[CV_8S] = (void*)icv##FUNCNAME##_8s_Cn##FLAG;         \
    tab->fn_2d[CV_32F] = (void*)icv##FUNCNAME##_32f_Cn##FLAG;       \
    tab->fn_2d[CV_64F] = (void*)icv##FUNCNAME##_64f_Cn##FLAG;       \
}


ICV_DEF_INIT_PYR_TABLE( PyrUp_Gauss5x5, R )
ICV_DEF_INIT_PYR_TABLE( PyrDown_Gauss5x5, R )

ICV_DEF_INIT_PYR_BORDER_TABLE( PyrDownBorder, R )

typedef CvStatus (CV_STDCALL * CvPyrDownBorderFunc)( const void* src, int srcstep,
                                                     CvSize srcsize,
                                                     void* dst, int dststep,
                                                     CvSize dstsize,
                                                     int channels );

/****************************************************************************************\
*                                 External functions                                     *
\****************************************************************************************/

CV_IMPL void
cvPyrUp( const void* srcarr, void* dstarr, int _filter )
{
    static CvBigFuncTable pyrup_tab;
    static int inittab = 0;
    
    void *buffer = 0;
    int local_alloc = 0;

    CV_FUNCNAME( "cvPyrUp" );

    __BEGIN__;

    int coi1 = 0, coi2 = 0;
    int buffer_size = 0;
    int type;
    CvMat srcstub, *src = (CvMat*)srcarr;
    CvMat dststub, *dst = (CvMat*)dstarr;
    CvFilter filter = (CvFilter) _filter;
    CvFunc2D_2A1P func;

    if( !inittab )
    {
        icvInitPyrUp_Gauss5x5RTable( &pyrup_tab );
        inittab = 1;
    }

    CV_CALL( src = cvGetMat( src, &srcstub, &coi1 ));
    CV_CALL( dst = cvGetMat( dst, &dststub, &coi2 ));

    if( coi1 != 0 || coi2 != 0 )
        CV_ERROR( CV_BadCOI, "" );

    if( filter != CV_GAUSSIAN_5x5 )
        CV_ERROR( CV_StsBadArg, "this filter type not supported" );

    if( !CV_ARE_TYPES_EQ( src, dst ))
        CV_ERROR( CV_StsUnmatchedFormats, "" );

    if( src->width*2 != dst->width || src->height*2 != dst->height )
        CV_ERROR( CV_StsUnmatchedSizes, "" );

    type = CV_MAT_TYPE(src->type);

    func = (CvFunc2D_2A1P)(pyrup_tab.fn_2d[type]);

    if( !func )
        CV_ERROR( CV_StsUnsupportedFormat, "" );

    IPPI_CALL( icvPyrUpGetBufSize_Gauss5x5( src->width, icvDepthToDataType(type),
                                            CV_MAT_CN( type ), &buffer_size ));

    if( buffer_size <= CV_MAX_LOCAL_SIZE )
    {
        buffer = alloca( buffer_size );
        local_alloc = 1;
    }
    else
    {
        CV_CALL( buffer = cvAlloc( buffer_size ));
    }

    IPPI_CALL( func( src->data.ptr, src->step, dst->data.ptr, dst->step,
                     icvGetMatSize(src), buffer ));
    __END__;

    if( buffer && !local_alloc )
        cvFree( &buffer );
}


CV_IMPL void
cvPyrDown( const void* srcarr, void* dstarr, int _filter )
{
    static CvBigFuncTable pyrdown_tab;
    static CvFuncTable pyrdownborder_tab;
    static int inittab = 0;
    
    void *buffer = 0;
    int local_alloc = 0;

    CV_FUNCNAME( "cvPyrDown" );

    __BEGIN__;

    int coi1 = 0, coi2 = 0;
    int buffer_size = 0;
    int type;
    CvMat srcstub, *src = (CvMat*)srcarr;
    CvMat dststub, *dst = (CvMat*)dstarr;
    CvFilter filter = (CvFilter) _filter;
    CvFunc2D_2A1P func;
    CvSize src_size, src_size2, dst_size;

    if( !inittab )
    {
        icvInitPyrDown_Gauss5x5RTable( &pyrdown_tab );
        icvInitPyrDownBorderRTable( &pyrdownborder_tab );
        inittab = 1;
    }

    CV_CALL( src = cvGetMat( src, &srcstub, &coi1 ));
    CV_CALL( dst = cvGetMat( dst, &dststub, &coi2 ));

    if( coi1 != 0 || coi2 != 0 )
        CV_ERROR( CV_BadCOI, "" );

    if( filter != CV_GAUSSIAN_5x5 )
        CV_ERROR( CV_StsBadArg, "this filter type not supported" );

    if( !CV_ARE_TYPES_EQ( src, dst ))
        CV_ERROR( CV_StsUnmatchedFormats, "" );

    src_size = icvGetMatSize(src);
    dst_size = icvGetMatSize(dst);
    src_size2.width = src_size.width & -2;
    src_size2.height = src_size.height & -2;

    if( (unsigned)(dst_size.width - src_size.width/2) > 1 ||
        (unsigned)(dst_size.height - src_size.height/2) > 1 )
        CV_ERROR( CV_StsUnmatchedSizes, "" );

    if( src->data.ptr == dst->data.ptr )
        CV_ERROR( CV_StsInplaceNotSupported, "" );

    type = CV_MAT_TYPE(src->type);

    func = (CvFunc2D_2A1P)(pyrdown_tab.fn_2d[type]);

    if( !func )
        CV_ERROR( CV_StsUnsupportedFormat, "" );

    IPPI_CALL( icvPyrDownGetBufSize_Gauss5x5( src_size2.width, icvDepthToDataType(type),
                                              CV_MAT_CN( type ), &buffer_size ));
    
    if( buffer_size <= CV_MAX_LOCAL_SIZE )
    {
        buffer = alloca( buffer_size );
        local_alloc = 1;
    }
    else
    {
        CV_CALL( buffer = cvAlloc( buffer_size ));
    }

    IPPI_CALL(func(src->data.ptr, src->step, dst->data.ptr, dst->step, src_size2, buffer));

    if( src_size.width != dst_size.width*2 || src_size.height != dst_size.height*2 )
    {
        CvPyrDownBorderFunc border_func = (CvPyrDownBorderFunc)
                            pyrdownborder_tab.fn_2d[CV_MAT_DEPTH(type)];

        if( !border_func )
            CV_ERROR( CV_StsUnsupportedFormat, "" );

        IPPI_CALL( borde

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?