Update inner_functions.cpp

Fix #4958 cv::ml::StatModel::calcError not working for responses of type CV_32S
This commit is contained in:
logic1988 2016-12-14 21:06:57 +08:00 committed by Alexander Alekhin
parent 53f72f18f5
commit de059567d7

View File

@ -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();
@ -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;