Commit dae0dc9c authored by jaco's avatar jaco

BING Objectness porting progress

parent 6f1b6eb4
......@@ -74,7 +74,7 @@ class CV_EXPORTS_W Saliency : public virtual Algorithm
* \return true if the saliency map is computed, false otherwise
*/
//bool computeSaliency( const Mat& image, Mat& saliencyMap );
bool computeSaliency( const InputArray& image, OutputArray& saliencyMap );
bool computeSaliency( const InputArray image, OutputArray saliencyMap );
/**
* \brief Get the name of the specific saliency type
......@@ -84,7 +84,7 @@ class CV_EXPORTS_W Saliency : public virtual Algorithm
protected:
//virtual bool computeSaliencyImpl( const Mat& image, Mat& saliencyMap ) = 0;
virtual bool computeSaliencyImpl( const InputArray& image, OutputArray& saliencyMap ) = 0;
virtual bool computeSaliencyImpl( const InputArray image, OutputArray saliencyMap ) = 0;
String className;
};
......@@ -96,7 +96,7 @@ class CV_EXPORTS_W StaticSaliency : public virtual Saliency
bool computeBinaryMap( const Mat& saliencyMap, Mat& binaryMap );
protected:
virtual bool computeSaliencyImpl( const InputArray& image, OutputArray& saliencyMap ) = 0;
virtual bool computeSaliencyImpl( const InputArray image, OutputArray saliencyMap ) = 0;
};
......@@ -106,7 +106,7 @@ class CV_EXPORTS_W MotionSaliency : public virtual Saliency
protected:
virtual bool computeSaliencyImpl( const InputArray& image, OutputArray& saliencyMap ) = 0;
virtual bool computeSaliencyImpl( const InputArray image, OutputArray saliencyMap ) = 0;
};
......@@ -116,7 +116,7 @@ class CV_EXPORTS_W Objectness : public virtual Saliency
{
protected:
virtual bool computeSaliencyImpl( const InputArray& image, OutputArray& saliencyMap ) = 0;
virtual bool computeSaliencyImpl( const InputArray image, OutputArray saliencyMap ) = 0;
};
......
......@@ -90,7 +90,7 @@ class CV_EXPORTS_W StaticSaliencySpectralResidual : public StaticSaliency
void write( FileStorage& fs ) const;
protected:
bool computeSaliencyImpl( const InputArray& src, OutputArray& dst );
bool computeSaliencyImpl( const InputArray src, OutputArray dst );
AlgorithmInfo* info() const; //{ return 0; }
CV_PROP_RW Ptr<Size> resizedImageSize;
......@@ -124,7 +124,7 @@ class CV_EXPORTS_W MotionSaliencyPBAS : public MotionSaliency
void write( FileStorage& fs ) const;
protected:
bool computeSaliencyImpl( const InputArray& src, OutputArray& dst );
bool computeSaliencyImpl( const InputArray src, OutputArray dst );
AlgorithmInfo* info() const; // { return 0; }
private:
......@@ -154,7 +154,8 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
// The trained model should be prepared before calling this function: loadTrainedModel() or trainStageI() + trainStageII().
// Use numDet to control the final number of proposed bounding boxes, and number of per size (scale and aspect ratio)
void getObjBndBoxes(CMat &img3u, ValStructVec<float, Vec4i> &valBoxes, int numDetPerSize = 120);
void getObjBndBoxesForImage(Mat img, ValStructVec<float, Vec4i> &boxes, int numDetPerSize);
void getObjBndBoxesForSingleImage(Mat img, ValStructVec<float, Vec4i> &boxes, int numDetPerSize);
vector<float> getobjectnessValues();
void setColorSpace(int clr = MAXBGR);
......@@ -167,18 +168,19 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
protected:
bool computeSaliencyImpl( const InputArray& src, OutputArray& dst );
bool computeSaliencyImpl( const InputArray src, OutputArray dst );
AlgorithmInfo* info() const; //{ return 0; }
private: // Parameters
const double _base, _logBase; // base for window size quantization
const int _W; // As described in the paper: #Size, Size(_W, _H) of feature window.
const int _NSS; // Size for non-maximal suppress
const int _maxT, _minT, _numT; // The minimal and maximal dimensions of the template
double _base, _logBase; // base for window size quantization
int _W; // As described in the paper: #Size, Size(_W, _H) of feature window.
int _NSS; // Size for non-maximal suppress
int _maxT, _minT, _numT; // The minimal and maximal dimensions of the template
int _Clr; //
static const char* _clrName[3];
//TODO Probably remove this parameters
//DataSetVOC &_voc; // The dataset for training, testing
std:: string _modelName, _trainDirSI, _bbResDir;
......@@ -187,6 +189,11 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
FilterTIG _tigF; // TIG filter
Mat _svmReW1f; // Re-weight parameters learned at stage II.
// List of the rectangles' objectness value, in the same order as
// vector<Vec4i> objectnessBoundingBox returned by the algorithm (in computeSaliencyImpl function)
vector<float> objectnessValues;
//vector<Vec4i> objectnessBoundingBox;
private: // Help functions
bool filtersLoaded() {int n = _svmSzIdxs.size(); return n > 0 && _svmReW1f.size() == Size(2, n) && _svmFilter.size() == Size(_W, _W);}
......
#include "kyheader.h"
#include "CmFile.h"
// Get image names from a wildcard. Eg: GetNames("D:\\*.jpg", imgNames);
int CmFile::GetNames(CStr &_nameW, vecS &_names, string _dir)
{
_dir = GetFolder(_nameW);
_names.clear();
DIR *dir;
struct dirent *ent;
if((dir = opendir(_dir.c_str()))!=NULL){
//print all the files and directories within directory
while((ent = readdir(dir))!=NULL){
if(ent->d_name[0] == '.')
continue;
if(ent->d_type ==4)
continue;
_names.push_back(ent->d_name);
}
closedir(dir);
} else {
perror("");
return EXIT_FAILURE;
}
return (int)_names.size();
}
int CmFile::GetSubFolders(CStr &folder, vecS &subFolders)
{
subFolders.clear();
string nameWC = GetFolder(folder);//folder + "/*";
DIR *dir;
struct dirent *ent;
if((dir = opendir(nameWC.c_str()))!=NULL){
while((ent = readdir(dir))!=NULL){
if(ent->d_name[0] == '.')
continue;
if(ent->d_type == 4){
subFolders.push_back(ent->d_name);
}
}
closedir(dir);
} else {
perror("");
return EXIT_FAILURE;
}
return (int)subFolders.size();
}
int CmFile::GetNames(CStr& rootFolder, CStr &fileW, vecS &names)
{
GetNames(rootFolder + fileW, names);
vecS subFolders, tmpNames;
int subNum = CmFile::GetSubFolders(rootFolder, subFolders);//
for (int i = 0; i < subNum; i++){
subFolders[i] += "/";
int subNum = GetNames(rootFolder + subFolders[i], fileW, tmpNames);
for (int j = 0; j < subNum; j++)
names.push_back(subFolders[i] + tmpNames[j]);
}
return (int)names.size();
}
int CmFile::GetNamesNE(CStr& nameWC, vecS &names, string dir, string ext)
{
int fNum = GetNames(nameWC, names, dir);
ext = GetExtention(nameWC);
for (int i = 0; i < fNum; i++)
names[i] = GetNameNE(names[i]);
return fNum;
}
int CmFile::GetNamesNE(CStr& rootFolder, CStr &fileW, vecS &names)
{
int fNum = GetNames(rootFolder, fileW, names);
int extS = GetExtention(fileW).size();
for (int i = 0; i < fNum; i++)
names[i].resize(names[i].size() - extS);
return fNum;
}
bool CmFile::MkDir(CStr &_path)
{
if(_path.size() == 0)
return false;
static char buffer[1024];
strcpy(buffer, _S(_path));
#ifdef _WIN32
for (int i = 0; buffer[i] != 0; i ++) {
if (buffer[i] == '\\' || buffer[i] == '/') {
buffer[i] = '\0';
CreateDirectoryA(buffer, 0);
buffer[i] = '/';
}
}
return CreateDirectoryA(_S(_path), 0);
#else
for (int i = 0; buffer[i] != 0; i ++) {
if (buffer[i] == '\\' || buffer[i] == '/') {
buffer[i] = '\0';
mkdir(buffer, 0);
buffer[i] = '/';
}
}
return mkdir(_S(_path), 0);
#endif
}
void CmFile::loadStrList(CStr &fName, vecS & strs, bool flag)
{
ifstream fIn(fName);
string line;
//vecS strs;
while(getline(fIn, line)){
unsigned sz = line.size();
if(flag)
line.resize(sz - 1);
printf("%s\n",_S(line));
strs.push_back(line);
}
//return strs;
}
bool CmFile::writeStrList(CStr &fName, const vecS &strs)
{
FILE *f = fopen(_S(fName), "w");
if (f == NULL)
return false;
for (size_t i = 0; i < strs.size(); i++)
fprintf(f, "%s\n", _S(strs[i]));
fclose(f);
return true;
}
#pragma once
#ifdef _WIN32
#include <windows.h>
#else
#include <iostream>
#include <stdlib.h>
#include <sys/stat.h>
#include <dirent.h>
#endif
struct CmFile
{
static inline string GetFolder(CStr& path);
static inline string GetName(CStr& path);
static inline string GetNameNE(CStr& path);
static inline string GetPathNE(CStr& path);
// 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& rootFolder, CStr &fileW, vecS &names);
static int GetNamesNE(CStr& nameWC, vecS &names, string dir = string(), string ext = string());
static int GetNamesNE(CStr& rootFolder, CStr &fileW, vecS &names);
static inline string GetExtention(CStr name);
static int GetSubFolders(CStr& folder, vecS& subFolders);
static inline string GetWkDir();
static bool MkDir(CStr& path);
static void loadStrList(CStr &fName, vecS &strs, bool flag=false);
static bool writeStrList(CStr &fName, const vecS &strs);
};
/************************************************************************/
/* Implementation of inline functions */
/************************************************************************/
string CmFile::GetFolder(CStr& path)
{
return path.substr(0, path.find_last_of("\\/")+1);
}
string CmFile::GetName(CStr& path)
{
int start = path.find_last_of("\\/")+1;
int end = path.find_last_not_of(' ')+1;
return path.substr(start, end - start);
}
string CmFile::GetNameNE(CStr& path)
{
int start = path.find_last_of("\\/")+1;
int end = path.find_last_of('.');
if (end >= 0)
return path.substr(start, end - start);
else
return path.substr(start, path.find_last_not_of(' ')+1 - start);
}
string CmFile::GetPathNE(CStr& path)
{
int end = path.find_last_of('.');
if (end >= 0)
return path.substr(0, end);
else
return path.substr(0, path.find_last_not_of(' ') + 1);
}
string CmFile::GetExtention(CStr name)
{
return name.substr(name.find_last_of('.'));
}
/************************************************************************/
/* Implementations */
/************************************************************************/
......@@ -87,7 +87,7 @@ void MotionSaliencyPBAS::write( cv::FileStorage& fs ) const
//params.write( fs );
}
bool MotionSaliencyPBAS::computeSaliencyImpl( const InputArray& src, OutputArray& dst )
bool MotionSaliencyPBAS::computeSaliencyImpl( const InputArray src, OutputArray dst )
{
return true;
......
This diff is collapsed.
......@@ -50,7 +50,10 @@ CV_INIT_ALGORITHM( StaticSaliencySpectralResidual, "SALIENCY.SPECTRAL_RESIDUAL",
CV_INIT_ALGORITHM( MotionSaliencyPBAS, "SALIENCY.PBAS",);
CV_INIT_ALGORITHM( ObjectnessBING, "SALIENCY.BING", );
CV_INIT_ALGORITHM( ObjectnessBING, "SALIENCY.BING",
obj.info()->addParam(obj, "_base", obj._base);
obj.info()->addParam(obj, "_NSS", obj._NSS);
obj.info()->addParam(obj, "_W", obj._W));
bool initModule_saliency( void )
{
......
......@@ -97,7 +97,7 @@ void StaticSaliencySpectralResidual::write( cv::FileStorage& fs ) const
//params.write( fs );
}
bool StaticSaliencySpectralResidual::computeSaliencyImpl( const InputArray& image, OutputArray& saliencyMap )
bool StaticSaliencySpectralResidual::computeSaliencyImpl( const InputArray image, OutputArray saliencyMap )
{
Mat grayTemp, grayDown;
std::vector<Mat> mv;
......
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