zoukankan      html  css  js  c++  java
  • cvReadTrainData

    cvReadTrainData的源代码在opencv的cvboost.cpp文件之中,详细内容例如以下所看到的:

    CV_BOOST_IMPL
    void cvReadTrainData( const char* filename,
                          int flags,
                          CvMat** trainData,
                          CvMat** trainClasses )
    {
    
        CV_FUNCNAME( "cvReadTrainData" );
    
        __BEGIN__;
    
        FILE* file;
        int m, n;
        int i, j;
        float val;
        int values_read = -1;
    
        if( filename == NULL )
        {
            CV_ERROR( CV_StsNullPtr, "filename must be specified" );
        }
        if( trainData == NULL )
        {
            CV_ERROR( CV_StsNullPtr, "trainData must be not NULL" );
        }
        if( trainClasses == NULL )
        {
            CV_ERROR( CV_StsNullPtr, "trainClasses must be not NULL" );
        }
    
        *trainData = NULL;
        *trainClasses = NULL;
        file = fopen( filename, "r" );
        if( !file )
        {
            CV_ERROR( CV_StsError, "Unable to open file" );
        }
    
        values_read = fscanf( file, "%d %d", &m, &n );
        CV_Assert(values_read == 2);
    
        if( CV_IS_ROW_SAMPLE( flags ) )
        {
            CV_CALL( *trainData = cvCreateMat( m, n, CV_32FC1 ) );
        }
        else
        {
            CV_CALL( *trainData = cvCreateMat( n, m, CV_32FC1 ) );
        }
    
        CV_CALL( *trainClasses = cvCreateMat( 1, m, CV_32FC1 ) );
    
        for( i = 0; i < m; i++ )
        {
            for( j = 0; j < n; j++ )
            {
                values_read = fscanf( file, "%f", &val );
                CV_Assert(values_read == 1);
                if( CV_IS_ROW_SAMPLE( flags ) )
                {
                    CV_MAT_ELEM( **trainData, float, i, j ) = val;
                }
                else
                {
                    CV_MAT_ELEM( **trainData, float, j, i ) = val;
                }
            }
            values_read = fscanf( file, "%f", &val );
            CV_Assert(values_read == 2);
            CV_MAT_ELEM( **trainClasses, float, 0, i ) = val;
        }
    
        fclose( file );
    
        __END__;
    
    }
    


  • 相关阅读:
    Linux下对拍(A+B问题)
    洛谷 P1043 数字游戏 区间DP
    6.22 集训--DP复习一
    洛谷 P1220 关路灯 区间DP
    A*算法求K短路模板 POJ 2449
    点分治模板 POJ 1741
    HDU
    棋子游戏 51Nod
    数论习题总结
    CodeForces
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/7008607.html
Copyright © 2011-2022 走看看