switched to non-constant references in Algorithm::addParam, which is more safe.
authorVadim Pisarevsky <no@email>
Sat, 17 Mar 2012 09:50:47 +0000 (09:50 +0000)
committerVadim Pisarevsky <no@email>
Sat, 17 Mar 2012 09:50:47 +0000 (09:50 +0000)
modules/core/include/opencv2/core/core.hpp
modules/core/src/algorithm.cpp
modules/features2d/include/opencv2/features2d/features2d.hpp
modules/features2d/src/detectors.cpp
modules/features2d/src/fast.cpp
modules/features2d/src/mser.cpp
modules/features2d/src/orb.cpp
modules/features2d/src/stardetector.cpp
modules/nonfree/src/sift.cpp
modules/nonfree/src/surf.cpp
samples/cpp/bagofwords_classification.cpp

index 81990c9..dfb807c 100644 (file)
@@ -4294,8 +4294,8 @@ public:
     ~AlgorithmInfo();
     void get(const Algorithm* algo, const char* name, int argType, void* value) const;
     void set(Algorithm* algo, const char* name, int argType, const void* value) const;
-    void addParam_(const Algorithm* algo, const char* name, int argType,
-                   const void* value, bool readOnly, 
+    void addParam_(Algorithm& algo, const char* name, int argType,
+                   void* value, bool readOnly, 
                    Algorithm::Getter getter, Algorithm::Setter setter,
                    const string& help=string());
     string paramHelp(const char* name) const;
@@ -4306,33 +4306,33 @@ public:
     void read(Algorithm* algo, const FileNode& fn) const;
     string name() const;
     
-    void addParam(const Algorithm* algo, const char* name,
-                  const int& value, bool readOnly=false, 
+    void addParam(Algorithm& algo, const char* name,
+                  int& value, bool readOnly=false, 
                   int (Algorithm::*getter)()=0,
                   void (Algorithm::*setter)(int)=0,
                   const string& help=string());
-    void addParam(const Algorithm* algo, const char* name,
-                  const bool& value, bool readOnly=false, 
+    void addParam(Algorithm& algo, const char* name,
+                  bool& value, bool readOnly=false, 
                   int (Algorithm::*getter)()=0,
                   void (Algorithm::*setter)(int)=0,
                   const string& help=string());
-    void addParam(const Algorithm* algo, const char* name,
-                  const double& value, bool readOnly=false, 
+    void addParam(Algorithm& algo, const char* name,
+                  double& value, bool readOnly=false, 
                   double (Algorithm::*getter)()=0,
                   void (Algorithm::*setter)(double)=0,
                   const string& help=string());
-    void addParam(const Algorithm* algo, const char* name,
-                  const string& value, bool readOnly=false, 
+    void addParam(Algorithm& algo, const char* name,
+                  string& value, bool readOnly=false, 
                   string (Algorithm::*getter)()=0,
                   void (Algorithm::*setter)(const string&)=0,
                   const string& help=string());
-    void addParam(const Algorithm* algo, const char* name,
-                  const Mat& value, bool readOnly=false, 
+    void addParam(Algorithm& algo, const char* name,
+                  Mat& value, bool readOnly=false, 
                   Mat (Algorithm::*getter)()=0,
                   void (Algorithm::*setter)(const Mat&)=0,
                   const string& help=string());
-    void addParam(const Algorithm* algo, const char* name,
-                  const Ptr<Algorithm>& value, bool readOnly=false, 
+    void addParam(Algorithm& algo, const char* name,
+                  Ptr<Algorithm>& value, bool readOnly=false, 
                   Ptr<Algorithm> (Algorithm::*getter)()=0,
                   void (Algorithm::*setter)(const Ptr<Algorithm>&)=0,
                   const string& help=string());
index b7b084e..e0ab6c6 100644 (file)
@@ -541,8 +541,8 @@ void AlgorithmInfo::getParams(vector<string>& names) const
 }
     
     
-void AlgorithmInfo::addParam_(const Algorithm* algo, const char* name, int argType,
-                              const void* value, bool readOnly, 
+void AlgorithmInfo::addParam_(Algorithm& algo, const char* name, int argType,
+                              void* value, bool readOnly, 
                               Algorithm::Getter getter, Algorithm::Setter setter,
                               const string& help)
 {
@@ -550,13 +550,13 @@ void AlgorithmInfo::addParam_(const Algorithm* algo, const char* name, int argTy
                argType == Param::REAL || argType == Param::STRING ||
                argType == Param::MAT || argType == Param::ALGORITHM );
     data->params.add(string(name), Param(argType, readOnly,
-                     (int)((size_t)value - (size_t)(void*)algo),
+                     (int)((size_t)value - (size_t)(void*)&algo),
                      getter, setter, help));
 }
     
     
-void AlgorithmInfo::addParam(const Algorithm* algo, const char* name,
-                             const int& value, bool readOnly, 
+void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
+                             int& value, bool readOnly, 
                              int (Algorithm::*getter)(),
                              void (Algorithm::*setter)(int),
                              const string& help)
@@ -565,8 +565,8 @@ void AlgorithmInfo::addParam(const Algorithm* algo, const char* name,
               (Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
 }
 
-void AlgorithmInfo::addParam(const Algorithm* algo, const char* name,
-                             const bool& value, bool readOnly, 
+void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
+                             bool& value, bool readOnly, 
                              int (Algorithm::*getter)(),
                              void (Algorithm::*setter)(int),
                              const string& help)
@@ -575,8 +575,8 @@ void AlgorithmInfo::addParam(const Algorithm* algo, const char* name,
               (Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
 }
     
-void AlgorithmInfo::addParam(const Algorithm* algo, const char* name,
-                             const double& value, bool readOnly, 
+void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
+                             double& value, bool readOnly, 
                              double (Algorithm::*getter)(),
                              void (Algorithm::*setter)(double),
                              const string& help)
@@ -585,8 +585,8 @@ void AlgorithmInfo::addParam(const Algorithm* algo, const char* name,
               (Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
 }
 
-void AlgorithmInfo::addParam(const Algorithm* algo, const char* name,
-                             const string& value, bool readOnly, 
+void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
+                             string& value, bool readOnly, 
                              string (Algorithm::*getter)(),
                              void (Algorithm::*setter)(const string&),
                              const string& help)
@@ -595,8 +595,8 @@ void AlgorithmInfo::addParam(const Algorithm* algo, const char* name,
               (Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
 }
 
-void AlgorithmInfo::addParam(const Algorithm* algo, const char* name,
-                             const Mat& value, bool readOnly, 
+void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
+                             Mat& value, bool readOnly, 
                              Mat (Algorithm::*getter)(),
                              void (Algorithm::*setter)(const Mat&),
                              const string& help)
@@ -605,8 +605,8 @@ void AlgorithmInfo::addParam(const Algorithm* algo, const char* name,
               (Algorithm::Getter)getter, (Algorithm::Setter)setter, help);
 }
     
-void AlgorithmInfo::addParam(const Algorithm* algo, const char* name,
-                             const Ptr<Algorithm>& value, bool readOnly, 
+void AlgorithmInfo::addParam(Algorithm& algo, const char* name,
+                             Ptr<Algorithm>& value, bool readOnly, 
                              Ptr<Algorithm> (Algorithm::*getter)(),
                              void (Algorithm::*setter)(const Ptr<Algorithm>&),
                              const string& help)
index 39bc2c8..d14d9d5 100644 (file)
@@ -481,9 +481,9 @@ public:
 protected:
     virtual void detectImpl( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
 
-    float initFeatureScale;
+    double initFeatureScale;
     int featureScaleLevels;
-    float featureScaleMul;
+    double featureScaleMul;
     
     int initXyStep;
     int initImgBound;
index f68c5e5..8fd8f40 100644 (file)
@@ -160,17 +160,18 @@ AlgorithmInfo* GFTTDetector::info() const
     static volatile bool initialized = false;
     if( !initialized )
     {
-        gftt_info.addParam(this, "nfeatures", nfeatures);
-        gftt_info.addParam(this, "qualityLevel", qualityLevel);
-        gftt_info.addParam(this, "minDistance", minDistance);
-        gftt_info.addParam(this, "useHarrisDetector", useHarrisDetector);
-        gftt_info.addParam(this, "k", k);
+        GFTTDetector obj;
+        gftt_info.addParam(obj, "nfeatures", obj.nfeatures);
+        gftt_info.addParam(obj, "qualityLevel", obj.qualityLevel);
+        gftt_info.addParam(obj, "minDistance", obj.minDistance);
+        gftt_info.addParam(obj, "useHarrisDetector", obj.useHarrisDetector);
+        gftt_info.addParam(obj, "k", obj.k);
         
-        harris_info.addParam(this, "nfeatures", nfeatures);
-        harris_info.addParam(this, "qualityLevel", qualityLevel);
-        harris_info.addParam(this, "minDistance", minDistance);
-        harris_info.addParam(this, "useHarrisDetector", useHarrisDetector);
-        harris_info.addParam(this, "k", k);
+        harris_info.addParam(obj, "nfeatures", obj.nfeatures);
+        harris_info.addParam(obj, "qualityLevel", obj.qualityLevel);
+        harris_info.addParam(obj, "minDistance", obj.minDistance);
+        harris_info.addParam(obj, "useHarrisDetector", obj.useHarrisDetector);
+        harris_info.addParam(obj, "k", obj.k);
         
         initialized = true;
     }
@@ -217,24 +218,25 @@ void DenseFeatureDetector::detectImpl( const Mat& image, vector<KeyPoint>& keypo
     
 
 static Algorithm* createDense() { return new DenseFeatureDetector; }
-
+static AlgorithmInfo dense_info("Feature2D.Dense", createDense);
+    
 AlgorithmInfo* DenseFeatureDetector::info() const
 {
-    static AlgorithmInfo info_("Feature2D.Dense", createDense);
     static volatile bool initialized = false;
     if( !initialized )
     {
-        info_.addParam(this, "initFeatureScale", initFeatureScale);
-        info_.addParam(this, "featureScaleLevels", featureScaleLevels);
-        info_.addParam(this, "featureScaleMul", featureScaleMul);
-        info_.addParam(this, "initXyStep", initXyStep);
-        info_.addParam(this, "initImgBound", initImgBound);
-        info_.addParam(this, "varyXyStepWithScale", varyXyStepWithScale);
-        info_.addParam(this, "varyImgBoundWithScale", varyImgBoundWithScale);
+        DenseFeatureDetector obj;
+        dense_info.addParam(obj, "initFeatureScale", obj.initFeatureScale);
+        dense_info.addParam(obj, "featureScaleLevels", obj.featureScaleLevels);
+        dense_info.addParam(obj, "featureScaleMul", obj.featureScaleMul);
+        dense_info.addParam(obj, "initXyStep", obj.initXyStep);
+        dense_info.addParam(obj, "initImgBound", obj.initImgBound);
+        dense_info.addParam(obj, "varyXyStepWithScale", obj.varyXyStepWithScale);
+        dense_info.addParam(obj, "varyImgBoundWithScale", obj.varyImgBoundWithScale);
         
         initialized = true;
     }
-    return &info_;
+    return &dense_info;
 }    
 
 /*
index 829a6cf..2be9df6 100644 (file)
@@ -400,8 +400,9 @@ AlgorithmInfo* FastFeatureDetector::info() const
     static volatile bool initialized = false;
     if( !initialized )
     {
-        fast_info.addParam(this, "threshold", threshold);
-        fast_info.addParam(this, "nonmaxSuppression", nonmaxSuppression);
+        FastFeatureDetector obj;
+        fast_info.addParam(obj, "threshold", obj.threshold);
+        fast_info.addParam(obj, "nonmaxSuppression", obj.nonmaxSuppression);
         
         initialized = true;
     }
index a930c60..f99bf81 100644 (file)
@@ -1307,15 +1307,16 @@ AlgorithmInfo* MSER::info() const
     static volatile bool initialized = false;
     if( !initialized )
     {
-        mser_info.addParam(this, "delta", delta);
-        mser_info.addParam(this, "minArea", minArea);
-        mser_info.addParam(this, "maxArea", maxArea);
-        mser_info.addParam(this, "maxVariation", maxVariation);
-        mser_info.addParam(this, "minDiversity", minDiversity);
-        mser_info.addParam(this, "maxEvolution", maxEvolution);
-        mser_info.addParam(this, "areaThreshold", areaThreshold);
-        mser_info.addParam(this, "minMargin", minMargin);
-        mser_info.addParam(this, "edgeBlurSize", edgeBlurSize);
+        MSER obj;
+        mser_info.addParam(obj, "delta", obj.delta);
+        mser_info.addParam(obj, "minArea", obj.minArea);
+        mser_info.addParam(obj, "maxArea", obj.maxArea);
+        mser_info.addParam(obj, "maxVariation", obj.maxVariation);
+        mser_info.addParam(obj, "minDiversity", obj.minDiversity);
+        mser_info.addParam(obj, "maxEvolution", obj.maxEvolution);
+        mser_info.addParam(obj, "areaThreshold", obj.areaThreshold);
+        mser_info.addParam(obj, "minMargin", obj.minMargin);
+        mser_info.addParam(obj, "edgeBlurSize", obj.edgeBlurSize);
         
         initialized = true;
     }
index 2219f9c..4255cce 100644 (file)
@@ -556,14 +556,15 @@ AlgorithmInfo* ORB::info() const
     static volatile bool initialized = false;
     if( !initialized )
     {
-        orb_info.addParam(this, "nFeatures", nfeatures);
-        orb_info.addParam(this, "scaleFactor", scaleFactor);
-        orb_info.addParam(this, "nLevels", nlevels);
-        orb_info.addParam(this, "firstLevel", firstLevel);
-        orb_info.addParam(this, "edgeThreshold", edgeThreshold);
-        orb_info.addParam(this, "patchSize", patchSize);
-        orb_info.addParam(this, "WTA_K", WTA_K);
-        orb_info.addParam(this, "scoreType", scoreType);
+        ORB obj;
+        orb_info.addParam(obj, "nFeatures", obj.nfeatures);
+        orb_info.addParam(obj, "scaleFactor", obj.scaleFactor);
+        orb_info.addParam(obj, "nLevels", obj.nlevels);
+        orb_info.addParam(obj, "firstLevel", obj.firstLevel);
+        orb_info.addParam(obj, "edgeThreshold", obj.edgeThreshold);
+        orb_info.addParam(obj, "patchSize", obj.patchSize);
+        orb_info.addParam(obj, "WTA_K", obj.WTA_K);
+        orb_info.addParam(obj, "scoreType", obj.scoreType);
         
         initialized = true;
     }
index 3f75899..60c332e 100644 (file)
@@ -456,11 +456,12 @@ AlgorithmInfo* StarDetector::info() const
     static volatile bool initialized = false;
     if( !initialized )
     {
-        star_info.addParam(this, "maxSize", maxSize);
-        star_info.addParam(this, "responseThreshold", responseThreshold);
-        star_info.addParam(this, "lineThresholdProjected", lineThresholdProjected);
-        star_info.addParam(this, "lineThresholdBinarized", lineThresholdBinarized);
-        star_info.addParam(this, "suppressNonmaxSize", suppressNonmaxSize);
+        StarDetector obj;
+        star_info.addParam(obj, "maxSize", obj.maxSize);
+        star_info.addParam(obj, "responseThreshold", obj.responseThreshold);
+        star_info.addParam(obj, "lineThresholdProjected", obj.lineThresholdProjected);
+        star_info.addParam(obj, "lineThresholdBinarized", obj.lineThresholdBinarized);
+        star_info.addParam(obj, "suppressNonmaxSize", obj.suppressNonmaxSize);
         
         initialized = true;
     }
index bb5e1ef..cca8322 100644 (file)
@@ -683,11 +683,12 @@ AlgorithmInfo* SIFT::info() const
     static volatile bool initialized = false;
     if( !initialized )
     {
-        sift_info.addParam(this, "nFeatures", nfeatures);
-        sift_info.addParam(this, "nOctaveLayers", nOctaveLayers);
-        sift_info.addParam(this, "contrastThreshold", contrastThreshold);
-        sift_info.addParam(this, "edgeThreshold", edgeThreshold);
-        sift_info.addParam(this, "sigma", sigma);
+        SIFT obj;
+        sift_info.addParam(obj, "nFeatures", obj.nfeatures);
+        sift_info.addParam(obj, "nOctaveLayers", obj.nOctaveLayers);
+        sift_info.addParam(obj, "contrastThreshold", obj.contrastThreshold);
+        sift_info.addParam(obj, "edgeThreshold", obj.edgeThreshold);
+        sift_info.addParam(obj, "sigma", obj.sigma);
         
         initialized = true;
     }
index 8e2c1a8..617018c 100644 (file)
@@ -930,11 +930,12 @@ AlgorithmInfo* SURF::info() const
     static volatile bool initialized = false;
     if( !initialized )
     {
-        surf_info.addParam(this, "hessianThreshold", hessianThreshold);
-        surf_info.addParam(this, "nOctaves", nOctaves);
-        surf_info.addParam(this, "nOctaveLayers", nOctaveLayers);
-        surf_info.addParam(this, "extended", extended);
-        surf_info.addParam(this, "upright", upright);
+        SURF obj;
+        surf_info.addParam(obj, "hessianThreshold", obj.hessianThreshold);
+        surf_info.addParam(obj, "nOctaves", obj.nOctaves);
+        surf_info.addParam(obj, "nOctaveLayers", obj.nOctaveLayers);
+        surf_info.addParam(obj, "extended", obj.extended);
+        surf_info.addParam(obj, "upright", obj.upright);
         
         initialized = true;
     }
index 39b808c..7ea03c6 100644 (file)
@@ -1814,7 +1814,7 @@ void VocData::getSortOrder(const vector<float>& values, vector<size_t>& order, b
 void VocData::readFileToString(const string filename, string& file_contents)
 {
     std::ifstream ifs(filename.c_str());
-    if (ifs == false) CV_Error(CV_StsError,"could not open text file");
+    if (!ifs.is_open()) CV_Error(CV_StsError,"could not open text file");
 
     stringstream oss;
     oss << ifs.rdbuf();