cvReadTrainData
2015-07-10 16:02
246 查看
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__; }
相关文章推荐
- svn冲突:skipped remains conflicted one or more files are in a state.
- New Valid Tracking Metric Now Available in Seller Central
- Contains Duplicate
- CoovaChilli-1.3.0编译时出现main-opt.c:781: error: ‘ptr’ may be used uninitialized in this function的解决方法
- Diesel powered certainly are a very hot favored around the globe
- Similarity in Elasticsearch: A Brief Introduction to the Similarity Models Available
- This file probably contains a syntax error."错误
- MFC 单文档中添加OnPaint
- 更新xcode6 运行报错 Command /usr/bin/codesign failed with exit code 1
- 操作系统(aix\redhat\suse)修改主机名方法
- 我对CONTAINING_RECORD宏的详细解释
- 1 对WinMain的理解
- hdu 5045 - Contest(2014 ACM/ICPC Asia Regional Shanghai Online )概率dp
- 安装配置fail2ban防止暴力破解
- HDU 2476 String painter(区间dp)
- editor dose not contain a main type
- "NO 3D support is available from the host"
- "NO 3D support is available from the host"
- TurboMail为各行业提供个性化邮件系统方案
- Leetcode Factorial Trailing Zeroes