From 554080d89b87dad454ab1e545c56ce320b3015a5 Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Thu, 6 Dec 2012 12:59:20 +0400 Subject: [PATCH] add file globbing --- apps/sft/include/sft/common.hpp | 6 ++++- apps/sft/include/sft/octave.hpp | 13 ++++++++++- apps/sft/include/sft/random.hpp | 42 ++++++++++++++++++++++++++++++++++ apps/sft/octave.cpp | 50 ++++++++++++++++++++++++++++++++++++++++- apps/sft/sft.cpp | 5 ++++- 5 files changed, 112 insertions(+), 4 deletions(-) diff --git a/apps/sft/include/sft/common.hpp b/apps/sft/include/sft/common.hpp index 6d62dfd..e1ad526 100644 --- a/apps/sft/include/sft/common.hpp +++ b/apps/sft/include/sft/common.hpp @@ -49,8 +49,12 @@ namespace sft { using cv::Mat; struct ICF; - typedef std::vector Icfvector; + typedef std::string string; + + typedef std::vector Icfvector; + typedef std::vector svector; } + #endif \ No newline at end of file diff --git a/apps/sft/include/sft/octave.hpp b/apps/sft/include/sft/octave.hpp index 9243ef7..e2b206a 100644 --- a/apps/sft/include/sft/octave.hpp +++ b/apps/sft/include/sft/octave.hpp @@ -49,6 +49,16 @@ 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; }; diff --git a/apps/sft/include/sft/random.hpp b/apps/sft/include/sft/random.hpp index d9d9f78..e184da6 100644 --- a/apps/sft/include/sft/random.hpp +++ b/apps/sft/include/sft/random.hpp @@ -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__ diff --git a/apps/sft/octave.cpp b/apps/sft/octave.cpp index 60eed96..c8004b7 100644 --- a/apps/sft/octave.cpp +++ b/apps/sft/octave.cpp @@ -54,8 +54,10 @@ # define show(a, b) #endif +#include + // ============ 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: /octave_/pos/*.png +// 2. negatives: /octave_/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 diff --git a/apps/sft/sft.cpp b/apps/sft/sft.cpp index 7b98071..e671c21 100644 --- a/apps/sft/sft.cpp +++ b/apps/sft/sft.cpp @@ -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; -- 2.7.4