From 8672ae58e2d1d99b02a1b726a29ae1d915312656 Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Thu, 10 Jan 2013 00:21:34 +0400 Subject: [PATCH] fix globbing under win --- apps/sft/fpool.cpp | 73 ++++++++++++++++++++++++++++++++++-- apps/sft/include/sft/common.hpp | 3 +- apps/sft/include/sft/config.hpp | 4 +- modules/ml/include/opencv2/ml/ml.hpp | 6 +-- modules/ml/src/octave.cpp | 10 ++--- 5 files changed, 80 insertions(+), 16 deletions(-) diff --git a/apps/sft/fpool.cpp b/apps/sft/fpool.cpp index 7b7c2fa..23b61e1 100644 --- a/apps/sft/fpool.cpp +++ b/apps/sft/fpool.cpp @@ -43,7 +43,6 @@ #include #include -#include #include // ========= FeaturePool ========= // @@ -89,8 +88,8 @@ void sft::ICFFeaturePool::fill(int desired) pool.reserve(nfeatures); - sft::Random::engine eng(8854342234L); - sft::Random::engine eng_ch(314152314L); + sft::Random::engine eng(8854342234LU); + sft::Random::engine eng_ch(314152314LU); sft::Random::uniform chRand(0, N_CHANNELS - 1); @@ -142,6 +141,14 @@ string itoa(long i) return std::string(s); } +} + +#if !defined (_WIN32) && ! defined(__MINGW32__) + +#include + +namespace { +using namespace sft; void glob(const string& path, svector& ret) { glob_t glob_result; @@ -158,7 +165,58 @@ void glob(const string& path, svector& ret) globfree(&glob_result); } + +} +#else + +#include +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: // 1. positives: /octave_/pos/*.png // 2. negatives: /octave_/neg/*.png @@ -167,10 +225,19 @@ ScaledDataset::ScaledDataset(const string& path, const int oct) dprintf("%s\n", "get dataset file names..."); dprintf("%s\n", "Positives globbing..."); + +#if !defined (_WIN32) && ! defined(__MINGW32__) glob(path + "/pos/octave_" + itoa(oct) + "/*.png", pos); +#else + glob(path + "/pos/octave_" + itoa(oct), "png", pos); +#endif dprintf("%s\n", "Negatives globbing..."); +#if !defined (_WIN32) && ! defined(__MINGW32__) glob(path + "/neg/octave_" + itoa(oct) + "/*.png", neg); +#else + glob(path + "/neg/octave_" + itoa(oct), "png", neg); +#endif // Check: files not empty CV_Assert(pos.size() != size_t(0)); diff --git a/apps/sft/include/sft/common.hpp b/apps/sft/include/sft/common.hpp index 0f771cc..4ddc0a3 100644 --- a/apps/sft/include/sft/common.hpp +++ b/apps/sft/include/sft/common.hpp @@ -62,8 +62,7 @@ namespace sft #if defined WITH_DEBUG_OUT # include -# define dprintf(format, ...) \ - do { printf(format, ##__VA_ARGS__); } while (0) +# define dprintf(format, ...) printf(format, ##__VA_ARGS__) #else # define dprintf(format, ...) #endif diff --git a/apps/sft/include/sft/config.hpp b/apps/sft/include/sft/config.hpp index d0ede66..e63b1c9 100644 --- a/apps/sft/include/sft/config.hpp +++ b/apps/sft/include/sft/config.hpp @@ -60,7 +60,7 @@ struct Config // Scaled and shrunk model size. 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, cvRound(modelWinSize.height * octave) / shrinkage ); } @@ -68,7 +68,7 @@ struct Config // Scaled but, not shrunk bounding box for object in sample image. 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), cvRound(modelWinSize.width * octave), cvRound(modelWinSize.height * octave)); } diff --git a/modules/ml/include/opencv2/ml/ml.hpp b/modules/ml/include/opencv2/ml/ml.hpp index 7a1d0ed..c8bf44f 100644 --- a/modules/ml/include/opencv2/ml/ml.hpp +++ b/modules/ml/include/opencv2/ml/ml.hpp @@ -2132,7 +2132,7 @@ template<> CV_EXPORTS void Ptr::delete_obj(); CV_EXPORTS bool initModule_ml(void); -CV_EXPORTS class FeaturePool +class CV_EXPORTS FeaturePool { public: @@ -2145,7 +2145,7 @@ public: virtual ~FeaturePool(); }; -class Dataset +class CV_EXPORTS Dataset { public: typedef enum {POSITIVE = 1, NEGATIVE = 2} SampleType; @@ -2156,7 +2156,7 @@ public: }; // used for traning single octave scale -class Octave : cv::Boost +class CV_EXPORTS Octave : public cv::Boost { public: diff --git a/modules/ml/src/octave.cpp b/modules/ml/src/octave.cpp index 8154d20..9b36b22 100644 --- a/modules/ml/src/octave.cpp +++ b/modules/ml/src/octave.cpp @@ -47,8 +47,7 @@ #if defined WITH_DEBUG_OUT # include -# define dprintf(format, ...) \ - do { printf(format, ##__VA_ARGS__); } while (0) +# define dprintf(format, ...) printf(format, ##__VA_ARGS__) #else # define dprintf(format, ...) #endif @@ -121,7 +120,6 @@ struct Random typedef rnd::uniform_int uniform; }; } - #endif cv::FeaturePool::~FeaturePool(){} @@ -244,8 +242,8 @@ void cv::Octave::processPositives(const Dataset* dataset, const FeaturePool* poo void cv::Octave::generateNegatives(const Dataset* dataset, const FeaturePool* pool) { // ToDo: set seed, use offsets - sft::Random::engine eng(65633343L); - sft::Random::engine idxEng(764224349868L); + sft::Random::engine eng(65633343LU); + sft::Random::engine idxEng(764224349868LU); int h = boundingBox.height; @@ -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 { 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(0); int nfeatures = 0; cv::Mat thresholds = _thresholds.getMat(); -- 2.7.4