Skip to content

Commit

Permalink
Update inner_functions.cpp
Browse files Browse the repository at this point in the history
Fix opencv#4958 cv::ml::StatModel::calcError not working for responses of type CV_32S
  • Loading branch information
logic1988 authored and alalek committed Dec 16, 2016
1 parent 53f72f1 commit de05956
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion modules/ml/src/inner_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ float StatModel::calcError( const Ptr<TrainData>& data, bool testerr, OutputArra
int i, n = (int)sidx.total();
bool isclassifier = isClassifier();
Mat responses = data->getResponses();
int responses_type = responses.type();

if( n == 0 )
n = data->getNSamples();
Expand All @@ -91,7 +92,7 @@ float StatModel::calcError( const Ptr<TrainData>& data, bool testerr, OutputArra
int si = sidx_ptr ? sidx_ptr[i] : i;
Mat sample = layout == ROW_SAMPLE ? samples.row(si) : samples.col(si);
float val = predict(sample);
float val0 = responses.at<float>(si);
float val0 = (responses_type == CV_32S) ? (float)responses.at<int>(si) : responses.at<float>(si);

if( isclassifier )
err += fabs(val - val0) > FLT_EPSILON;
Expand Down

0 comments on commit de05956

Please sign in to comment.