fclose(file);
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)
{
str_to_flt_elem( token, el_ptr[cols_count-1], type);
var_types_ptr[cols_count-1] |= type;
cvSeqPush( seq, el_ptr );
- if( !fgets_chomp( buf, M, file ) || !strchr( buf, delimiter ) )
+ if( !fgets_chomp( buf, M, file ) )
break;
}
fclose(file);
CV_ERROR( CV_StsBadArg, "train samples count is not correct" );
train_sample_portion = train_sample_portion <= FLT_EPSILON ||
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 )
for (int i = 0; i < sample_count; i++ )
sample_idx[i] = i;
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] );
+
+ 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] );
}