Commit 0a162305 authored by jaco's avatar jaco

BING modification after OpenCV master update

parent a76954ad
...@@ -158,8 +158,8 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness ...@@ -158,8 +158,8 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
vector<float> getobjectnessValues(); vector<float> getobjectnessValues();
void setColorSpace(int clr = MAXBGR); void setColorSpace(int clr = MAXBGR);
void set_modelName(string name); void setModelName(string modelName);
void set_bbResDir(string dir); void setBBResDir(string dir);
// Read matrix from binary file // Read matrix from binary file
static bool matRead( const std::string& filename, Mat& M); static bool matRead( const std::string& filename, Mat& M);
......
...@@ -9,13 +9,14 @@ using namespace cv; ...@@ -9,13 +9,14 @@ using namespace cv;
static const char* keys = static const char* keys =
{ "{@saliency_algorithm | | Saliency algorithm <saliencyAlgorithmType.[saliencyAlgorithmTypeSubType]> }" { "{@saliency_algorithm | | Saliency algorithm <saliencyAlgorithmType.[saliencyAlgorithmTypeSubType]> }"
"{@video_name | | video name }" "{@video_name | | video name }"
"{@start_frame |1| Start frame }" }; "{@start_frame |1| Start frame }"
"{@training_path |1| Path of the folder containing the trained files}" };
static void help() static void help()
{ {
cout << "\nThis example shows the functionality of \"Saliency \"" cout << "\nThis example shows the functionality of \"Saliency \""
"Call:\n" "Call:\n"
"./example_saliency_computeSaliency <SALIENCY.[saliencyAlgorithmSubType]> <video_name> <start_frame> \n" "./example_saliency_computeSaliency <saliencyAlgorithmSubType> <video_name> <start_frame> \n"
<< endl; << endl;
} }
...@@ -26,6 +27,7 @@ int main( int argc, char** argv ) ...@@ -26,6 +27,7 @@ int main( int argc, char** argv )
String saliency_algorithm = parser.get<String>( 0 ); String saliency_algorithm = parser.get<String>( 0 );
String video_name = parser.get<String>( 1 ); String video_name = parser.get<String>( 1 );
int start_frame = parser.get<int>( 2 ); int start_frame = parser.get<int>( 2 );
String training_path = parser.get<String>( 3 );
if( saliency_algorithm.empty() || video_name.empty() ) if( saliency_algorithm.empty() || video_name.empty() )
{ {
...@@ -61,6 +63,7 @@ int main( int argc, char** argv ) ...@@ -61,6 +63,7 @@ int main( int argc, char** argv )
Mat binaryMap; Mat binaryMap;
Mat image; Mat image;
//OutputArray saliencyMap( image ); //OutputArray saliencyMap( image );
Mat image2=imread("/home/puja/src/BING_beta2_linux/VOC2007/oneVideoJpeg4Test/0011.jpg");
cap >> frame; cap >> frame;
if( frame.empty() ) if( frame.empty() )
...@@ -70,16 +73,14 @@ int main( int argc, char** argv ) ...@@ -70,16 +73,14 @@ int main( int argc, char** argv )
frame.copyTo( image ); frame.copyTo( image );
if( saliency_algorithm.find( "SPECTRAL_RESIDUAL" ) == 0 ) if( saliency_algorithm.find( "SPECTRAL_RESIDUAL" ) == 0 )
{ {
Mat saliencyMap; Mat saliencyMap;
if( saliencyAlgorithm->computeSaliency( image, saliencyMap ) ) if( saliencyAlgorithm->computeSaliency( image, saliencyMap ) )
{ {
StaticSaliencySpectralResidual spec; StaticSaliencySpectralResidual spec;
//Mat salMat=saliencyMap.getMat();
spec.computeBinaryMap( saliencyMap, binaryMap ); spec.computeBinaryMap( saliencyMap, binaryMap );
//saliencyAlgorithm->computeBinaryMap( saliencyMap, binaryMap );
imshow( "Saliency Map", saliencyMap ); imshow( "Saliency Map", saliencyMap );
imshow( "Original Image", image ); imshow( "Original Image", image );
imshow( "Binary Map", binaryMap ); imshow( "Binary Map", binaryMap );
...@@ -89,26 +90,28 @@ int main( int argc, char** argv ) ...@@ -89,26 +90,28 @@ int main( int argc, char** argv )
} }
else if( saliency_algorithm.find( "BING" ) == 0 ) else if( saliency_algorithm.find( "BING" ) == 0 )
{ {
vector<Vec4i> saliencyMap; if( training_path.empty() )
//Ptr<ObjectnessBING> bing = Saliency::create( "BING" ); {
//bing=static_cast<ObjectnessBING>(saliencyAlgorithm);
saliencyAlgorithm.staticCast<ObjectnessBING>()->set_modelName("home/puja/src/opencv_contrib/modules/saliency/src/ObjectnessTrainedModel/");
saliencyAlgorithm.staticCast<ObjectnessBING>()->set_bbResDir("/home/puja/src/opencv_contrib/modules/saliency/src/ObjectnessTrainedModel/");
//ObjectnessBING bing(saliencyAlgorithm);
//bing->set_modelName("home/puja/src/opencv_contrib/modules/saliency/src/ObjectnessTrainedModel/"); cout << "Path of trained files missing! " << endl;
//bing->set_bbResDir("/home/puja/src/opencv_contrib/modules/saliency/src/ObjectnessTrainedModel/"); return -1;
}
if( saliencyAlgorithm->computeSaliency( image, saliencyMap ) ) else
{ {
std::cout << "-----------------OBJECTNESS-----------" << std::endl; vector<Vec4i> saliencyMap;
std::cout << "OBJECTNESS BOUNDING BOX VECTOR SIZE" << saliencyMap.size() << std::endl; saliencyAlgorithm.dynamicCast<ObjectnessBING>()->setModelName( training_path );
std::cout << " " << saliencyMap[0] << std::endl; saliencyAlgorithm.dynamicCast<ObjectnessBING>()->setBBResDir(training_path + "/Results" );
std::cout << " " << saliencyMap[1] << std::endl;
std::cout << " " << saliencyMap[2] << std::endl; if( saliencyAlgorithm->computeSaliency( image2, saliencyMap ) )
{
std::cout << "-----------------OBJECTNESS-----------" << std::endl;
std::cout << "OBJECTNESS BOUNDING BOX VECTOR SIZE" << saliencyMap.size() << std::endl;
std::cout << " " << saliencyMap[0] << std::endl;
std::cout << " " << saliencyMap[1] << std::endl;
std::cout << " " << saliencyMap[2] << std::endl;
}
} }
} }
......
...@@ -105,7 +105,7 @@ bool CmFile::MkDir(CStr &_path) ...@@ -105,7 +105,7 @@ bool CmFile::MkDir(CStr &_path)
} }
void CmFile::loadStrList(CStr &fName, vecS & strs, bool flag) void CmFile::loadStrList(CStr &fName, vecS & strs, bool flag)
{ {
ifstream fIn(fName); ifstream fIn(fName.c_str());
string line; string line;
//vecS strs; //vecS strs;
while(getline(fIn, line)){ while(getline(fIn, line)){
......
#include "kyheader.h" #include "kyheader.h"
#include "CmShow.h" #include "CmShow.h"
#include "opencv2/core.hpp" #include "opencv2/core.hpp"
#include <opencv2/highgui.hpp>
......
...@@ -53,14 +53,14 @@ struct ValStructVec ...@@ -53,14 +53,14 @@ struct ValStructVec
void sort( bool descendOrder = true ); void sort( bool descendOrder = true );
const vector<ST> &getSortedStructVal(); const vector<ST> &getSortedStructVal();
vector<pair<VT, int>> getvalIdxes(); vector<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 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 vector<pair<VT, int> > valIdxes; // Indexes after sort
bool smaller() bool smaller()
{ {
return true; return true;
...@@ -81,9 +81,9 @@ template<typename VT, typename ST> ...@@ -81,9 +81,9 @@ 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<pair<VT, int> >() );
else else
std::sort( valIdxes.begin(), valIdxes.end(), std::less<pair<VT, int>>() ); std::sort( valIdxes.begin(), valIdxes.end(), std::less<pair<VT, int> >() );
} }
template<typename VT, typename ST> template<typename VT, typename ST>
...@@ -96,7 +96,7 @@ const vector<ST>& ValStructVec<VT, ST>::getSortedStructVal() ...@@ -96,7 +96,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() vector<pair<VT, int> > ValStructVec<VT, ST>::getvalIdxes()
{ {
return valIdxes; return valIdxes;
} }
......
...@@ -11,11 +11,8 @@ ...@@ -11,11 +11,8 @@
#include <cmath> #include <cmath>
#include <time.h> #include <time.h>
#include <fstream> #include <fstream>
#include <random>
//#include <atlstr.h>
//#include <atltypes.h>
#include <omp.h> #include <omp.h>
#include <strstream>
// TODO: reference additional headers your program requires here // TODO: reference additional headers your program requires here
...@@ -77,13 +74,13 @@ static inline int findFromList(const T &word, const vector<T> &strList) { ...@@ -77,13 +74,13 @@ 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;
} }
auto it = std::find(strList.begin(),strList.end(), word); vector<String>::iterator it = std::find(strList.begin(),strList.end(), word);
if (it == strList.end()) if (it == strList.end())
{ {
return -1; return -1;
} else } else
{ {
auto index = std::distance(strList.begin(), it); vector<String>::iterator index = std::distance(strList.begin(), it);
//cout << "index" <<" "<< index << endl; //cout << "index" <<" "<< index << endl;
return index; return index;
} }
......
...@@ -77,17 +77,17 @@ MotionSaliencyPBAS::~MotionSaliencyPBAS() ...@@ -77,17 +77,17 @@ MotionSaliencyPBAS::~MotionSaliencyPBAS()
} }
void MotionSaliencyPBAS::read( const cv::FileNode& fn ) void MotionSaliencyPBAS::read( const cv::FileNode& /*fn*/ )
{ {
//params.read( fn ); //params.read( fn );
} }
void MotionSaliencyPBAS::write( cv::FileStorage& fs ) const void MotionSaliencyPBAS::write( cv::FileStorage& /*fs*/ ) const
{ {
//params.write( fs ); //params.write( fs );
} }
bool MotionSaliencyPBAS::computeSaliencyImpl( const InputArray src, OutputArray dst ) bool MotionSaliencyPBAS::computeSaliencyImpl( const InputArray /*src*/, OutputArray /*dst*/ )
{ {
return true; return true;
......
...@@ -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 = "/home/puja/src/opencv_contrib/modules/saliency/src/ObjectnessTrainedModel/" //_modelName = "/home/puja/src/opencv_contrib/modules/saliency/src/ObjectnessTrainedModel/"
+ string( format( "ObjNessB%gW%d%s", _base, _W, _clrName[_Clr] ).c_str() ); // + 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() ); //_bbResDir = "/home/puja/src/opencv_contrib/modules/saliency/src/" + string( format( "BBoxesB%gW%d%s/", _base, _W, _clrName[_Clr] ).c_str() );
} }
void ObjectnessBING::set_modelName( string name ) void ObjectnessBING::setModelName( string modelName )
{ {
_modelName = name + string( format( "ObjNessB%gW%d%s", _base, _W, _clrName[_Clr] ).c_str() ); _modelName = modelName + string( format( "/ObjNessB%gW%d%s", _base, _W, _clrName[_Clr] ).c_str() );
} }
void ObjectnessBING::set_bbResDir( string dir ) void ObjectnessBING::setBBResDir( string dir )
{ {
_modelName = dir + string( format( "BBoxesB%gW%d%s/", _base, _W, _clrName[_Clr] ).c_str() ); _bbResDir = dir + string( format( "BBoxesB%gW%d%s/", _base, _W, _clrName[_Clr] ).c_str() );
} }
int ObjectnessBING::loadTrainedModel( string modelName ) // Return -1, 0, or 1 if partial, none, or all loaded int ObjectnessBING::loadTrainedModel( string modelName ) // Return -1, 0, or 1 if partial, none, or all loaded
...@@ -98,6 +98,8 @@ int ObjectnessBING::loadTrainedModel( string modelName ) // Return -1, 0, or 1 ...@@ -98,6 +98,8 @@ int ObjectnessBING::loadTrainedModel( string modelName ) // Return -1, 0, or 1
modelName = _modelName; modelName = _modelName;
CStr s1 = modelName + ".wS1", s2 = modelName + ".wS2", sI = modelName + ".idx"; CStr s1 = modelName + ".wS1", s2 = modelName + ".wS2", sI = modelName + ".idx";
Mat filters1f, reW1f, idx1i, show3u; Mat filters1f, reW1f, idx1i, show3u;
cout<<"***TEST*****"<<s1<<endl;
if( !matRead( s1, filters1f ) || !matRead( sI, idx1i ) ) if( !matRead( s1, filters1f ) || !matRead( sI, idx1i ) )
{ {
printf( "Can't load model: %s or %s\n", _S( s1 ), _S( sI ) ); printf( "Can't load model: %s or %s\n", _S( s1 ), _S( sI ) );
......
...@@ -74,7 +74,7 @@ Ptr<Saliency> Saliency::create( const String& saliencyType ) ...@@ -74,7 +74,7 @@ Ptr<Saliency> Saliency::create( const String& saliencyType )
//return Ptr<Saliency>(); //return Ptr<Saliency>();
} }
bool Saliency::computeSaliency( const InputArray& image, OutputArray& saliencyMap ) bool Saliency::computeSaliency( const InputArray image, OutputArray saliencyMap )
{ {
if( image.empty() ) if( image.empty() )
return false; return false;
......
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