From 3985980b2fca749c7e329a4ef6d7aed3e377a106 Mon Sep 17 00:00:00 2001 From: Cosmin Boaca Date: Tue, 28 Jan 2014 11:54:39 +0200 Subject: [PATCH] Added returnDFVal parameter to parallel CvSVM::predict function --- modules/ml/doc/support_vector_machines.rst | 2 +- modules/ml/include/opencv2/ml.hpp | 2 +- modules/ml/src/svm.cpp | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/ml/doc/support_vector_machines.rst b/modules/ml/doc/support_vector_machines.rst index 14ee12bb4e..9793bd6e3f 100644 --- a/modules/ml/doc/support_vector_machines.rst +++ b/modules/ml/doc/support_vector_machines.rst @@ -242,7 +242,7 @@ Predicts the response for input sample(s). .. ocv:function:: float CvSVM::predict( const CvMat* sample, bool returnDFVal=false ) const -.. ocv:function:: float CvSVM::predict( const CvMat* samples, CvMat* results ) const +.. ocv:function:: float CvSVM::predict( const CvMat* samples, CvMat* results, bool returnDFVal=false ) const .. ocv:pyfunction:: cv2.SVM.predict(sample[, returnDFVal]) -> retval diff --git a/modules/ml/include/opencv2/ml.hpp b/modules/ml/include/opencv2/ml.hpp index 42b90d22d9..7bc1d6fcf0 100644 --- a/modules/ml/include/opencv2/ml.hpp +++ b/modules/ml/include/opencv2/ml.hpp @@ -490,7 +490,7 @@ public: bool balanced=false ); virtual float predict( const CvMat* sample, bool returnDFVal=false ) const; - virtual float predict( const CvMat* samples, CV_OUT CvMat* results ) const; + virtual float predict( const CvMat* samples, CV_OUT CvMat* results, bool returnDFVal=false ) const; CV_WRAP CvSVM( const cv::Mat& trainData, const cv::Mat& responses, const cv::Mat& varIdx=cv::Mat(), const cv::Mat& sampleIdx=cv::Mat(), diff --git a/modules/ml/src/svm.cpp b/modules/ml/src/svm.cpp index f2d3c33ab8..341a817c94 100644 --- a/modules/ml/src/svm.cpp +++ b/modules/ml/src/svm.cpp @@ -2194,18 +2194,20 @@ float CvSVM::predict( const CvMat* sample, bool returnDFVal ) const } struct predict_body_svm : ParallelLoopBody { - predict_body_svm(const CvSVM* _pointer, float* _result, const CvMat* _samples, CvMat* _results) + predict_body_svm(const CvSVM* _pointer, float* _result, const CvMat* _samples, CvMat* _results, bool _returnDFVal) { pointer = _pointer; result = _result; samples = _samples; results = _results; + returnDFVal = _returnDFVal; } const CvSVM* pointer; float* result; const CvMat* samples; CvMat* results; + bool returnDFVal; void operator()( const cv::Range& range ) const { @@ -2213,7 +2215,7 @@ struct predict_body_svm : ParallelLoopBody { { CvMat sample; cvGetRow( samples, &sample, i ); - int r = (int)pointer->predict(&sample); + int r = (int)pointer->predict(&sample, returnDFVal); if (results) results->data.fl[i] = (float)r; if (i == 0) @@ -2222,11 +2224,11 @@ struct predict_body_svm : ParallelLoopBody { } }; -float CvSVM::predict(const CvMat* samples, CV_OUT CvMat* results) const +float CvSVM::predict(const CvMat* samples, CV_OUT CvMat* results, bool returnDFVal) const { float result = 0; cv::parallel_for_(cv::Range(0, samples->rows), - predict_body_svm(this, &result, samples, results) + predict_body_svm(this, &result, samples, results, returnDFVal) ); return result; }