added ability to read files with different space count
This commit is contained in:
@@ -161,8 +161,21 @@ int CvMLData::read_csv(const char* filename)
|
|||||||
fclose(file);
|
fclose(file);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
for( ptr = buf; *ptr != '\0'; ptr++ )
|
|
||||||
cols_count += (*ptr == delimiter);
|
ptr = buf;
|
||||||
|
while( *ptr == ' ' )
|
||||||
|
ptr++;
|
||||||
|
for( ; *ptr != '\0'; )
|
||||||
|
{
|
||||||
|
if(*ptr == delimiter || *ptr == ' ')
|
||||||
|
{
|
||||||
|
cols_count++;
|
||||||
|
ptr++;
|
||||||
|
while( *ptr == ' ' ) ptr++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
|
||||||
if ( cols_count == 0)
|
if ( cols_count == 0)
|
||||||
{
|
{
|
||||||
@@ -204,7 +217,7 @@ int CvMLData::read_csv(const char* filename)
|
|||||||
str_to_flt_elem( token, el_ptr[cols_count-1], type);
|
str_to_flt_elem( token, el_ptr[cols_count-1], type);
|
||||||
var_types_ptr[cols_count-1] |= type;
|
var_types_ptr[cols_count-1] |= type;
|
||||||
cvSeqPush( seq, el_ptr );
|
cvSeqPush( seq, el_ptr );
|
||||||
if( !fgets_chomp( buf, M, file ) || !strchr( buf, delimiter ) )
|
if( !fgets_chomp( buf, M, file ) )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fclose(file);
|
fclose(file);
|
||||||
@@ -606,7 +619,7 @@ void CvMLData::set_train_test_split( const CvTrainTestSplit * spl)
|
|||||||
CV_ERROR( CV_StsBadArg, "train samples count is not correct" );
|
CV_ERROR( CV_StsBadArg, "train samples count is not correct" );
|
||||||
train_sample_portion = train_sample_portion <= FLT_EPSILON ||
|
train_sample_portion = train_sample_portion <= FLT_EPSILON ||
|
||||||
1 - train_sample_portion <= FLT_EPSILON ? 1 : train_sample_portion;
|
1 - train_sample_portion <= FLT_EPSILON ? 1 : train_sample_portion;
|
||||||
train_sample_count = cvFloor( train_sample_portion * sample_count );
|
train_sample_count = std::max(1, cvFloor( train_sample_portion * sample_count ));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( train_sample_count == sample_count )
|
if ( train_sample_count == sample_count )
|
||||||
@@ -625,8 +638,10 @@ void CvMLData::set_train_test_split( const CvTrainTestSplit * spl)
|
|||||||
for (int i = 0; i < sample_count; i++ )
|
for (int i = 0; i < sample_count; i++ )
|
||||||
sample_idx[i] = i;
|
sample_idx[i] = i;
|
||||||
train_sample_idx = cvCreateMatHeader( 1, train_sample_count, CV_32SC1 );
|
train_sample_idx = cvCreateMatHeader( 1, train_sample_count, CV_32SC1 );
|
||||||
test_sample_idx = cvCreateMatHeader( 1, test_sample_count, CV_32SC1 );
|
|
||||||
*train_sample_idx = cvMat( 1, train_sample_count, CV_32SC1, &sample_idx[0] );
|
*train_sample_idx = cvMat( 1, train_sample_count, CV_32SC1, &sample_idx[0] );
|
||||||
|
|
||||||
|
CV_Assert(test_sample_count > 0);
|
||||||
|
test_sample_idx = cvCreateMatHeader( 1, test_sample_count, CV_32SC1 );
|
||||||
*test_sample_idx = cvMat( 1, test_sample_count, CV_32SC1, &sample_idx[train_sample_count] );
|
*test_sample_idx = cvMat( 1, test_sample_count, CV_32SC1, &sample_idx[train_sample_count] );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user