mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 14:13:15 +08:00
fix globbing under win
This commit is contained in:
parent
e2de3b0b81
commit
8672ae58e2
@ -43,7 +43,6 @@
|
||||
#include <sft/fpool.hpp>
|
||||
#include <sft/random.hpp>
|
||||
|
||||
#include <glob.h>
|
||||
#include <queue>
|
||||
|
||||
// ========= 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 <glob.h>
|
||||
|
||||
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 <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:
|
||||
// 1. positives: <train or test path>/octave_<octave number>/pos/*.png
|
||||
// 2. negatives: <train or test path>/octave_<octave number>/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));
|
||||
|
@ -62,8 +62,7 @@ namespace sft
|
||||
|
||||
#if defined WITH_DEBUG_OUT
|
||||
# include <stdio.h>
|
||||
# define dprintf(format, ...) \
|
||||
do { printf(format, ##__VA_ARGS__); } while (0)
|
||||
# define dprintf(format, ...) printf(format, ##__VA_ARGS__)
|
||||
#else
|
||||
# define dprintf(format, ...)
|
||||
#endif
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -2132,7 +2132,7 @@ template<> CV_EXPORTS void Ptr<CvDTreeSplit>::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:
|
||||
|
||||
|
@ -47,8 +47,7 @@
|
||||
|
||||
#if defined WITH_DEBUG_OUT
|
||||
# include <stdio.h>
|
||||
# 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<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<int>(0);
|
||||
int nfeatures = 0;
|
||||
cv::Mat thresholds = _thresholds.getMat();
|
||||
|
Loading…
Reference in New Issue
Block a user