add file globbing
authormarina.kolpakova <marina.kolpakova@itseez.com>
Thu, 6 Dec 2012 08:59:20 +0000 (12:59 +0400)
committermarina.kolpakova <marina.kolpakova@itseez.com>
Fri, 1 Feb 2013 10:34:38 +0000 (14:34 +0400)
apps/sft/include/sft/common.hpp
apps/sft/include/sft/octave.hpp
apps/sft/include/sft/random.hpp
apps/sft/octave.cpp
apps/sft/sft.cpp

index 6d62dfd..e1ad526 100644 (file)
@@ -49,8 +49,12 @@ namespace sft
 {
     using cv::Mat;
     struct ICF;
-    typedef std::vector<ICF>   Icfvector;
 
+    typedef std::string   string;
+
+    typedef std::vector<ICF>           Icfvector;
+    typedef std::vector<sft::string>   svector;
 }
 
+
 #endif
\ No newline at end of file
index 9243ef7..e2b206a 100644 (file)
 namespace sft
 {
 
+class Dataset
+{
+public:
+    Dataset(const sft::string& path, const int octave);
+
+private:
+    svector pos;
+    svector neg;
+};
+
 struct ICF
 {
     ICF(int x, int y, int w, int h, int ch) : bb(cv::Rect(x, y, w, h)), channel(ch) {}
@@ -93,12 +103,13 @@ private:
 class Octave : cv::Boost
 {
 public:
-    Octave();
+    Octave(int logScale);
     virtual ~Octave();
 
     virtual bool train( const cv::Mat& trainData, const cv::Mat& responses, const cv::Mat& varIdx=cv::Mat(),
        const cv::Mat& sampleIdx=cv::Mat(), const cv::Mat& varType=cv::Mat(), const cv::Mat& missingDataMask=cv::Mat());
 
+    int logScale;
 private:
     CvBoostParams params;
 };
index d9d9f78..e184da6 100644 (file)
@@ -1,3 +1,45 @@
+/*M///////////////////////////////////////////////////////////////////////////////////////
+//
+//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
+//
+//  By downloading, copying, installing or using the software you agree to this license.
+//  If you do not agree to this license, do not download, install,
+//  copy or use the software.
+//
+//
+//                           License Agreement
+//                For Open Source Computer Vision Library
+//
+// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
+// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved.
+// Third party copyrights are property of their respective owners.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+//   * Redistribution's of source code must retain the above copyright notice,
+//     this list of conditions and the following disclaimer.
+//
+//   * Redistribution's in binary form must reproduce the above copyright notice,
+//     this list of conditions and the following disclaimer in the documentation
+//     and/or other materials provided with the distribution.
+//
+//   * The name of the copyright holders may not be used to endorse or promote products
+//     derived from this software without specific prior written permission.
+//
+// This software is provided by the copyright holders and contributors "as is" and
+// any express or implied warranties, including, but not limited to, the implied
+// warranties of merchantability and fitness for a particular purpose are disclaimed.
+// In no event shall the Intel Corporation or contributors be liable for any direct,
+// indirect, incidental, special, exemplary, or consequential damages
+// (including, but not limited to, procurement of substitute goods or services;
+// loss of use, data, or profits; or business interruption) however caused
+// and on any theory of liability, whether in contract, strict liability,
+// or tort (including negligence or otherwise) arising in any way out of
+// the use of this software, even if advised of the possibility of such damage.
+//
+//M*/
+
 #ifndef __SFT_RANDOM_HPP__
 #define __SFT_RANDOM_HPP__
 
index 60eed96..c8004b7 100644 (file)
 # define show(a, b)
 #endif
 
+#include <glob.h>
+
 // ============ Octave ============ //
-sft::Octave::Octave(){}
+sft::Octave::Octave(int ls) : logScale(ls) {}
 
 sft::Octave::~Octave(){}
 
@@ -121,4 +123,50 @@ void sft::FeaturePool::fill(int desired)
         if (std::find(pool.begin(), pool.end(),f) == pool.end())
             pool.push_back(f);
     }
+}
+
+// ============ Dataset ============ //
+namespace {
+using namespace sft;
+
+string itoa(long i)
+{
+    char s[65];
+    sprintf(s, "%ld", i);
+    return std::string(s);
+}
+
+void glob(const string& path, svector& ret)
+{
+    glob_t glob_result;
+    glob(path.c_str(), GLOB_TILDE, 0, &glob_result);
+
+    ret.clear();
+    ret.reserve(glob_result.gl_pathc);
+
+    for(uint i = 0; i < glob_result.gl_pathc; ++i)
+    {
+        ret.push_back(std::string(glob_result.gl_pathv[i]));
+        // dprintf("%s\n", ret[i].c_str());
+    }
+
+    globfree(&glob_result);
+}
+}
+// in the default case data folders should be alligned as following:
+// 1. positives: <train or test path>/octave_<octave number>/pos/*.png
+// 2. negatives: <train or test path>/octave_<octave number>/neg/*.png
+Dataset::Dataset(const string& path, const int oct)
+{
+    // dprintf("%s\n", "get dataset file names...");
+
+    // dprintf("%s\n", "Positives globbing...");
+    glob(path + "/pos/octave_" + itoa(oct) + "/*.png", pos);
+
+    // dprintf("%s\n", "Negatives globbing...");
+    glob(path + "/neg/octave_" + itoa(oct) + "/*.png", neg);
+
+    // Check: files not empty
+    CV_Assert(pos.size() != size_t(0));
+    CV_Assert(neg.size() != size_t(0));
 }
\ No newline at end of file
index 7b98071..e671c21 100644 (file)
@@ -51,13 +51,16 @@ int main(int argc, char** argv)
     int nfeatures  = 50;
     int npositives = 10;
     int nnegatives = 10;
+
     int nsamples = npositives + nnegatives;
     cv::Size model(64, 128);
+    std::string path = "/home/kellan/cuda-dev/opencv_extra/testdata/sctrain/rescaled-train-2012-10-27-19-02-52";
 
-    sft::Octave boost;
+    sft::Octave boost(0);
     cv::Mat train_data(nfeatures, nsamples, CV_32FC1);
 
     sft::FeaturePool pool(model, nfeatures);
+    sft::Dataset(path, boost.logScale);
 
     cv::RNG rng;