Commit b7696377 authored by jaco's avatar jaco

BING porting finalized

parent 0a162305
set(the_description "Saliency API")
ocv_define_module(saliency opencv_imgproc)
ocv_define_module(saliency opencv_imgproc opencv_highgui)
......@@ -91,7 +91,7 @@ class CV_EXPORTS_W StaticSaliencySpectralResidual : public StaticSaliency
protected:
bool computeSaliencyImpl( const InputArray src, OutputArray dst );
AlgorithmInfo* info() const; //{ return 0; }
AlgorithmInfo* info() const;
CV_PROP_RW Ptr<Size> resizedImageSize;
private:
......@@ -125,7 +125,7 @@ class CV_EXPORTS_W MotionSaliencyPBAS : public MotionSaliency
protected:
bool computeSaliencyImpl( const InputArray src, OutputArray dst );
AlgorithmInfo* info() const; // { return 0; }
AlgorithmInfo* info() const;
private:
//Params params;
......@@ -158,8 +158,8 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
vector<float> getobjectnessValues();
void setColorSpace(int clr = MAXBGR);
void setModelName(string modelName);
void setBBResDir(string dir);
void setTrainingPath(string trainingPath);
void setBBResDir(string resultsDir);
// Read matrix from binary file
static bool matRead( const std::string& filename, Mat& M);
......@@ -171,7 +171,7 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
protected:
bool computeSaliencyImpl( const InputArray src, OutputArray dst );
AlgorithmInfo* info() const; //{ return 0; }
AlgorithmInfo* info() const;
private: // Parameters
double _base, _logBase; // base for window size quantization
......@@ -182,9 +182,8 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
int _Clr; //
static const char* _clrName[3];
//TODO Probably remove this parameters
//DataSetVOC &_voc; // The dataset for training, testing
std:: string _modelName, _bbResDir;
// Names and paths to read model and to store results
std:: string _modelName, _bbResDir, _trainingPath, _resultsDir;
vecI _svmSzIdxs; // Indexes of active size. It's equal to _svmFilters.size() and _svmReW1f.rows
Mat _svmFilter; // Filters learned at stage I, each is a _H by _W CV_32F matrix
......@@ -192,7 +191,7 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
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)
// the vector<Vec4i> objectnessBoundingBox returned by the algorithm (in computeSaliencyImpl function)
vector<float> objectnessValues;
//vector<Vec4i> objectnessBoundingBox;
......@@ -212,7 +211,6 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
static inline int bgrMaxDist(const Vec3b &u, const Vec3b &v) {int b = abs(u[0]-v[0]), g = abs(u[1]-v[1]), r = abs(u[2]-v[2]); b = max(b,g); return max(b,r);}
static inline int vecDist3b(const Vec3b &u, const Vec3b &v) {return abs(u[0]-v[0]) + abs(u[1]-v[1]) + abs(u[2]-v[2]);}
//inline string strVec4i(const Vec4i &vv) const {return std::format("%d, %d, %d, %d", vv[0], vv[1], vv[2], vv[3]);}
//Non-maximal suppress
static void nonMaxSup(CMat &matchCost1f, ValStructVec<float, Point> &matchCost, int NSS = 1, int maxPoint = 50, bool fast = true);
......
......@@ -62,7 +62,7 @@ int main( int argc, char** argv )
Mat binaryMap;
Mat image;
//OutputArray saliencyMap( image );
Mat image2=imread("/home/puja/src/BING_beta2_linux/VOC2007/oneVideoJpeg4Test/0011.jpg");
cap >> frame;
......@@ -101,7 +101,7 @@ int main( int argc, char** argv )
{
vector<Vec4i> saliencyMap;
saliencyAlgorithm.dynamicCast<ObjectnessBING>()->setModelName( training_path );
saliencyAlgorithm.dynamicCast<ObjectnessBING>()->setTrainingPath( training_path );
saliencyAlgorithm.dynamicCast<ObjectnessBING>()->setBBResDir(training_path + "/Results" );
if( saliencyAlgorithm->computeSaliency( image2, saliencyMap ) )
......
......@@ -75,21 +75,18 @@ ObjectnessBING::~ObjectnessBING()
void ObjectnessBING::setColorSpace( int clr )
{
_Clr = clr;
//_modelName = "/home/puja/src/opencv_contrib/modules/saliency/src/ObjectnessTrainedModel/"
// + string( format( "ObjNessB%gW%d%s", _base, _W, _clrName[_Clr] ).c_str() );
//_bbResDir = "/home/puja/src/opencv_contrib/modules/saliency/src/" + string( format( "BBoxesB%gW%d%s/", _base, _W, _clrName[_Clr] ).c_str() );
_modelName = _trainingPath + "/" + 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() );
}
void ObjectnessBING::setModelName( string modelName )
void ObjectnessBING::setTrainingPath( string trainingPath )
{
_modelName = modelName + string( format( "/ObjNessB%gW%d%s", _base, _W, _clrName[_Clr] ).c_str() );
_trainingPath = trainingPath;
}
void ObjectnessBING::setBBResDir( string dir )
void ObjectnessBING::setBBResDir( string resultsDir )
{
_bbResDir = dir + string( format( "BBoxesB%gW%d%s/", _base, _W, _clrName[_Clr] ).c_str() );
_resultsDir = resultsDir;
}
int ObjectnessBING::loadTrainedModel( string modelName ) // Return -1, 0, or 1 if partial, none, or all loaded
......@@ -99,7 +96,6 @@ int ObjectnessBING::loadTrainedModel( string modelName ) // Return -1, 0, or 1
CStr s1 = modelName + ".wS1", s2 = modelName + ".wS2", sI = modelName + ".idx";
Mat filters1f, reW1f, idx1i, show3u;
cout<<"***TEST*****"<<s1<<endl;
if( !matRead( s1, filters1f ) || !matRead( sI, idx1i ) )
{
printf( "Can't load model: %s or %s\n", _S( s1 ), _S( sI ) );
......@@ -144,7 +140,6 @@ void ObjectnessBING::predictBBoxSI( CMat &img3u, ValStructVec<float, Vec4i> &val
resize( img3u, im3u, Size( cvRound( _W * imgW * 1.0 / width ), cvRound( _W * imgH * 1.0 / height ) ) );
gradientMag( im3u, mag1u );
//imwrite(_voc.localDir + format("%d.png", r), mag1u);
//Mat mag1f;
//mag1u.convertTo(mag1f, CV_32F);
//matchTemplate(mag1f, _svmFilter, matchCost1f, CV_TM_CCORR);
......@@ -445,8 +440,6 @@ bool ObjectnessBING::matRead( const string& filename, Mat& _M )
String filenamePlusExt( filename.c_str() );
filenamePlusExt += ".yml.gz";
FileStorage fs2( filenamePlusExt, FileStorage::READ );
//String fileNameString( filename.c_str() );
Mat M;
fs2[String( removeExtension( basename( filename ) ).c_str() )] >> M;
......@@ -492,13 +485,6 @@ bool ObjectnessBING::computeSaliencyImpl( const InputArray image, OutputArray ob
// At the top there are the rectangles with lower values of ​​objectness, ie more
// likely to have objects in them.
vector<Vec4i> sortedBB = finalBoxes.getSortedStructVal();
//objBoundingBox.create( 1, sortedBB.size(), CV_MAKETYPE( CV_32S, CV_MAT_CN(objBoundingBox.type()) ) );
//Mat obj = objBoundingBox.getMat();
//for ( uint i = 0; i < sortedBB.size(); i++ )
// obj.at<Vec4i>( i ) = sortedBB[i];
Mat( sortedBB ).copyTo( objBoundingBox );
// List of the rectangles' objectness value
......
......@@ -51,27 +51,8 @@ Saliency::~Saliency()
Ptr<Saliency> Saliency::create( const String& saliencyType )
{
/*if( saliencyType.find( "STATIC_SALIENCY.SPECTRAL_RESIDUAL" ) == 0 )
{
return Ptr < Saliency > ( new StaticSaliencySpectralResidual() );
}
else if( saliencyType.find( "STATIC_SALIENCY.ITTI_CIO" ) == 0 )
{
//return Ptr < Saliency > ( new SaliencyIttiCIO() );
}
else if( saliencyType.find( "MOTION_SALIENCY.PBAS" ) == 0 )
{
return Ptr < Saliency > ( new MotionSaliencyPBAS() );
}
else if( saliencyType.find( "OBJECTNESS.BING" ) == 0 )
{
return Ptr < Saliency > ( new ObjectnessBING() );
} */
return Algorithm::create<Saliency>( "SALIENCY." + saliencyType );
//CV_Error( -1, "Saliency algorithm type " + saliencyType + " not supported" );
//return Ptr<Saliency>();
}
bool Saliency::computeSaliency( const InputArray image, OutputArray saliencyMap )
......
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