码迷,mamicode.com
首页 > 其他好文 > 详细

icvPrecalculate

时间:2015-07-14 15:43:28      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:icvgettrainingdataca   icvprecalculate   opencv源码分析   adaboost   



/*
 *icvPrecalculate
 *作用:计算特征值,并排序
 *具体来说也就是根据训练样本信息和haar特征信息,在函数内部引用icvGetTrainingDataCallback来
 *分批计算正负样本的前numprecalated个haar特征值,并把计算好的特征值进行排序,最后结果存储在data->valcache之中
 */
static
void icvPrecalculate( CvHaarTrainingData* data,          //训练样本信息
                      CvIntHaarFeatures* haarFeatures,   //haar特征信息
                      int numprecalculated )             //预计算特征个数
{
    CV_FUNCNAME( "icvPrecalculate" );

    __BEGIN__;

    icvReleaseHaarTrainingDataCache( &data );

    numprecalculated -= numprecalculated % CV_STUMP_TRAIN_PORTION;
    numprecalculated = MIN( numprecalculated, haarFeatures->count );

    if( numprecalculated > 0 )
    {
        //size_t datasize;
        int m;
        CvUserdata userdata;

        /* private variables */
        #ifdef CV_OPENMP
        CvMat t_data;
        CvMat t_idx;
        int first;
        int t_portion;
        int portion = CV_STUMP_TRAIN_PORTION;      //每批计算特征的数量
        #endif /* CV_OPENMP */

        m = data->sum.rows;                        //确定样本总数量,正负样本数之和

#ifdef CV_COL_ARRANGEMENT
        CV_CALL( data->valcache = cvCreateMat( numprecalculated, m, CV_32FC1 ) );       //下面这三组代码是给data->valcache和data->idxcache分配内存
#else
        CV_CALL( data->valcache = cvCreateMat( m, numprecalculated, CV_32FC1 ) );
#endif
        CV_CALL( data->idxcache = cvCreateMat( numprecalculated, m, CV_IDX_MAT_TYPE ) );

        userdata = cvUserdata( data, haarFeatures );

        #ifdef CV_OPENMP
        #pragma omp parallel for private(t_data, t_idx, first, t_portion)
        for( first = 0; first < numprecalculated; first += portion )
        {
            t_data = *data->valcache;
            t_idx = *data->idxcache;
            t_portion = MIN( portion, (numprecalculated - first) );

            /* indices */
            t_idx.rows = t_portion;             //每批计算特征的个数
            t_idx.data.ptr = data->idxcache->data.ptr + first * ((size_t)t_idx.step);

            /* feature values */
#ifdef CV_COL_ARRANGEMENT
            t_data.rows = t_portion;
            t_data.data.ptr = data->valcache->data.ptr +
                first * ((size_t) t_data.step );
#else
            t_data.cols = t_portion;
            t_data.data.ptr = data->valcache->data.ptr +
                first * ((size_t) CV_ELEM_SIZE( t_data.type ));
#endif
            icvGetTrainingDataCallback( &t_data, NULL, NULL, first, t_portion,
                                        &userdata );
#ifdef CV_COL_ARRANGEMENT
            cvGetSortedIndices( &t_data, &t_idx, 0 );
#else
            cvGetSortedIndices( &t_data, &t_idx, 1 );
#endif

#ifdef CV_VERBOSE
            putc( '.', stderr );
            fflush( stderr );
#endif /* CV_VERBOSE */

        }

#ifdef CV_VERBOSE
        fprintf( stderr, "\n" );
        fflush( stderr );
#endif /* CV_VERBOSE */

        #else
        icvGetTrainingDataCallback( data->valcache, NULL, NULL, 0, numprecalculated,
                                    &userdata );                   //调用icvGetTrainingDataCallback函数计算特征值,把计算好的特征值存储在data->valcache中
#ifdef CV_COL_ARRANGEMENT
        cvGetSortedIndices( data->valcache, data->idxcache, 0 );   //对计算好的特征值data->valcache进行排序,并存储在data->idxcache中
#else
        cvGetSortedIndices( data->valcache, data->idxcache, 1 );
#endif
        #endif /* CV_OPENMP */
    }

    __END__;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

icvPrecalculate

标签:icvgettrainingdataca   icvprecalculate   opencv源码分析   adaboost   

原文地址:http://blog.csdn.net/ding977921830/article/details/46877295

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!