Commit d5d6f0a2 authored by jaco's avatar jaco

wip windows compiling error fixed

parent 5e6cef4c
...@@ -101,9 +101,9 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness ...@@ -101,9 +101,9 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
void read(); void read();
void write() const; void write() const;
vector<float> getobjectnessValues(); std::vector<float> getobjectnessValues();
void setTrainingPath( string trainingPath ); void setTrainingPath( std::string trainingPath );
void setBBResDir( string resultsDir ); void setBBResDir( std::string resultsDir );
protected: protected:
bool computeSaliencyImpl( const InputArray image, OutputArray objectnessBoundingBox ); bool computeSaliencyImpl( const InputArray image, OutputArray objectnessBoundingBox );
...@@ -137,7 +137,7 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness ...@@ -137,7 +137,7 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
// List of the rectangles' objectness value, in the same order as // List of the rectangles' objectness value, in the same order as
// the vector<Vec4i> objectnessBoundingBox returned by the algorithm (in computeSaliencyImpl function) // the vector<Vec4i> objectnessBoundingBox returned by the algorithm (in computeSaliencyImpl function)
vector<float> objectnessValues; std::vector<float> objectnessValues;
//vector<Vec4i> objectnessBoundingBox; //vector<Vec4i> objectnessBoundingBox;
private: private:
......
...@@ -42,129 +42,143 @@ ...@@ -42,129 +42,143 @@
#include "kyheader.h" #include "kyheader.h"
#include "CmFile.h" #include "CmFile.h"
// Get image names from a wildcard. Eg: GetNames("D:\\*.jpg", imgNames); // Get image names from a wildcard. Eg: GetNames("D:\\*.jpg", imgNames);
int CmFile::GetNames(CStr &_nameW, vecS &_names, string _dir) int CmFile::GetNames( CStr &_nameW, vecS &_names, std::string _dir )
{ {
_dir = GetFolder(_nameW); _dir = GetFolder( _nameW );
_names.clear(); _names.clear();
DIR *dir; DIR *dir;
struct dirent *ent; struct dirent *ent;
if((dir = opendir(_dir.c_str()))!=NULL){ if( ( dir = opendir( _dir.c_str() ) ) != NULL )
//print all the files and directories within directory {
while((ent = readdir(dir))!=NULL){ //print all the files and directories within directory
if(ent->d_name[0] == '.') while ( ( ent = readdir( dir ) ) != NULL )
continue; {
if(ent->d_type ==4) if( ent->d_name[0] == '.' )
continue; continue;
_names.push_back(ent->d_name); if( ent->d_type == 4 )
} continue;
closedir(dir); _names.push_back( ent->d_name );
} else {
perror("");
return EXIT_FAILURE;
} }
return (int)_names.size(); closedir( dir );
}
else
{
perror( "" );
return EXIT_FAILURE;
}
return (int) _names.size();
} }
int CmFile::GetSubFolders(CStr &folder, vecS &subFolders) int CmFile::GetSubFolders( CStr &folder, vecS &subFolders )
{ {
subFolders.clear(); subFolders.clear();
string nameWC = GetFolder(folder);//folder + "/*"; std::string nameWC = GetFolder( folder ); //folder + "/*";
DIR *dir; DIR *dir;
struct dirent *ent; struct dirent *ent;
if((dir = opendir(nameWC.c_str()))!=NULL){ if( ( dir = opendir( nameWC.c_str() ) ) != NULL )
while((ent = readdir(dir))!=NULL){ {
if(ent->d_name[0] == '.') while ( ( ent = readdir( dir ) ) != NULL )
continue; {
if(ent->d_type == 4){ if( ent->d_name[0] == '.' )
subFolders.push_back(ent->d_name); continue;
} if( ent->d_type == 4 )
} {
closedir(dir); subFolders.push_back( ent->d_name );
} else { }
perror("");
return EXIT_FAILURE;
} }
return (int)subFolders.size(); closedir( dir );
}
else
{
perror( "" );
return EXIT_FAILURE;
}
return (int) subFolders.size();
} }
int CmFile::GetNames(CStr& rootFolder, CStr &fileW, vecS &names) int CmFile::GetNames( CStr& rootFolder, CStr &fileW, vecS &names )
{ {
GetNames(rootFolder + fileW, names); GetNames( rootFolder + fileW, names );
vecS subFolders, tmpNames; vecS subFolders, tmpNames;
int subNum = CmFile::GetSubFolders(rootFolder, subFolders);// int subNum = CmFile::GetSubFolders( rootFolder, subFolders ); //
for (int i = 0; i < subNum; i++){ for ( int i = 0; i < subNum; i++ )
subFolders[i] += "/"; {
int subNum_ = GetNames(rootFolder + subFolders[i], fileW, tmpNames); subFolders[i] += "/";
for (int j = 0; j < subNum_; j++) int subNum_ = GetNames( rootFolder + subFolders[i], fileW, tmpNames );
names.push_back(subFolders[i] + tmpNames[j]); for ( int j = 0; j < subNum_; j++ )
} names.push_back( subFolders[i] + tmpNames[j] );
return (int)names.size(); }
return (int) names.size();
} }
int CmFile::GetNamesNE(CStr& nameWC, vecS &names, string dir, string ext) int CmFile::GetNamesNE( CStr& nameWC, vecS &names, std::string dir, std::string ext )
{ {
int fNum = GetNames(nameWC, names, dir); int fNum = GetNames( nameWC, names, dir );
ext = GetExtention(nameWC); ext = GetExtention( nameWC );
for (int i = 0; i < fNum; i++) for ( int i = 0; i < fNum; i++ )
names[i] = GetNameNE(names[i]); names[i] = GetNameNE( names[i] );
return fNum; return fNum;
} }
int CmFile::GetNamesNE(CStr& rootFolder, CStr &fileW, vecS &names) int CmFile::GetNamesNE( CStr& rootFolder, CStr &fileW, vecS &names )
{ {
int fNum = GetNames(rootFolder, fileW, names); int fNum = GetNames( rootFolder, fileW, names );
int extS = GetExtention(fileW).size(); int extS = GetExtention( fileW ).size();
for (int i = 0; i < fNum; i++) for ( int i = 0; i < fNum; i++ )
names[i].resize(names[i].size() - extS); names[i].resize( names[i].size() - extS );
return fNum; return fNum;
} }
bool CmFile::MkDir(CStr &_path) bool CmFile::MkDir( CStr &_path )
{ {
if(_path.size() == 0) if( _path.size() == 0 )
return false; return false;
static char buffer[1024]; static char buffer[1024];
strcpy(buffer, _S(_path)); strcpy( buffer, _S( _path ) );
#ifdef _WIN32 #ifdef _WIN32
for (int i = 0; buffer[i] != 0; i ++) { for (int i = 0; buffer[i] != 0; i ++)
if (buffer[i] == '\\' || buffer[i] == '/') { {
buffer[i] = '\0'; if (buffer[i] == '\\' || buffer[i] == '/')
CreateDirectoryA(buffer, 0); {
buffer[i] = '/'; buffer[i] = '\0';
} CreateDirectoryA(buffer, 0);
buffer[i] = '/';
} }
return CreateDirectoryA(_S(_path), 0); }
return CreateDirectoryA(_S(_path), 0);
#else #else
for (int i = 0; buffer[i] != 0; i ++) { for ( int i = 0; buffer[i] != 0; i++ )
if (buffer[i] == '\\' || buffer[i] == '/') { {
buffer[i] = '\0'; if( buffer[i] == '\\' || buffer[i] == '/' )
mkdir(buffer, 0); {
buffer[i] = '/'; buffer[i] = '\0';
} mkdir( buffer, 0 );
buffer[i] = '/';
} }
return mkdir(_S(_path), 0); }
return mkdir( _S( _path ), 0 );
#endif #endif
} }
void CmFile::loadStrList(CStr &fName, vecS & strs, bool flag) void CmFile::loadStrList( CStr &fName, vecS & strs, bool flag )
{ {
ifstream fIn(fName.c_str()); std::ifstream fIn( fName.c_str() );
string line; std::string line;
//vecS strs; //vecS strs;
while(getline(fIn, line)){ while ( getline( fIn, line ) )
unsigned sz = line.size(); {
if(flag) unsigned sz = line.size();
line.resize(sz - 1); if( flag )
printf("%s\n",_S(line)); line.resize( sz - 1 );
strs.push_back(line); printf( "%s\n", _S( line ) );
} strs.push_back( line );
//return strs; }
//return strs;
} }
bool CmFile::writeStrList(CStr &fName, const vecS &strs) bool CmFile::writeStrList( CStr &fName, const vecS &strs )
{ {
FILE *f = fopen(_S(fName), "w"); FILE *f = fopen( _S( fName ), "w" );
if (f == NULL) if( f == NULL )
return false; return false;
for (size_t i = 0; i < strs.size(); i++) for ( size_t i = 0; i < strs.size(); i++ )
fprintf(f, "%s\n", _S(strs[i])); fprintf( f, "%s\n", _S( strs[i] ) );
fclose(f); fclose( f );
return true; return true;
} }
...@@ -53,21 +53,21 @@ ...@@ -53,21 +53,21 @@
struct CmFile struct CmFile
{ {
static inline string GetFolder(CStr& path); static inline std::string GetFolder(CStr& path);
static inline string GetName(CStr& path); static inline std::string GetName(CStr& path);
static inline string GetNameNE(CStr& path); static inline std::string GetNameNE(CStr& path);
static inline string GetPathNE(CStr& path); static inline std::string GetPathNE(CStr& path);
// Get file names from a wildcard. Eg: GetNames("D:\\*.jpg", imgNames); // Get file names from a wildcard. Eg: GetNames("D:\\*.jpg", imgNames);
static int GetNames(CStr &nameW, vecS &names, std::string _dir = std::string()); static int GetNames(CStr &nameW, vecS &names, std::string _dir = std::string());
static int GetNames(CStr& rootFolder, CStr &fileW, vecS &names); static int GetNames(CStr& rootFolder, CStr &fileW, vecS &names);
static int GetNamesNE(CStr& nameWC, vecS &names, string dir = string(), string ext = string()); static int GetNamesNE(CStr& nameWC, vecS &names, std::string dir = std::string(), std::string ext = std::string());
static int GetNamesNE(CStr& rootFolder, CStr &fileW, vecS &names); static int GetNamesNE(CStr& rootFolder, CStr &fileW, vecS &names);
static inline string GetExtention(CStr name); static inline std::string GetExtention(CStr name);
static int GetSubFolders(CStr& folder, vecS& subFolders); static int GetSubFolders(CStr& folder, vecS& subFolders);
static inline string GetWkDir(); static inline std::string GetWkDir();
static bool MkDir(CStr& path); static bool MkDir(CStr& path);
static void loadStrList(CStr &fName, vecS &strs, bool flag=false); static void loadStrList(CStr &fName, vecS &strs, bool flag=false);
...@@ -77,19 +77,19 @@ struct CmFile ...@@ -77,19 +77,19 @@ struct CmFile
/************************************************************************/ /************************************************************************/
/* Implementation of inline functions */ /* Implementation of inline functions */
/************************************************************************/ /************************************************************************/
string CmFile::GetFolder(CStr& path) std::string CmFile::GetFolder(CStr& path)
{ {
return path.substr(0, path.find_last_of("\\/")+1); return path.substr(0, path.find_last_of("\\/")+1);
} }
string CmFile::GetName(CStr& path) std::string CmFile::GetName(CStr& path)
{ {
int start = path.find_last_of("\\/")+1; int start = path.find_last_of("\\/")+1;
int end = path.find_last_not_of(' ')+1; int end = path.find_last_not_of(' ')+1;
return path.substr(start, end - start); return path.substr(start, end - start);
} }
string CmFile::GetNameNE(CStr& path) std::string CmFile::GetNameNE(CStr& path)
{ {
int start = path.find_last_of("\\/")+1; int start = path.find_last_of("\\/")+1;
int end = path.find_last_of('.'); int end = path.find_last_of('.');
...@@ -99,7 +99,7 @@ string CmFile::GetNameNE(CStr& path) ...@@ -99,7 +99,7 @@ string CmFile::GetNameNE(CStr& path)
return path.substr(start, path.find_last_not_of(' ')+1 - start); return path.substr(start, path.find_last_not_of(' ')+1 - start);
} }
string CmFile::GetPathNE(CStr& path) std::string CmFile::GetPathNE(CStr& path)
{ {
int end = path.find_last_of('.'); int end = path.find_last_of('.');
if (end >= 0) if (end >= 0)
...@@ -108,7 +108,7 @@ string CmFile::GetPathNE(CStr& path) ...@@ -108,7 +108,7 @@ string CmFile::GetPathNE(CStr& path)
return path.substr(0, path.find_last_not_of(' ') + 1); return path.substr(0, path.find_last_not_of(' ') + 1);
} }
string CmFile::GetExtention(CStr name) std::string CmFile::GetExtention(CStr name)
{ {
return name.substr(name.find_last_of('.')); return name.substr(name.find_last_of('.'));
} }
......
...@@ -46,7 +46,9 @@ ...@@ -46,7 +46,9 @@
typedef pair<int, int> CostiIdx; typedef std::pair<int, int> CostiIdx;
using namespace cv;
Mat CmShow::HistBins(CMat& color3f, CMat& val, CStr& title, bool descendShow, CMat &with) Mat CmShow::HistBins(CMat& color3f, CMat& val, CStr& title, bool descendShow, CMat &with)
{ {
// Prepare data // Prepare data
...@@ -69,10 +71,10 @@ Mat CmShow::HistBins(CMat& color3f, CMat& val, CStr& title, bool descendShow, CM ...@@ -69,10 +71,10 @@ Mat CmShow::HistBins(CMat& color3f, CMat& val, CStr& title, bool descendShow, CM
int* binH = (int*)(binVal1i.data); int* binH = (int*)(binVal1i.data);
Vec3b* binColor = (Vec3b*)(binColor3b.data); Vec3b* binColor = (Vec3b*)(binColor3b.data);
int* binW = (int*)(width1i.data); int* binW = (int*)(width1i.data);
vector<CostiIdx> costIdx(n); std::vector<CostiIdx> costIdx(n);
if (descendShow){ if (descendShow){
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
costIdx[i] = make_pair(binH[i], i); costIdx[i] = std::make_pair(binH[i], i);
sort(costIdx.begin(), costIdx.end(), std::greater<CostiIdx>()); sort(costIdx.begin(), costIdx.end(), std::greater<CostiIdx>());
} }
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
class CmShow class CmShow
{ {
public: public:
static Mat HistBins(CMat& color3f, CMat& val, CStr& title, bool descendShow = false, CMat &with = Mat()); static cv::Mat HistBins(CMat& color3f, CMat& val, CStr& title, bool descendShow = false, CMat &with = cv::Mat());
static void showTinyMat(CStr &title, CMat &m); static void showTinyMat(CStr &title, CMat &m);
static inline void SaveShow(CMat& img, CStr& title); static inline void SaveShow(CMat& img, CStr& title);
}; };
......
...@@ -43,77 +43,86 @@ ...@@ -43,77 +43,86 @@
#include "FilterTIG.h" #include "FilterTIG.h"
#include "CmShow.h" #include "CmShow.h"
using namespace cv;
void FilterTIG::update(CMat &w1f){ void FilterTIG::update( CMat &w1f )
CV_Assert(w1f.cols * w1f.rows == D && w1f.type() == CV_32F && w1f.isContinuous()); {
float b[D], residuals[D]; CV_Assert( w1f.cols * w1f.rows == D && w1f.type() == CV_32F && w1f.isContinuous() );
memcpy(residuals, w1f.data, sizeof(float)*D); float b[D], residuals[D];
for (int i = 0; i < NUM_COMP; i++){ memcpy( residuals, w1f.data, sizeof(float) * D );
float avg = 0; for ( int i = 0; i < NUM_COMP; i++ )
for (int j = 0; j < D; j++){ {
b[j] = residuals[j] >= 0.0f ? 1.0f : -1.0f; float avg = 0;
avg += residuals[j] * b[j]; for ( int j = 0; j < D; j++ )
} {
avg /= D; b[j] = residuals[j] >= 0.0f ? 1.0f : -1.0f;
_coeffs1[i] = avg, _coeffs2[i] = avg*2, _coeffs4[i] = avg*4, _coeffs8[i] = avg*8; avg += residuals[j] * b[j];
for (int j = 0; j < D; j++)
residuals[j] -= avg*b[j];
UINT64 tig = 0;
for (int j = 0; j < D; j++)
tig = (tig << 1) | (b[j] > 0 ? 1 : 0);
_bTIGs[i] = tig;
} }
avg /= D;
_coeffs1[i] = avg, _coeffs2[i] = avg * 2, _coeffs4[i] = avg * 4, _coeffs8[i] = avg * 8;
for ( int j = 0; j < D; j++ )
residuals[j] -= avg * b[j];
UINT64 tig = 0;
for ( int j = 0; j < D; j++ )
tig = ( tig << 1 ) | ( b[j] > 0 ? 1 : 0 );
_bTIGs[i] = tig;
}
} }
void FilterTIG::reconstruct(Mat &w1f){ void FilterTIG::reconstruct( Mat &w1f )
w1f = Mat::zeros(8, 8, CV_32F); {
float *weight = (float*)w1f.data; w1f = Mat::zeros( 8, 8, CV_32F );
for (int i = 0; i < NUM_COMP; i++){ float *weight = (float*) w1f.data;
UINT64 tig = _bTIGs[i]; for ( int i = 0; i < NUM_COMP; i++ )
for (int j = 0; j < D; j++) {
weight[j] += _coeffs1[i] * (((tig >> (63-j)) & 1) ? 1 : -1); UINT64 tig = _bTIGs[i];
} for ( int j = 0; j < D; j++ )
weight[j] += _coeffs1[i] * ( ( ( tig >> ( 63 - j ) ) & 1 ) ? 1 : -1 );
}
} }
// For a W by H gradient magnitude map, find a W-7 by H-7 CV_32F matching score map // For a W by H gradient magnitude map, find a W-7 by H-7 CV_32F matching score map
// Please refer to my paper for definition of the variables used in this function // Please refer to my paper for definition of the variables used in this function
Mat FilterTIG::matchTemplate(const Mat &mag1u){ Mat FilterTIG::matchTemplate( const Mat &mag1u )
const int H = mag1u.rows, W = mag1u.cols; {
const Size sz(W+1, H+1); // Expand original size to avoid dealing with boundary conditions const int H = mag1u.rows, W = mag1u.cols;
Mat_<INT64> Tig1 = Mat_<INT64>::zeros(sz), Tig2 = Mat_<INT64>::zeros(sz); const Size sz( W + 1, H + 1 ); // Expand original size to avoid dealing with boundary conditions
Mat_<INT64> Tig4 = Mat_<INT64>::zeros(sz), Tig8 = Mat_<INT64>::zeros(sz); Mat_<INT64> Tig1 = Mat_<INT64>::zeros( sz ), Tig2 = Mat_<INT64>::zeros( sz );
Mat_<byte> Row1 = Mat_<byte>::zeros(sz), Row2 = Mat_<byte>::zeros(sz); Mat_<INT64> Tig4 = Mat_<INT64>::zeros( sz ), Tig8 = Mat_<INT64>::zeros( sz );
Mat_<byte> Row4 = Mat_<byte>::zeros(sz), Row8 = Mat_<byte>::zeros(sz); Mat_<byte> Row1 = Mat_<byte>::zeros( sz ), Row2 = Mat_<byte>::zeros( sz );
Mat_<float> scores(sz); Mat_<byte> Row4 = Mat_<byte>::zeros( sz ), Row8 = Mat_<byte>::zeros( sz );
for(int y = 1; y <= H; y++){ Mat_<float> scores( sz );
const byte* G = mag1u.ptr<byte>(y-1); for ( int y = 1; y <= H; y++ )
INT64* T1 = Tig1.ptr<INT64>(y); // Binary TIG of current row {
INT64* T2 = Tig2.ptr<INT64>(y); const byte* G = mag1u.ptr<byte>( y - 1 );
INT64* T4 = Tig4.ptr<INT64>(y); INT64* T1 = Tig1.ptr<INT64>( y ); // Binary TIG of current row
INT64* T8 = Tig8.ptr<INT64>(y); INT64* T2 = Tig2.ptr<INT64>( y );
INT64* Tu1 = Tig1.ptr<INT64>(y-1); // Binary TIG of upper row INT64* T4 = Tig4.ptr<INT64>( y );
INT64* Tu2 = Tig2.ptr<INT64>(y-1); INT64* T8 = Tig8.ptr<INT64>( y );
INT64* Tu4 = Tig4.ptr<INT64>(y-1); INT64* Tu1 = Tig1.ptr<INT64>( y - 1 ); // Binary TIG of upper row
INT64* Tu8 = Tig8.ptr<INT64>(y-1); INT64* Tu2 = Tig2.ptr<INT64>( y - 1 );
byte* R1 = Row1.ptr<byte>(y); INT64* Tu4 = Tig4.ptr<INT64>( y - 1 );
byte* R2 = Row2.ptr<byte>(y); INT64* Tu8 = Tig8.ptr<INT64>( y - 1 );
byte* R4 = Row4.ptr<byte>(y); byte* R1 = Row1.ptr<byte>( y );
byte* R8 = Row8.ptr<byte>(y); byte* R2 = Row2.ptr<byte>( y );
float *s = scores.ptr<float>(y); byte* R4 = Row4.ptr<byte>( y );
for (int x = 1; x <= W; x++) { byte* R8 = Row8.ptr<byte>( y );
byte g = G[x-1]; float *s = scores.ptr<float>( y );
R1[x] = (R1[x-1] << 1) | ((g >> 4) & 1); for ( int x = 1; x <= W; x++ )
R2[x] = (R2[x-1] << 1) | ((g >> 5) & 1); {
R4[x] = (R4[x-1] << 1) | ((g >> 6) & 1); byte g = G[x - 1];
R8[x] = (R8[x-1] << 1) | ((g >> 7) & 1); R1[x] = ( R1[x - 1] << 1 ) | ( ( g >> 4 ) & 1 );
T1[x] = (Tu1[x] << 8) | R1[x]; R2[x] = ( R2[x - 1] << 1 ) | ( ( g >> 5 ) & 1 );
T2[x] = (Tu2[x] << 8) | R2[x]; R4[x] = ( R4[x - 1] << 1 ) | ( ( g >> 6 ) & 1 );
T4[x] = (Tu4[x] << 8) | R4[x]; R8[x] = ( R8[x - 1] << 1 ) | ( ( g >> 7 ) & 1 );
T8[x] = (Tu8[x] << 8) | R8[x]; T1[x] = ( Tu1[x] << 8 ) | R1[x];
s[x] = dot(T1[x], T2[x], T4[x], T8[x]); T2[x] = ( Tu2[x] << 8 ) | R2[x];
} T4[x] = ( Tu4[x] << 8 ) | R4[x];
T8[x] = ( Tu8[x] << 8 ) | R8[x];
s[x] = dot( T1[x], T2[x], T4[x], T8[x] );
} }
Mat matchCost1f; }
scores(Rect(8, 8, W-7, H-7)).copyTo(matchCost1f); Mat matchCost1f;
return matchCost1f; scores( Rect( 8, 8, W - 7, H - 7 ) ).copyTo( matchCost1f );
return matchCost1f;
} }
...@@ -47,12 +47,12 @@ public: ...@@ -47,12 +47,12 @@ public:
void update(CMat &w); void update(CMat &w);
// For a W by H gradient magnitude map, find a W-7 by H-7 CV_32F matching score map // For a W by H gradient magnitude map, find a W-7 by H-7 CV_32F matching score map
Mat matchTemplate(const Mat &mag1u); cv::Mat matchTemplate(const cv::Mat &mag1u);
inline float dot(const INT64 tig1, const INT64 tig2, const INT64 tig4, const INT64 tig8); inline float dot(const INT64 tig1, const INT64 tig2, const INT64 tig4, const INT64 tig8);
public: public:
void reconstruct(Mat &w); // For illustration purpose void reconstruct(cv::Mat &w); // For illustration purpose
private: private:
static const int NUM_COMP = 2; // Number of components static const int NUM_COMP = 2; // Number of components
......
...@@ -70,7 +70,7 @@ struct ValStructVec ...@@ -70,7 +70,7 @@ struct ValStructVec
} }
inline void pushBack( const VT& val, const ST& structVal ) inline void pushBack( const VT& val, const ST& structVal )
{ {
valIdxes.push_back( make_pair( val, sz ) ); valIdxes.push_back( std::make_pair( val, sz ) );
structVals.push_back( structVal ); structVals.push_back( structVal );
sz++; sz++;
} }
...@@ -93,21 +93,21 @@ struct ValStructVec ...@@ -93,21 +93,21 @@ struct ValStructVec
} // Should be called after sort } // Should be called after sort
void sort( bool descendOrder = true ); void sort( bool descendOrder = true );
const vector<ST> &getSortedStructVal(); const std::vector<ST> &getSortedStructVal();
vector<pair<VT, int> > getvalIdxes(); std::vector<std::pair<VT, int> > getvalIdxes();
void append( const ValStructVec<VT, ST> &newVals, int startV = 0 ); void append( const ValStructVec<VT, ST> &newVals, int startV = 0 );
vector<ST> structVals; // struct values std::vector<ST> structVals; // struct values
private: private:
int sz; // size of the value struct vector int sz; // size of the value struct vector
vector<pair<VT, int> > valIdxes; // Indexes after sort std::vector<std::pair<VT, int> > valIdxes; // Indexes after sort
bool smaller() bool smaller()
{ {
return true; return true;
} }
; ;
vector<ST> sortedStructVals; std::vector<ST> sortedStructVals;
}; };
template<typename VT, typename ST> template<typename VT, typename ST>
...@@ -122,13 +122,13 @@ template<typename VT, typename ST> ...@@ -122,13 +122,13 @@ template<typename VT, typename ST>
void ValStructVec<VT, ST>::sort( bool descendOrder /* = true */) void ValStructVec<VT, ST>::sort( bool descendOrder /* = true */)
{ {
if( descendOrder ) if( descendOrder )
std::sort( valIdxes.begin(), valIdxes.end(), std::greater<pair<VT, int> >() ); std::sort( valIdxes.begin(), valIdxes.end(), std::greater<std::pair<VT, int> >() );
else else
std::sort( valIdxes.begin(), valIdxes.end(), std::less<pair<VT, int> >() ); std::sort( valIdxes.begin(), valIdxes.end(), std::less<std::pair<VT, int> >() );
} }
template<typename VT, typename ST> template<typename VT, typename ST>
const vector<ST>& ValStructVec<VT, ST>::getSortedStructVal() const std::vector<ST>& ValStructVec<VT, ST>::getSortedStructVal()
{ {
sortedStructVals.resize( sz ); sortedStructVals.resize( sz );
for ( int i = 0; i < sz; i++ ) for ( int i = 0; i < sz; i++ )
...@@ -137,7 +137,7 @@ const vector<ST>& ValStructVec<VT, ST>::getSortedStructVal() ...@@ -137,7 +137,7 @@ const vector<ST>& ValStructVec<VT, ST>::getSortedStructVal()
} }
template<typename VT, typename ST> template<typename VT, typename ST>
vector<pair<VT, int> > ValStructVec<VT, ST>::getvalIdxes() std::vector<std::pair<VT, int> > ValStructVec<VT, ST>::getvalIdxes()
{ {
return valIdxes; return valIdxes;
} }
......
...@@ -69,8 +69,7 @@ ...@@ -69,8 +69,7 @@
//#pragma comment( lib, cvLIB("core")) //#pragma comment( lib, cvLIB("core"))
//#pragma comment( lib, cvLIB("imgproc")) //#pragma comment( lib, cvLIB("imgproc"))
//#pragma comment( lib, cvLIB("highgui")) //#pragma comment( lib, cvLIB("highgui"))
using namespace cv;
using namespace std;
#ifdef WIN32 #ifdef WIN32
/* windows stuff */ /* windows stuff */
#else #else
...@@ -84,9 +83,9 @@ typedef unsigned char byte; ...@@ -84,9 +83,9 @@ typedef unsigned char byte;
typedef std::vector<int> vecI; typedef std::vector<int> vecI;
typedef const std::string CStr; typedef const std::string CStr;
typedef const Mat CMat; typedef const cv::Mat CMat;
typedef std::vector<std::string> vecS; typedef std::vector<std::string> vecS;
typedef std::vector<Mat> vecM; typedef std::vector<cv::Mat> vecM;
typedef std::vector<float> vecF; typedef std::vector<float> vecF;
typedef std::vector<double> vecD; typedef std::vector<double> vecD;
...@@ -106,11 +105,10 @@ enum ...@@ -106,11 +105,10 @@ enum
cv::error(cv::Exception(CV_StsAssert, msg, __FUNCTION__, __FILE__, __LINE__) ); }\ cv::error(cv::Exception(CV_StsAssert, msg, __FUNCTION__, __FILE__, __LINE__) ); }\
} }
using namespace std;
// Return -1 if not in the list // Return -1 if not in the list
template<typename T> template<typename T>
static inline int findFromList( const T &word, const vector<T> &strList ) static inline int findFromList( const T &word, const std::vector<T> &strList )
{ {
//TODO delete test code //TODO delete test code
//cout << "\n\n" << "word" <<" "<< word << endl; //cout << "\n\n" << "word" <<" "<< word << endl;
...@@ -120,7 +118,7 @@ static inline int findFromList( const T &word, const vector<T> &strList ) ...@@ -120,7 +118,7 @@ static inline int findFromList( const T &word, const vector<T> &strList )
//cout << "Size w " << word.size() << " Size L "<< strList[i].size() << endl; //cout << "Size w " << word.size() << " Size L "<< strList[i].size() << endl;
} }
vector<String>::iterator it = std::find( strList.begin(), strList.end(), word ); std::vector<cv::String>::iterator it = std::find( strList.begin(), strList.end(), word );
if( it == strList.end() ) if( it == strList.end() )
{ {
return -1; return -1;
...@@ -149,21 +147,21 @@ template<typename T> inline T sqr( T x ) ...@@ -149,21 +147,21 @@ template<typename T> inline T sqr( T x )
{ {
return x * x; return x * x;
} // out of range risk for T = byte, ... } // out of range risk for T = byte, ...
template<class T, int D> inline T vecSqrDist( const Vec<T, D> &v1, const Vec<T, D> &v2 ) template<class T, int D> inline T vecSqrDist( const cv::Vec<T, D> &v1, const cv::Vec<T, D> &v2 )
{ {
T s = 0; T s = 0;
for ( int i = 0; i < D; i++ ) for ( int i = 0; i < D; i++ )
s += sqr( v1[i] - v2[i] ); s += sqr( v1[i] - v2[i] );
return s; return s;
} // out of range risk for T = byte, ... } // out of range risk for T = byte, ...
template<class T, int D> inline T vecDist( const Vec<T, D> &v1, const Vec<T, D> &v2 ) template<class T, int D> inline T vecDist( const cv::Vec<T, D> &v1, const cv::Vec<T, D> &v2 )
{ {
return sqrt( vecSqrDist( v1, v2 ) ); return sqrt( vecSqrDist( v1, v2 ) );
} // out of range risk for T = byte, ... } // out of range risk for T = byte, ...
inline Rect Vec4i2Rect( Vec4i &v ) inline cv::Rect Vec4i2Rect( cv::Vec4i &v )
{ {
return Rect( Point( v[0] - 1, v[1] - 1 ), Point( v[2], v[3] ) ); return cv::Rect( cv::Point( v[0] - 1, v[1] - 1 ), cv::Point( v[2], v[3] ) );
} }
#ifdef __WIN32 #ifdef __WIN32
......
...@@ -75,21 +75,21 @@ ObjectnessBING::~ObjectnessBING() ...@@ -75,21 +75,21 @@ ObjectnessBING::~ObjectnessBING()
void ObjectnessBING::setColorSpace( int clr ) void ObjectnessBING::setColorSpace( int clr )
{ {
_Clr = clr; _Clr = clr;
_modelName = _trainingPath + "/" + string( format( "ObjNessB%gW%d%s", _base, _W, _clrName[_Clr] ).c_str() ); _modelName = _trainingPath + "/" + std::string( format( "ObjNessB%gW%d%s", _base, _W, _clrName[_Clr] ).c_str() );
_bbResDir = _resultsDir + "/" + string( format( "BBoxesB%gW%d%s/", _base, _W, _clrName[_Clr] ).c_str() ); _bbResDir = _resultsDir + "/" + std::string( format( "BBoxesB%gW%d%s/", _base, _W, _clrName[_Clr] ).c_str() );
} }
void ObjectnessBING::setTrainingPath( string trainingPath ) void ObjectnessBING::setTrainingPath( std::string trainingPath )
{ {
_trainingPath = trainingPath; _trainingPath = trainingPath;
} }
void ObjectnessBING::setBBResDir( string resultsDir ) void ObjectnessBING::setBBResDir( std::string resultsDir )
{ {
_resultsDir = resultsDir; _resultsDir = resultsDir;
} }
int ObjectnessBING::loadTrainedModel( string modelName ) // Return -1, 0, or 1 if partial, none, or all loaded int ObjectnessBING::loadTrainedModel( std::string modelName ) // Return -1, 0, or 1 if partial, none, or all loaded
{ {
if( modelName.size() == 0 ) if( modelName.size() == 0 )
modelName = _modelName; modelName = _modelName;
...@@ -400,15 +400,15 @@ void ObjectnessBING::getObjBndBoxesForSingleImage( Mat img, ValStructVec<float, ...@@ -400,15 +400,15 @@ void ObjectnessBING::getObjBndBoxesForSingleImage( Mat img, ValStructVec<float,
CmFile::MkDir( _bbResDir ); CmFile::MkDir( _bbResDir );
CStr fName = _bbResDir + "bb"; CStr fName = _bbResDir + "bb";
vector<Vec4i> sortedBB = finalBoxes.getSortedStructVal(); std::vector<Vec4i> sortedBB = finalBoxes.getSortedStructVal();
std::ofstream ofs; std::ofstream ofs;
ofs.open( _S( fName + ".txt" ), std::ofstream::out ); ofs.open( _S( fName + ".txt" ), std::ofstream::out );
stringstream dim; std::stringstream dim;
dim << sortedBB.size(); dim << sortedBB.size();
ofs << dim.str() << "\n"; ofs << dim.str() << "\n";
for ( size_t k = 0; k < sortedBB.size(); k++ ) for ( size_t k = 0; k < sortedBB.size(); k++ )
{ {
stringstream str; std::stringstream str;
str << sortedBB[k][0] << " " << sortedBB[k][1] << " " << sortedBB[k][2] << " " << sortedBB[k][3] << "\n"; str << sortedBB[k][0] << " " << sortedBB[k][1] << " " << sortedBB[k][2] << " " << sortedBB[k][3] << "\n";
ofs << str.str(); ofs << str.str();
} }
...@@ -435,7 +435,7 @@ std::string inline removeExtension( std::string const& filename ) ...@@ -435,7 +435,7 @@ std::string inline removeExtension( std::string const& filename )
} }
// Read matrix from binary file // Read matrix from binary file
bool ObjectnessBING::matRead( const string& filename, Mat& _M ) bool ObjectnessBING::matRead( const std::string& filename, Mat& _M )
{ {
String filenamePlusExt( filename.c_str() ); String filenamePlusExt( filename.c_str() );
filenamePlusExt += ".yml.gz"; filenamePlusExt += ".yml.gz";
...@@ -461,7 +461,7 @@ bool ObjectnessBING::matRead( const string& filename, Mat& _M ) ...@@ -461,7 +461,7 @@ bool ObjectnessBING::matRead( const string& filename, Mat& _M )
M.copyTo( _M ); M.copyTo( _M );
return true; return true;
} }
vector<float> ObjectnessBING::getobjectnessValues() std::vector<float> ObjectnessBING::getobjectnessValues()
{ {
return objectnessValues; return objectnessValues;
} }
...@@ -484,7 +484,7 @@ bool ObjectnessBING::computeSaliencyImpl( const InputArray image, OutputArray ob ...@@ -484,7 +484,7 @@ bool ObjectnessBING::computeSaliencyImpl( const InputArray image, OutputArray ob
// List of rectangles returned by objectess function in descending order. // List of rectangles returned by objectess function in descending order.
// At the top there are the rectangles with higher values, ie more // At the top there are the rectangles with higher values, ie more
// likely to have objects in them. // likely to have objects in them.
vector<Vec4i> sortedBB = finalBoxes.getSortedStructVal(); std::vector<Vec4i> sortedBB = finalBoxes.getSortedStructVal();
Mat( sortedBB ).copyTo( objectnessBoundingBox ); Mat( sortedBB ).copyTo( objectnessBoundingBox );
// List of the rectangles' objectness value // List of the rectangles' objectness value
......
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