Commit 8672ae58 authored by marina.kolpakova's avatar marina.kolpakova

fix globbing under win

parent e2de3b0b
...@@ -43,7 +43,6 @@ ...@@ -43,7 +43,6 @@
#include <sft/fpool.hpp> #include <sft/fpool.hpp>
#include <sft/random.hpp> #include <sft/random.hpp>
#include <glob.h>
#include <queue> #include <queue>
// ========= FeaturePool ========= // // ========= FeaturePool ========= //
...@@ -89,8 +88,8 @@ void sft::ICFFeaturePool::fill(int desired) ...@@ -89,8 +88,8 @@ void sft::ICFFeaturePool::fill(int desired)
pool.reserve(nfeatures); pool.reserve(nfeatures);
sft::Random::engine eng(8854342234L); sft::Random::engine eng(8854342234LU);
sft::Random::engine eng_ch(314152314L); sft::Random::engine eng_ch(314152314LU);
sft::Random::uniform chRand(0, N_CHANNELS - 1); sft::Random::uniform chRand(0, N_CHANNELS - 1);
...@@ -142,6 +141,14 @@ string itoa(long i) ...@@ -142,6 +141,14 @@ string itoa(long i)
return std::string(s); return std::string(s);
} }
}
#if !defined (_WIN32) && ! defined(__MINGW32__)
#include <glob.h>
namespace {
using namespace sft;
void glob(const string& path, svector& ret) void glob(const string& path, svector& ret)
{ {
glob_t glob_result; glob_t glob_result;
...@@ -158,7 +165,58 @@ void glob(const string& path, svector& ret) ...@@ -158,7 +165,58 @@ void glob(const string& path, svector& ret)
globfree(&glob_result); globfree(&glob_result);
} }
}
#else
#include <windows.h>
namespace {
using namespace sft;
void glob(const string& refRoot, const string& refExt, svector &refvecFiles)
{
std::string strFilePath; // Filepath
std::string strExtension; // Extension
std::string strPattern = refRoot + "\\*.*";
WIN32_FIND_DATA FileInformation; // File information
HANDLE hFile = ::FindFirstFile(strPattern.c_str(), &FileInformation);
if(hFile == INVALID_HANDLE_VALUE)
CV_Error(CV_StsBadArg, "Your dataset search path is incorrect");
do
{
if(FileInformation.cFileName[0] != '.')
{
strFilePath.erase();
strFilePath = refRoot + "\\" + FileInformation.cFileName;
if( !(FileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
{
// Check extension
strExtension = FileInformation.cFileName;
strExtension = strExtension.substr(strExtension.rfind(".") + 1);
if(strExtension == refExt)
// Save filename
refvecFiles.push_back(strFilePath);
}
}
}
while(::FindNextFile(hFile, &FileInformation) == TRUE);
// Close handle
::FindClose(hFile);
DWORD dwError = ::GetLastError();
if(dwError != ERROR_NO_MORE_FILES)
CV_Error(CV_StsBadArg, "Your dataset search path is incorrect");
}
} }
#endif
// in the default case data folders should be alligned as following: // in the default case data folders should be alligned as following:
// 1. positives: <train or test path>/octave_<octave number>/pos/*.png // 1. positives: <train or test path>/octave_<octave number>/pos/*.png
// 2. negatives: <train or test path>/octave_<octave number>/neg/*.png // 2. negatives: <train or test path>/octave_<octave number>/neg/*.png
...@@ -167,10 +225,19 @@ ScaledDataset::ScaledDataset(const string& path, const int oct) ...@@ -167,10 +225,19 @@ ScaledDataset::ScaledDataset(const string& path, const int oct)
dprintf("%s\n", "get dataset file names..."); dprintf("%s\n", "get dataset file names...");
dprintf("%s\n", "Positives globbing..."); dprintf("%s\n", "Positives globbing...");
#if !defined (_WIN32) && ! defined(__MINGW32__)
glob(path + "/pos/octave_" + itoa(oct) + "/*.png", pos); glob(path + "/pos/octave_" + itoa(oct) + "/*.png", pos);
#else
glob(path + "/pos/octave_" + itoa(oct), "png", pos);
#endif
dprintf("%s\n", "Negatives globbing..."); dprintf("%s\n", "Negatives globbing...");
#if !defined (_WIN32) && ! defined(__MINGW32__)
glob(path + "/neg/octave_" + itoa(oct) + "/*.png", neg); glob(path + "/neg/octave_" + itoa(oct) + "/*.png", neg);
#else
glob(path + "/neg/octave_" + itoa(oct), "png", neg);
#endif
// Check: files not empty // Check: files not empty
CV_Assert(pos.size() != size_t(0)); CV_Assert(pos.size() != size_t(0));
......
...@@ -62,8 +62,7 @@ namespace sft ...@@ -62,8 +62,7 @@ namespace sft
#if defined WITH_DEBUG_OUT #if defined WITH_DEBUG_OUT
# include <stdio.h> # include <stdio.h>
# define dprintf(format, ...) \ # define dprintf(format, ...) printf(format, ##__VA_ARGS__)
do { printf(format, ##__VA_ARGS__); } while (0)
#else #else
# define dprintf(format, ...) # define dprintf(format, ...)
#endif #endif
......
...@@ -60,7 +60,7 @@ struct Config ...@@ -60,7 +60,7 @@ struct Config
// Scaled and shrunk model size. // Scaled and shrunk model size.
cv::Size model(ivector::const_iterator it) const cv::Size model(ivector::const_iterator it) const
{ {
float octave = powf(2, *it); float octave = powf(2.f, *it);
return cv::Size( cvRound(modelWinSize.width * octave) / shrinkage, return cv::Size( cvRound(modelWinSize.width * octave) / shrinkage,
cvRound(modelWinSize.height * octave) / shrinkage ); cvRound(modelWinSize.height * octave) / shrinkage );
} }
...@@ -68,7 +68,7 @@ struct Config ...@@ -68,7 +68,7 @@ struct Config
// Scaled but, not shrunk bounding box for object in sample image. // Scaled but, not shrunk bounding box for object in sample image.
cv::Rect bbox(ivector::const_iterator it) const cv::Rect bbox(ivector::const_iterator it) const
{ {
float octave = powf(2, *it); float octave = powf(2.f, *it);
return cv::Rect( cvRound(offset.x * octave), cvRound(offset.y * octave), return cv::Rect( cvRound(offset.x * octave), cvRound(offset.y * octave),
cvRound(modelWinSize.width * octave), cvRound(modelWinSize.height * octave)); cvRound(modelWinSize.width * octave), cvRound(modelWinSize.height * octave));
} }
......
...@@ -2132,7 +2132,7 @@ template<> CV_EXPORTS void Ptr<CvDTreeSplit>::delete_obj(); ...@@ -2132,7 +2132,7 @@ template<> CV_EXPORTS void Ptr<CvDTreeSplit>::delete_obj();
CV_EXPORTS bool initModule_ml(void); CV_EXPORTS bool initModule_ml(void);
CV_EXPORTS class FeaturePool class CV_EXPORTS FeaturePool
{ {
public: public:
...@@ -2145,7 +2145,7 @@ public: ...@@ -2145,7 +2145,7 @@ public:
virtual ~FeaturePool(); virtual ~FeaturePool();
}; };
class Dataset class CV_EXPORTS Dataset
{ {
public: public:
typedef enum {POSITIVE = 1, NEGATIVE = 2} SampleType; typedef enum {POSITIVE = 1, NEGATIVE = 2} SampleType;
...@@ -2156,7 +2156,7 @@ public: ...@@ -2156,7 +2156,7 @@ public:
}; };
// used for traning single octave scale // used for traning single octave scale
class Octave : cv::Boost class CV_EXPORTS Octave : public cv::Boost
{ {
public: public:
......
...@@ -47,8 +47,7 @@ ...@@ -47,8 +47,7 @@
#if defined WITH_DEBUG_OUT #if defined WITH_DEBUG_OUT
# include <stdio.h> # include <stdio.h>
# define dprintf(format, ...) \ # define dprintf(format, ...) printf(format, ##__VA_ARGS__)
do { printf(format, ##__VA_ARGS__); } while (0)
#else #else
# define dprintf(format, ...) # define dprintf(format, ...)
#endif #endif
...@@ -121,7 +120,6 @@ struct Random ...@@ -121,7 +120,6 @@ struct Random
typedef rnd::uniform_int<int> uniform; typedef rnd::uniform_int<int> uniform;
}; };
} }
#endif #endif
cv::FeaturePool::~FeaturePool(){} cv::FeaturePool::~FeaturePool(){}
...@@ -244,8 +242,8 @@ void cv::Octave::processPositives(const Dataset* dataset, const FeaturePool* poo ...@@ -244,8 +242,8 @@ void cv::Octave::processPositives(const Dataset* dataset, const FeaturePool* poo
void cv::Octave::generateNegatives(const Dataset* dataset, const FeaturePool* pool) void cv::Octave::generateNegatives(const Dataset* dataset, const FeaturePool* pool)
{ {
// ToDo: set seed, use offsets // ToDo: set seed, use offsets
sft::Random::engine eng(65633343L); sft::Random::engine eng(65633343LU);
sft::Random::engine idxEng(764224349868L); sft::Random::engine idxEng(764224349868LU);
int h = boundingBox.height; int h = boundingBox.height;
...@@ -350,7 +348,7 @@ void cv::Octave::traverse(const CvBoostTree* tree, cv::FileStorage& fs, int& nfe ...@@ -350,7 +348,7 @@ void cv::Octave::traverse(const CvBoostTree* tree, cv::FileStorage& fs, int& nfe
void cv::Octave::write( cv::FileStorage &fso, const FeaturePool* pool, InputArray _thresholds) const void cv::Octave::write( cv::FileStorage &fso, const FeaturePool* pool, InputArray _thresholds) const
{ {
CV_Assert(!_thresholds.empty()); CV_Assert(!_thresholds.empty());
cv::Mat used( 1, weak->total * ( pow(2.f, params.max_depth) - 1), CV_32SC1); cv::Mat used( 1, weak->total * ( (int)pow(2.f, params.max_depth) - 1), CV_32SC1);
int* usedPtr = used.ptr<int>(0); int* usedPtr = used.ptr<int>(0);
int nfeatures = 0; int nfeatures = 0;
cv::Mat thresholds = _thresholds.getMat(); cv::Mat thresholds = _thresholds.getMat();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment