diff --git a/modules/ml/include/opencv2/ml/ml.hpp b/modules/ml/include/opencv2/ml/ml.hpp index 68416846a..867da610d 100644 --- a/modules/ml/include/opencv2/ml/ml.hpp +++ b/modules/ml/include/opencv2/ml/ml.hpp @@ -1926,7 +1926,7 @@ public: CvANN_MLP_TrainParams params = CvANN_MLP_TrainParams(), int flags=0 ); - CV_WRAP virtual float predict( const cv::Mat& inputs, cv::Mat& outputs ) const; + CV_WRAP virtual float predict( const cv::Mat& inputs, CV_OUT cv::Mat& outputs ) const; #endif CV_WRAP virtual void clear(); diff --git a/samples/python2/letter_recog.py b/samples/python2/letter_recog.py index c66591d7f..0d4d18f54 100644 --- a/samples/python2/letter_recog.py +++ b/samples/python2/letter_recog.py @@ -90,6 +90,7 @@ class SVM(LetterStatModel): def predict(self, samples): return np.float32( [self.model.predict(s) for s in samples] ) + class MLP(LetterStatModel): def __init__(self): self.model = cv2.ANN_MLP() @@ -109,10 +110,8 @@ class MLP(LetterStatModel): self.model.train(samples, np.float32(new_responses), None, params = params) def predict(self, samples): - pass - #return np.float32( [self.model.predict(s) for s in samples] ) - - + ret, resp = self.model.predict(samples) + return resp.argmax(-1) if __name__ == '__main__':