Commit c3c9723f authored by berak's avatar berak

text: fix memleak in ocr_hmm_decoder

changed double *p to vector<double>
parent 12cd33c9
...@@ -935,7 +935,7 @@ public: ...@@ -935,7 +935,7 @@ public:
protected: protected:
void normalizeAndZCA(Mat& patches); void normalizeAndZCA(Mat& patches);
double eval_feature(Mat& feature, double* prob_estimates); double eval_feature(Mat& feature, vector<double>& prob_estimates);
private: private:
int nr_class; // number of classes int nr_class; // number of classes
...@@ -1089,7 +1089,7 @@ void OCRHMMClassifierCNN::eval( InputArray _src, vector<int>& out_class, vector< ...@@ -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)); (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); double predict_label = eval_feature(feature,p);
//cout << " Prediction: " << vocabulary[predict_label] << " with probability " << p[0] << endl; //cout << " Prediction: " << vocabulary[predict_label] << " with probability " << p[0] << endl;
if (predict_label < 0) if (predict_label < 0)
...@@ -1107,7 +1107,6 @@ void OCRHMMClassifierCNN::eval( InputArray _src, vector<int>& out_class, vector< ...@@ -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 // normalize for contrast and apply ZCA whitening to a set of image patches
...@@ -1157,11 +1156,8 @@ void OCRHMMClassifierCNN::normalizeAndZCA(Mat& 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 idx=0; idx<nr_feature; idx++)
for(int i=0;i<nr_class;i++) 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 prob_estimates[i] += weights.at<float>(idx,i)*feature.at<double>(0,idx); //TODO use vectorized dot product
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment