moving algorithm type to param
authorDmitriy Anisimov <avdmitry@gmail.com>
Sat, 6 Sep 2014 05:29:32 +0000 (09:29 +0400)
committerDmitriy Anisimov <avdmitry@gmail.com>
Sat, 6 Sep 2014 05:29:32 +0000 (09:29 +0400)
modules/ml/include/opencv2/ml.hpp
modules/ml/src/knearest.cpp
modules/ml/test/test_emknearestkmeans.cpp

index 0a8f01d..2030f69 100644 (file)
@@ -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<KNearest> create(const Params& params=Params(), int type=DEFAULT);
+    static Ptr<KNearest> create(const Params& params=Params());
 };
 
 /****************************************************************************************\
index 14c799b..ac9e95c 100644 (file)
 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> KNearest::create(const Params& p, int type)
+Ptr<KNearest> KNearest::create(const Params& p)
 {
-    if (KDTREE==type)
+    if (KDTREE==p.algorithmType)
     {
         return makePtr<KNearestKDTreeImpl>(p);
     }
index 8e08170..ba0b82b 100644 (file)
@@ -330,7 +330,7 @@ void CV_KNearestTest::run( int /*start_from*/ )
     }
 
     // KNearest KDTree implementation
-    Ptr<KNearest> knearestKdt = KNearest::create(ml::KNearest::Params(), ml::KNearest::KDTREE);
+    Ptr<KNearest> 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 ) )