cveigenobjectswrap.cpp.svn-base

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

SVN-BASE
732
字号
/*--------------------------------------------------------------------------------------*/
/*F///////////////////////////////////////////////////////////////////////////////////////
//    Names: cvEigenDecomposite
//    Purpose: The function calculates all decomposition coefficients for input object
//             using previously calculated eigen objects basis and the mean (averaged)
//             object
//
//    Parameters:  obj         - input object
//                 nEigObjs    - number of eigen objects
//                 eigInput    - pointer either to array of pointers to eigen objects
//                               or to read callback function (depending on ioFlags)
//                 ioFlags     - input/output flags
//                 userData    - pointer to the structure which contains all necessary
//                               data for the callback function
//                 avg         - averaged object
//                 coeffs      - calculated coefficients (output data)
//
//    Notes:   see notes for cvCalcEigenObjects function
//F*/

CV_IMPL void
cvEigenDecomposite( IplImage* obj,
                    int       nEigObjs,
                    void*     eigInput,
                    int       ioFlags, 
                    void*     userData, 
                    IplImage* avg, 
                    float*    coeffs )
{
    float *avg_data;
    uchar *obj_data;
    int avg_step = 0, obj_step = 0;
    CvSize avg_size, obj_size;
    int i;

    CV_FUNCNAME( "cvEigenDecomposite" );

    __BEGIN__;

    CV_CALL( CV_CHECK_IMAGE( avg ));
    cvGetImageRawData( avg, (uchar **) & avg_data, &avg_step, &avg_size );
    if( avg->depth != IPL_DEPTH_32F )
        CV_ERROR( CV_BadDepth, icvUnsupportedFormat );
    if( avg->nChannels != 1 )
        CV_ERROR( CV_BadNumChannels, icvUnsupportedFormat );

    CV_CALL( CV_CHECK_IMAGE( obj ));
    cvGetImageRawData( obj, &obj_data, &obj_step, &obj_size );
    if( obj->depth != IPL_DEPTH_8U )
        CV_ERROR( CV_BadDepth, icvUnsupportedFormat );
    if( obj->nChannels != 1 )
        CV_ERROR( CV_BadNumChannels, icvUnsupportedFormat );

    if( obj_size != avg_size )
        CV_ERROR( CV_StsBadArg, "Different sizes of objects" );

    if( ioFlags == CV_EIGOBJ_NO_CALLBACK )
    {
        IplImage **eigens = (IplImage **) (((CvInput *) & eigInput)->data);
        float **eigs = (float **) icvAlloc( sizeof( float * ) * nEigObjs );
        int eig_step = 0, old_step = 0;
        CvSize eig_size = avg_size, old_size = avg_size;

        if( eigs == NULL )
            CV_ERROR( CV_StsBadArg, "Insufficient memory" );

        for( i = 0; i < nEigObjs; i++ )
        {
            IplImage *eig = eigens[i];
            float *eig_data;

            CV_CALL( CV_CHECK_IMAGE( eig ));
            cvGetImageRawData( eig, (uchar **) & eig_data, &eig_step, &eig_size );
            if( eig->depth != IPL_DEPTH_32F )
                CV_ERROR( CV_BadDepth, icvUnsupportedFormat );
            if( eig_size != avg_size || eig_size != old_size )
                CV_ERROR( CV_StsBadArg, "Different sizes of objects" );
            if( eig->nChannels != 1 )
                CV_ERROR( CV_BadNumChannels, icvUnsupportedFormat );
            if( i > 0 && eig_step != old_step )
                CV_ERROR( CV_StsBadArg, "Different steps of objects" );

            old_step = eig_step;
            old_size = eig_size;
            eigs[i] = eig_data;
        }

        CV_CALL( icvEigenDecomposite_8u32fR( obj_data,
                                             obj_step,
                                             nEigObjs,
                                             (void*) eigs,
                                             eig_step,
                                             ioFlags,
                                             userData,
                                             avg_data,
                                             avg_step,
                                             obj_size,
                                             coeffs   ));
        icvFree( (void **) &eigs );
    }

    else

    {
        CV_CALL( icvEigenDecomposite_8u32fR( obj_data,
                                             obj_step,
                                             nEigObjs,
                                             eigInput,
                                             avg_step,
                                             ioFlags,
                                             userData,
                                             avg_data,
                                             avg_step,
                                             obj_size,
                                             coeffs   ));
    }

    __CLEANUP__;
    __END__;
}

/*--------------------------------------------------------------------------------------*/
/*F///////////////////////////////////////////////////////////////////////////////////////
//    Name: cvEigenProjection
//    Purpose: The function calculates object projection to the eigen sub-space (restores
//             an object) using previously calculated eigen objects basis, mean (averaged)
//             object and decomposition coefficients of the restored object
//    Context:
//    Parameters:  nEigObjs    - number of eigen objects
//                 eigInput    - pointer either to array of pointers to eigen objects
//                               or to read callback function (depending on ioFlags)
//                 ioFlags     - input/output flags
//                 userData    - pointer to the structure which contains all necessary
//                               data for the callback function
//                 coeffs      - array of decomposition coefficients
//                 avg         - averaged object
//                 proj        - object projection (output data)
//
//    Notes:   see notes for cvCalcEigenObjects function
//F*/

CV_IMPL void
cvEigenProjection( void*     eigInput,
                   int       nEigObjs,
                   int       ioFlags,
                   void*     userData,
                   float*    coeffs, 
                   IplImage* avg,
                   IplImage* proj )
{
    float *avg_data;
    uchar *proj_data;
    int avg_step = 0, proj_step = 0;
    CvSize avg_size, proj_size;
    int i;

    CV_FUNCNAME( "cvEigenProjection" );

    __BEGIN__;

    CV_CALL( CV_CHECK_IMAGE( avg ));
    cvGetImageRawData( avg, (uchar **) & avg_data, &avg_step, &avg_size );
    if( avg->depth != IPL_DEPTH_32F )
        CV_ERROR( CV_BadDepth, icvUnsupportedFormat );
    if( avg->nChannels != 1 )
        CV_ERROR( CV_BadNumChannels, icvUnsupportedFormat );

    CV_CALL( CV_CHECK_IMAGE( proj ));
    cvGetImageRawData( proj, &proj_data, &proj_step, &proj_size );
    if( proj->depth != IPL_DEPTH_8U )
        CV_ERROR( CV_BadDepth, icvUnsupportedFormat );
    if( proj->nChannels != 1 )
        CV_ERROR( CV_BadNumChannels, icvUnsupportedFormat );

    if( proj_size != avg_size )
        CV_ERROR( CV_StsBadArg, "Different sizes of projects" );

    if( ioFlags == CV_EIGOBJ_NO_CALLBACK )
    {
        IplImage **eigens = (IplImage**) (((CvInput *) & eigInput)->data);
        float **eigs = (float**) icvAlloc( sizeof( float * ) * nEigObjs );
        int eig_step = 0, old_step = 0;
        CvSize eig_size = avg_size, old_size = avg_size;

        if( eigs == NULL )
            CV_ERROR( CV_StsBadArg, "Insufficient memory" );

        for( i = 0; i < nEigObjs; i++ )
        {
            IplImage *eig = eigens[i];
            float *eig_data;

            CV_CALL( CV_CHECK_IMAGE( eig ));
            cvGetImageRawData( eig, (uchar **) & eig_data, &eig_step, &eig_size );
            if( eig->depth != IPL_DEPTH_32F )
                CV_ERROR( CV_BadDepth, icvUnsupportedFormat );
            if( eig_size != avg_size || eig_size != old_size )
                CV_ERROR( CV_StsBadArg, "Different sizes of objects" );
            if( eig->nChannels != 1 )
                CV_ERROR( CV_BadNumChannels, icvUnsupportedFormat );
            if( i > 0 && eig_step != old_step )
                CV_ERROR( CV_StsBadArg, "Different steps of objects" );

            old_step = eig_step;
            old_size = eig_size;
            eigs[i] = eig_data;
        }

        CV_CALL( icvEigenProjection_8u32fR( nEigObjs,
                                            (void*) eigs,
                                            eig_step,
                                            ioFlags,
                                            userData,
                                            coeffs,
                                            avg_data,
                                            avg_step,
                                            proj_data,
                                            proj_step,
                                            avg_size   ));
        icvFree( (void **) &eigs );
    }

    else

    {
        CV_CALL( icvEigenProjection_8u32fR( nEigObjs,
                                            eigInput,
                                            avg_step,
                                            ioFlags,
                                            userData,
                                            coeffs,
                                            avg_data,
                                            avg_step,
                                            proj_data,
                                            proj_step,
                                            avg_size   ));
    }

    __CLEANUP__;
    __END__;
}

/*  END  OF   FILE  */

⌨️ 快捷键说明

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