add file globbing

This commit is contained in:
marina.kolpakova 2012-12-06 12:59:20 +04:00
parent 86973f8ede
commit 554080d89b
5 changed files with 112 additions and 4 deletions

View 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

View File

@ -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;
};

View 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__

View File

@ -54,8 +54,10 @@
# 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));
}

View 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;