From dfaf75f50246159c72a2cdc0e6e63c455894d102 Mon Sep 17 00:00:00 2001 From: Dmitriy Anisimov Date: Sat, 6 Sep 2014 09:29:32 +0400 Subject: [PATCH] moving algorithm type to param --- modules/ml/include/opencv2/ml.hpp | 7 ++++--- modules/ml/src/knearest.cpp | 14 +++++++------- modules/ml/test/test_emknearestkmeans.cpp | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/ml/include/opencv2/ml.hpp b/modules/ml/include/opencv2/ml.hpp index 0a8f01dd03..2030f69ac7 100644 --- a/modules/ml/include/opencv2/ml.hpp +++ b/modules/ml/include/opencv2/ml.hpp @@ -230,8 +230,9 @@ public: class CV_EXPORTS_W_MAP Params { public: - Params(int defaultK=10, bool isclassifier_=true, int Emax_=INT_MAX); + Params(int algorithmType_=BRUTE_FORCE, int defaultK=10, bool isclassifier_=true, int Emax_=INT_MAX); + CV_PROP_RW int algorithmType; CV_PROP_RW int defaultK; CV_PROP_RW bool isclassifier; CV_PROP_RW int Emax; // for implementation with KDTree @@ -243,9 +244,9 @@ public: OutputArray neighborResponses=noArray(), OutputArray dist=noArray() ) const = 0; - enum { DEFAULT=1, KDTREE=2 }; + enum { BRUTE_FORCE=1, KDTREE=2 }; - static Ptr create(const Params& params=Params(), int type=DEFAULT); + static Ptr create(const Params& params=Params()); }; /****************************************************************************************\ diff --git a/modules/ml/src/knearest.cpp b/modules/ml/src/knearest.cpp index 14c799be5b..ac9e95ca0d 100644 --- a/modules/ml/src/knearest.cpp +++ b/modules/ml/src/knearest.cpp @@ -50,14 +50,14 @@ namespace cv { namespace ml { -KNearest::Params::Params(int k, bool isclassifier_, int Emax_) +KNearest::Params::Params(int algorithmType_, int k, bool isclassifier_, int Emax_) : + algorithmType(algorithmType_), + defaultK(k), + isclassifier(isclassifier_), + Emax(Emax_) { - defaultK = k; - isclassifier = isclassifier_; - Emax = Emax_; } - class KNearestImpl : public KNearest { public: @@ -497,9 +497,9 @@ public: Params params; }; -Ptr KNearest::create(const Params& p, int type) +Ptr KNearest::create(const Params& p) { - if (KDTREE==type) + if (KDTREE==p.algorithmType) { return makePtr(p); } diff --git a/modules/ml/test/test_emknearestkmeans.cpp b/modules/ml/test/test_emknearestkmeans.cpp index 8e08170c36..ba0b82b0c7 100644 --- a/modules/ml/test/test_emknearestkmeans.cpp +++ b/modules/ml/test/test_emknearestkmeans.cpp @@ -330,7 +330,7 @@ void CV_KNearestTest::run( int /*start_from*/ ) } // KNearest KDTree implementation - Ptr knearestKdt = KNearest::create(ml::KNearest::Params(), ml::KNearest::KDTREE); + Ptr knearestKdt = KNearest::create(ml::KNearest::Params(ml::KNearest::KDTREE)); knearestKdt->train(trainData, ml::ROW_SAMPLE, trainLabels); knearestKdt->findNearest(testData, 4, bestLabels); if( !calcErr( bestLabels, testLabels, sizes, err, true ) )