Commit a76954ad authored by jaco's avatar jaco

BING update2

parent f28bdc3d
......@@ -144,8 +144,8 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
ObjectnessBING();
~ObjectnessBING();
void read( const FileNode& fn );
void write( FileStorage& fs ) const;
void read();
void write() const;
// Load trained model.
int loadTrainedModel(std::string modelName = ""); // Return -1, 0, or 1 if partial, none, or all loaded
......@@ -158,6 +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);
// Read matrix from binary file
static bool matRead( const std::string& filename, Mat& M);
......@@ -182,7 +184,7 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
//TODO Probably remove this parameters
//DataSetVOC &_voc; // The dataset for training, testing
std:: string _modelName, _trainDirSI, _bbResDir;
std:: string _modelName, _bbResDir;
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
......
......@@ -70,6 +70,7 @@ int main( int argc, char** argv )
frame.copyTo( image );
if( saliency_algorithm.find( "SPECTRAL_RESIDUAL" ) == 0 )
{
Mat saliencyMap;
......@@ -89,11 +90,22 @@ 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);
//bing->set_modelName("home/puja/src/opencv_contrib/modules/saliency/src/ObjectnessTrainedModel/");
//bing->set_bbResDir("/home/puja/src/opencv_contrib/modules/saliency/src/ObjectnessTrainedModel/");
if( saliencyAlgorithm->computeSaliency( image, saliencyMap ) )
{
std::cout << "-----------------OBJECTNESS-----------" << std::endl;
std::cout << "OBJ BB VECTOR SIZE" << saliencyMap.size() << 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;
......
......@@ -72,8 +72,8 @@ struct ValStructVec
template<typename VT, typename ST>
void ValStructVec<VT, ST>::append( const ValStructVec<VT, ST> &newVals, int startV )
{
int sz = newVals.size();
for ( int i = 0; i < sz; i++ )
int newValsSize = newVals.size();
for ( int i = 0; i < newValsSize; i++ )
pushBack( (float) ( ( i + 300 ) * startV )/*newVals(i)*/, newVals[i] );
}
......
......@@ -77,8 +77,19 @@ 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() );
// _trainDirSI = _voc.localDir + string(format("TrainS1B%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 )
{
_modelName = name + string( format( "ObjNessB%gW%d%s", _base, _W, _clrName[_Clr] ).c_str() );
}
void ObjectnessBING::set_bbResDir( string dir )
{
_modelName = 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
......@@ -388,17 +399,23 @@ void ObjectnessBING::getObjBndBoxesForSingleImage( Mat img, ValStructVec<float,
printf( "Average time for predicting an image (%s) is %gs\n", _clrName[_Clr], tm.TimeInSeconds() );
}
/*CmFile::MkDir(_bbResDir);
//Write on file the total number and the list of rectangles returned by objectess, one for each row.
CmFile::MkDir( _bbResDir );
CStr fName = _bbResDir + "bb";
//vector<Vec4i> sortedBB = finalBoxes.getSortedStructVal();
FILE *f = fopen( _S( fName + ".txt" ), "w" );
fprintf( f, "%d\n", finalBoxes.size() );
for ( size_t k = 0; k < finalBoxes.size(); k++ ){
//fprintf(f, "%g, %s\n", finalBoxes(k), _S(strVec4i(finalBoxes[k])));
//fprintf(f, "%g, %s\n", finalBoxes(k), finalBoxes(k)[0],finalBoxes(k)[1],finalBoxes(k)[2],finalBoxes(k)[3]);
vector<Vec4i> sortedBB = finalBoxes.getSortedStructVal();
std::ofstream ofs;
ofs.open( _S( fName + ".txt" ), std::ofstream::out );
stringstream dim;
dim << sortedBB.size();
ofs << dim.str() << "\n";
for ( size_t k = 0; k < sortedBB.size(); k++ )
{
stringstream str;
str << sortedBB[k][0] << " " << sortedBB[k][1] << " " << sortedBB[k][2] << " " << sortedBB[k][3] << "\n";
ofs << str.str();
}
fclose( f ); */
ofs.close();
}
struct MatchPathSeparator
......@@ -454,12 +471,12 @@ vector<float> ObjectnessBING::getobjectnessValues()
return objectnessValues;
}
void ObjectnessBING::read( const cv::FileNode& fn )
void ObjectnessBING::read()
{
}
void ObjectnessBING::write( cv::FileStorage& fs ) const
void ObjectnessBING::write() const
{
}
......@@ -472,15 +489,15 @@ bool ObjectnessBING::computeSaliencyImpl( const InputArray image, OutputArray ob
// List of rectangles returned by objectess function in ascending order.
// At the top there are the rectangles with lower values of ​​objectness, ie more
// likely to have objects in them.
//vector<Vec4i>
vector<Vec4i> sortedBB = finalBoxes.getSortedStructVal();
objBoundingBox.create( 1, sortedBB.size(), CV_MAKETYPE( CV_32S, CV_MAT_CN(objBoundingBox.type()) ) );
Mat obj = objBoundingBox.getMat();
//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];
for ( uint i = 0; i < sortedBB.size(); i++ )
obj.at<Vec4i>( i ) = sortedBB[i];
Mat( sortedBB ).copyTo( objBoundingBox );
// List of the rectangles' objectness value
unsigned long int valIdxesSize = finalBoxes.getvalIdxes().size();
......
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