mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-19 02:16:34 +08:00
text: fix memleak in ocr_hmm_decoder
changed double *p to vector<double>
This commit is contained in:
@@ -935,7 +935,7 @@ public:
|
||||
|
||||
protected:
|
||||
void normalizeAndZCA(Mat& patches);
|
||||
double eval_feature(Mat& feature, double* prob_estimates);
|
||||
double eval_feature(Mat& feature, vector<double>& prob_estimates);
|
||||
|
||||
private:
|
||||
int nr_class; // number of classes
|
||||
@@ -1089,7 +1089,7 @@ void OCRHMMClassifierCNN::eval( InputArray _src, vector<int>& out_class, vector<
|
||||
(feature_max.at<double>(0,k)-feature_min.at<double>(0,k));
|
||||
}
|
||||
|
||||
double *p = new double[nr_class];
|
||||
vector<double> p(nr_class, 0);
|
||||
double predict_label = eval_feature(feature,p);
|
||||
//cout << " Prediction: " << vocabulary[predict_label] << " with probability " << p[0] << endl;
|
||||
if (predict_label < 0)
|
||||
@@ -1107,7 +1107,6 @@ void OCRHMMClassifierCNN::eval( InputArray _src, vector<int>& out_class, vector<
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// normalize for contrast and apply ZCA whitening to a set of image patches
|
||||
@@ -1157,11 +1156,8 @@ void OCRHMMClassifierCNN::normalizeAndZCA(Mat& patches)
|
||||
|
||||
}
|
||||
|
||||
double OCRHMMClassifierCNN::eval_feature(Mat& feature, double* prob_estimates)
|
||||
double OCRHMMClassifierCNN::eval_feature(Mat& feature, vector<double>& prob_estimates)
|
||||
{
|
||||
for(int i=0;i<nr_class;i++)
|
||||
prob_estimates[i] = 0;
|
||||
|
||||
for(int idx=0; idx<nr_feature; idx++)
|
||||
for(int i=0;i<nr_class;i++)
|
||||
prob_estimates[i] += weights.at<float>(idx,i)*feature.at<double>(0,idx); //TODO use vectorized dot product
|
||||
|
Reference in New Issue
Block a user