cvlogic.cpp.svn-base

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

SVN-BASE
939
字号
                                                                                \
    return  CV_OK;                                                              \
}


/////////////////////////////////////////////////////////////////////////////////////////
//                                                                                     //
//                                LOGIC OPERATIONS                                     //
//                                                                                     //
/////////////////////////////////////////////////////////////////////////////////////////

static void
icvLogicS( const void* srcarr, CvScalar* scalar,
           void* dstarr, CvFunc2D_2A1P1I fn_2d )
{
    CV_FUNCNAME( "icvLogicS" );
    
    __BEGIN__;

    CvMat srcstub, *src = (CvMat*)srcarr;
    CvMat dststub, *dst = (CvMat*)dstarr;
    
    int coi1 = 0, coi2 = 0;
    int is_nd = 0;
    int pix_size, type;
    double buf[12];
    CvSize size;
    int src_step, dst_step;

    if( !CV_IS_MAT(src))
    {
        if( CV_IS_MATND(src) )
            is_nd = 1;
        else
            CV_CALL( src = cvGetMat( src, &srcstub, &coi1 ));
    }

    if( !CV_IS_MAT(dst))
    {
        if( CV_IS_MATND(dst) )
            is_nd = 1;
        else
            CV_CALL( dst = cvGetMat( dst, &dststub, &coi2 ));
    }

    if( is_nd )
    {
        CvArr* arrs[] = { src, dst };
        CvMatND stubs[2];
        CvMatNDIterator iterator;

        CV_CALL( icvPrepareArrayOp( 2, arrs, 0, stubs, &iterator ));

        type = CV_MAT_TYPE(iterator.hdr[0]->type);
        iterator.size.width *= icvPixSize[type];
        pix_size = icvPixSize[type & CV_MAT_DEPTH_MASK];

        CV_CALL( cvScalarToRawData( scalar, buf, type, 1 ));

        do
        {
            IPPI_CALL( fn_2d( iterator.ptr[0], CV_STUB_STEP,
                              iterator.ptr[1], CV_STUB_STEP,
                              iterator.size, buf, pix_size ));
        }
        while( icvNextMatNDSlice( &iterator ));
        EXIT;
    }

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

    if( !CV_ARE_TYPES_EQ( src, dst ) )
        CV_ERROR_FROM_CODE( CV_StsUnmatchedFormats );

    if( !CV_ARE_SIZES_EQ( src, dst ) )
        CV_ERROR_FROM_CODE( CV_StsUnmatchedSizes );

    size = icvGetMatSize( src );
    src_step = src->step;
    dst_step = dst->step;

    if( CV_IS_MAT_CONT( src->type & dst->type ))
    {
        size.width *= size.height;
        src_step = dst_step = CV_STUB_STEP;
        size.height = 1;
    }

    type = CV_MAT_TYPE( src->type );
    size.width *= icvPixSize[type];
    pix_size = icvPixSize[type & CV_MAT_DEPTH_MASK];

    CV_CALL( cvScalarToRawData( scalar, buf, type, 1 ));

    IPPI_CALL( fn_2d( src->data.ptr, src_step, dst->data.ptr, dst_step,
                      size, buf, pix_size ));

    __END__;
}


static void
icvLogic( const void* srcimg1, const void* srcimg2,
          void* dstarr, CvFunc2D_3A fn_2d )
{
    CV_FUNCNAME( "icvLogic" );
    
    __BEGIN__;

    int coi1 = 0, coi2 = 0, coi3 = 0;
    int is_nd = 0;
    CvMat  srcstub1, *src1 = (CvMat*)srcimg1;
    CvMat  srcstub2, *src2 = (CvMat*)srcimg2;
    CvMat  dststub,  *dst = (CvMat*)dstarr;
    int src1_step, src2_step, dst_step;
    CvSize size;

    if( !CV_IS_MAT(src1))
    {
        if( CV_IS_MATND(src1) )
            is_nd = 1;
        else
            CV_CALL( src1 = cvGetMat( src1, &srcstub1, &coi1 ));
    }

    if( !CV_IS_MAT(src2))
    {
        if( CV_IS_MATND(src2) )
            is_nd = 1;
        else
            CV_CALL( src2 = cvGetMat( src2, &srcstub2, &coi2 ));
    }

    if( !CV_IS_MAT(dst))
    {
        if( CV_IS_MATND(dst) )
            is_nd = 1;
        else
            CV_CALL( dst = cvGetMat( dst, &dststub, &coi3 ));
    }

    if( is_nd )
    {
        CvArr* arrs[] = { src1, src2, dst };
        CvMatND stubs[3];
        CvMatNDIterator iterator;
        int type;

        CV_CALL( icvPrepareArrayOp( 3, arrs, 0, stubs, &iterator ));

        type = CV_MAT_TYPE(iterator.hdr[0]->type);
        iterator.size.width *= icvPixSize[type];

        do
        {
            IPPI_CALL( fn_2d( iterator.ptr[0], CV_STUB_STEP,
                              iterator.ptr[1], CV_STUB_STEP,
                              iterator.ptr[2], CV_STUB_STEP,
                              iterator.size ));
        }
        while( icvNextMatNDSlice( &iterator ));
        EXIT;
    }

    if( coi1 != 0 || coi2 != 0 || coi3 != 0 )
        CV_ERROR_FROM_CODE( CV_BadCOI );

    if( !CV_ARE_TYPES_EQ( src1, src2 ) )
        CV_ERROR_FROM_CODE( CV_StsUnmatchedFormats );

    if( !CV_ARE_SIZES_EQ( src1, src2 ) )
        CV_ERROR_FROM_CODE( CV_StsUnmatchedSizes );

    size = icvGetMatSize( src1 );
        
    if( !CV_ARE_TYPES_EQ( src1, dst ) )
        CV_ERROR_FROM_CODE( CV_StsUnmatchedFormats );
    
    if( !CV_ARE_SIZES_EQ( src1, dst ) )
        CV_ERROR_FROM_CODE( CV_StsUnmatchedSizes );

    src1_step = src1->step;
    src2_step = src2->step;
    dst_step = dst->step;

    if( CV_IS_MAT_CONT( src1->type & src2->type & dst->type ))
    {
        size.width *= size.height;
        src1_step = src2_step = dst_step = CV_STUB_STEP;
        size.height = 1;
    }

    size.width *= icvPixSize[CV_MAT_TYPE(src1->type)];

    IPPI_CALL( fn_2d( src1->data.ptr, src1_step, src2->data.ptr, src2_step,
                      dst->data.ptr, dst_step, size ));

    __END__;
}


/////////////////////////////////////////////////////////////////////////////////////////
//                                                                                     //
//                       LOGIC OPERATIONS WITH MASK SUPPORT                            //
//                                                                                     //
/////////////////////////////////////////////////////////////////////////////////////////

static void
icvLogicSM( const void* srcarr, CvScalar* scalar, void* dstarr,
            const void* maskarr, CvArithmUniMaskFunc2D func )
{
    CV_FUNCNAME( "icvLogicSM" );
    
    __BEGIN__;

    double buf[12];
    int coi1 = 0, coi2 = 0;
    CvMat  srcstub, *src = (CvMat*)srcarr;
    CvMat  dststub, *dst = (CvMat*)dstarr;
    CvMat  maskstub, *mask = (CvMat*)maskarr;
    int pix_size, type;
    int dst_step, mask_step;
    CvSize size;

    if( !CV_IS_MAT(src))
        CV_CALL( src = cvGetMat( src, &srcstub, &coi1 ));

    if( !CV_IS_MAT(dst))
        CV_CALL( dst = cvGetMat( dst, &dststub ));

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

    CV_CALL( mask = cvGetMat( mask, &maskstub ));

    if( !CV_IS_MASK_ARR(mask) )
        CV_ERROR_FROM_CODE( CV_StsBadMask );

    if( !CV_ARE_SIZES_EQ( mask, dst ) )
        CV_ERROR_FROM_CODE( CV_StsUnmatchedSizes );

    if( src->data.ptr != dst->data.ptr )
    {
        CV_CALL( cvCopy( src, dst, mask ));
    }

    size = icvGetMatSize( dst );
    dst_step = dst->step;
    mask_step = mask->step;

    if( CV_IS_MAT_CONT( mask->type & dst->type ))
    {
        size.width *= size.height;
        dst_step = mask_step = CV_STUB_STEP;
        size.height = 1;
    }

    type = CV_MAT_TYPE( src->type );
    pix_size = icvPixSize[type];
    
    CV_CALL( cvScalarToRawData( scalar, buf, type, 0 ));
    IPPI_CALL( func( dst->data.ptr, dst_step, mask->data.ptr,
                     mask_step, size, buf, pix_size ));

    __END__;
}


CV_IMPL void
icvLogicM( const void* srcimg1, const void* srcimg2,
           void* dstarr, const void* maskarr,
           CvArithmBinMaskFunc2D func )
{
    CV_FUNCNAME( "icvLogicM" );
    
    __BEGIN__;

    int  coi1 = 0, coi2 = 0, coi3 = 0;
    CvMat  srcstub1, *src1 = (CvMat*)srcimg1;
    CvMat  srcstub2, *src2 = (CvMat*)srcimg2;
    CvMat  dststub, *dst = (CvMat*)dstarr;
    CvMat  maskstub, *mask = (CvMat*)maskarr;
    int src_step, dst_step, mask_step; 
    int pix_size;
    CvSize size;

    CV_CALL( src1 = cvGetMat( src1, &srcstub1, &coi1 ));
    CV_CALL( src2 = cvGetMat( src2, &srcstub2, &coi2 ));
    CV_CALL( dst = cvGetMat( dst, &dststub, &coi3 ));
    CV_CALL( mask = cvGetMat( mask, &maskstub ));

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

    if( !CV_IS_MASK_ARR(mask) )
        CV_ERROR_FROM_CODE( CV_StsBadMask );

    if( !CV_ARE_SIZES_EQ( mask, dst ) )
        CV_ERROR_FROM_CODE( CV_StsUnmatchedSizes );

    if( !CV_ARE_SIZES_EQ( src1, src2 ) )
        CV_ERROR_FROM_CODE( CV_StsUnmatchedSizes );

    size = icvGetMatSize( src1 );
    pix_size = icvPixSize[CV_MAT_TYPE(src1->type)];
        
    if( src2->data.ptr != dst->data.ptr )
    {
        if( src1->data.ptr != dst->data.ptr )
        {
            CV_CALL( cvCopy( src2, dst, mask ));
        }

⌨️ 快捷键说明

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