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
vector<float> getobjectnessValues();
void setColorSpace(int clr = MAXBGR);
void set_modelName(string name);
void set_bbResDir(string dir);
void setModelName(string modelName);
void setBBResDir(string dir);
// Read matrix from binary file
static bool matRead( const std::string& filename, Mat& M);
......
......@@ -9,13 +9,14 @@ using namespace cv;
static const char* keys =
{ "{@saliency_algorithm | | Saliency algorithm <saliencyAlgorithmType.[saliencyAlgorithmTypeSubType]> }"
"{@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()
{
cout << "\nThis example shows the functionality of \"Saliency \""
"Call:\n"
"./example_saliency_computeSaliency <SALIENCY.[saliencyAlgorithmSubType]> <video_name> <start_frame> \n"
"./example_saliency_computeSaliency <saliencyAlgorithmSubType> <video_name> <start_frame> \n"
<< endl;
}
......@@ -26,6 +27,7 @@ int main( int argc, char** argv )
String saliency_algorithm = parser.get<String>( 0 );
String video_name = parser.get<String>( 1 );
int start_frame = parser.get<int>( 2 );
String training_path = parser.get<String>( 3 );
if( saliency_algorithm.empty() || video_name.empty() )
{
......@@ -61,6 +63,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;
if( frame.empty() )
......@@ -70,16 +73,14 @@ int main( int argc, char** argv )
frame.copyTo( image );
if( saliency_algorithm.find( "SPECTRAL_RESIDUAL" ) == 0 )
{
Mat saliencyMap;
if( saliencyAlgorithm->computeSaliency( image, saliencyMap ) )
{
StaticSaliencySpectralResidual spec;
//Mat salMat=saliencyMap.getMat();
spec.computeBinaryMap( saliencyMap, binaryMap );
//saliencyAlgorithm->computeBinaryMap( saliencyMap, binaryMap );
imshow( "Saliency Map", saliencyMap );
imshow( "Original Image", image );
imshow( "Binary Map", binaryMap );
......@@ -89,26 +90,28 @@ int main( int argc, char** argv )
}
else if( saliency_algorithm.find( "BING" ) == 0 )
{
vector<Vec4i> saliencyMap;
//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);
if( training_path.empty() )
{
//bing->set_modelName("home/puja/src/opencv_contrib/modules/saliency/src/ObjectnessTrainedModel/");
//bing->set_bbResDir("/home/puja/src/opencv_contrib/modules/saliency/src/ObjectnessTrainedModel/");
cout << "Path of trained files missing! " << endl;
return -1;
}
if( saliencyAlgorithm->computeSaliency( image, saliencyMap ) )
else
{
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;
vector<Vec4i> saliencyMap;
saliencyAlgorithm.dynamicCast<ObjectnessBING>()->setModelName( training_path );
saliencyAlgorithm.dynamicCast<ObjectnessBING>()->setBBResDir(training_path + "/Results" );
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)
}
void CmFile::loadStrList(CStr &fName, vecS & strs, bool flag)
{
ifstream fIn(fName);
ifstream fIn(fName.c_str());
string line;
//vecS strs;
while(getline(fIn, line)){
......
#include "kyheader.h"
#include "CmShow.h"
#include "opencv2/core.hpp"
#include <opencv2/highgui.hpp>
......
......@@ -53,14 +53,14 @@ struct ValStructVec
void sort( bool descendOrder = true );
const vector<ST> &getSortedStructVal();
vector<pair<VT, int>> getvalIdxes();
vector<pair<VT, int> > getvalIdxes();
void append( const ValStructVec<VT, ST> &newVals, int startV = 0 );
vector<ST> structVals; // struct values
private:
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()
{
return true;
......@@ -81,9 +81,9 @@ template<typename VT, typename ST>
void ValStructVec<VT, ST>::sort( bool descendOrder /* = true */)
{
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
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>
......@@ -96,7 +96,7 @@ const vector<ST>& ValStructVec<VT, ST>::getSortedStructVal()
}
template<typename VT, typename ST>
vector<pair<VT, int>> ValStructVec<VT, ST>::getvalIdxes()
vector<pair<VT, int> > ValStructVec<VT, ST>::getvalIdxes()
{
return valIdxes;
}
......
......@@ -11,11 +11,8 @@
#include <cmath>
#include <time.h>
#include <fstream>
#include <random>
//#include <atlstr.h>
//#include <atltypes.h>
#include <omp.h>
#include <strstream>
// TODO: reference additional headers your program requires here
......@@ -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;
}
auto it = std::find(strList.begin(),strList.end(), word);
vector<String>::iterator it = std::find(strList.begin(),strList.end(), word);
if (it == strList.end())
{
return -1;
} else
{
auto index = std::distance(strList.begin(), it);
vector<String>::iterator index = std::distance(strList.begin(), it);
//cout << "index" <<" "<< index << endl;
return index;
}
......
......@@ -77,17 +77,17 @@ MotionSaliencyPBAS::~MotionSaliencyPBAS()
}
void MotionSaliencyPBAS::read( const cv::FileNode& fn )
void MotionSaliencyPBAS::read( const cv::FileNode& /*fn*/ )
{
//params.read( fn );
}
void MotionSaliencyPBAS::write( cv::FileStorage& fs ) const
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;
......
......@@ -75,21 +75,21 @@ 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 = "/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() );
}
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
......@@ -98,6 +98,8 @@ int ObjectnessBING::loadTrainedModel( string modelName ) // Return -1, 0, or 1
modelName = _modelName;
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 ) );
......
......@@ -74,7 +74,7 @@ Ptr<Saliency> Saliency::create( const String& saliencyType )
//return Ptr<Saliency>();
}
bool Saliency::computeSaliency( const InputArray& image, OutputArray& saliencyMap )
bool Saliency::computeSaliency( const InputArray image, OutputArray saliencyMap )
{
if( image.empty() )
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