Commit a76954ad authored by jaco's avatar jaco

BING update2

parent f28bdc3d
...@@ -144,8 +144,8 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness ...@@ -144,8 +144,8 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
ObjectnessBING(); ObjectnessBING();
~ObjectnessBING(); ~ObjectnessBING();
void read( const FileNode& fn ); void read();
void write( FileStorage& fs ) const; void write() const;
// Load trained model. // Load trained model.
int loadTrainedModel(std::string modelName = ""); // Return -1, 0, or 1 if partial, none, or all loaded 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 ...@@ -158,6 +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 set_bbResDir(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);
...@@ -182,7 +184,7 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness ...@@ -182,7 +184,7 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
//TODO Probably remove this parameters //TODO Probably remove this parameters
//DataSetVOC &_voc; // The dataset for training, testing //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 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 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 ) ...@@ -70,6 +70,7 @@ 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;
...@@ -89,11 +90,22 @@ int main( int argc, char** argv ) ...@@ -89,11 +90,22 @@ int main( int argc, char** argv )
else if( saliency_algorithm.find( "BING" ) == 0 ) else if( saliency_algorithm.find( "BING" ) == 0 )
{ {
vector<Vec4i> saliencyMap; 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 ) ) if( saliencyAlgorithm->computeSaliency( image, saliencyMap ) )
{ {
std::cout << "-----------------OBJECTNESS-----------" << std::endl; 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[0] << std::endl;
std::cout << " " << saliencyMap[1] << std::endl; std::cout << " " << saliencyMap[1] << std::endl;
std::cout << " " << saliencyMap[2] << std::endl; std::cout << " " << saliencyMap[2] << std::endl;
......
...@@ -72,8 +72,8 @@ struct ValStructVec ...@@ -72,8 +72,8 @@ struct ValStructVec
template<typename VT, typename ST> template<typename VT, typename ST>
void ValStructVec<VT, ST>::append( const ValStructVec<VT, ST> &newVals, int startV ) void ValStructVec<VT, ST>::append( const ValStructVec<VT, ST> &newVals, int startV )
{ {
int sz = newVals.size(); int newValsSize = newVals.size();
for ( int i = 0; i < sz; i++ ) for ( int i = 0; i < newValsSize; i++ )
pushBack( (float) ( ( i + 300 ) * startV )/*newVals(i)*/, newVals[i] ); pushBack( (float) ( ( i + 300 ) * startV )/*newVals(i)*/, newVals[i] );
} }
......
...@@ -77,8 +77,19 @@ void ObjectnessBING::setColorSpace( int clr ) ...@@ -77,8 +77,19 @@ 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() );
// _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 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, ...@@ -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() ); 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"; CStr fName = _bbResDir + "bb";
//vector<Vec4i> sortedBB = finalBoxes.getSortedStructVal(); vector<Vec4i> sortedBB = finalBoxes.getSortedStructVal();
FILE *f = fopen( _S( fName + ".txt" ), "w" ); std::ofstream ofs;
fprintf( f, "%d\n", finalBoxes.size() ); ofs.open( _S( fName + ".txt" ), std::ofstream::out );
for ( size_t k = 0; k < finalBoxes.size(); k++ ){ stringstream dim;
//fprintf(f, "%g, %s\n", finalBoxes(k), _S(strVec4i(finalBoxes[k]))); dim << sortedBB.size();
//fprintf(f, "%g, %s\n", finalBoxes(k), finalBoxes(k)[0],finalBoxes(k)[1],finalBoxes(k)[2],finalBoxes(k)[3]); 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();
} }
ofs.close();
fclose( f ); */
} }
struct MatchPathSeparator struct MatchPathSeparator
...@@ -454,12 +471,12 @@ vector<float> ObjectnessBING::getobjectnessValues() ...@@ -454,12 +471,12 @@ vector<float> ObjectnessBING::getobjectnessValues()
return objectnessValues; 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 ...@@ -472,15 +489,15 @@ bool ObjectnessBING::computeSaliencyImpl( const InputArray image, OutputArray ob
// List of rectangles returned by objectess function in ascending order. // List of rectangles returned by objectess function in ascending order.
// At the top there are the rectangles with lower values of ​​objectness, ie more // At the top there are the rectangles with lower values of ​​objectness, ie more
// likely to have objects in them. // likely to have objects in them.
//vector<Vec4i>
vector<Vec4i> sortedBB = finalBoxes.getSortedStructVal(); vector<Vec4i> sortedBB = finalBoxes.getSortedStructVal();
objBoundingBox.create( 1, sortedBB.size(), CV_MAKETYPE( CV_32S, CV_MAT_CN(objBoundingBox.type()) ) ); //objBoundingBox.create( 1, sortedBB.size(), CV_MAKETYPE( CV_32S, CV_MAT_CN(objBoundingBox.type()) ) );
Mat obj = objBoundingBox.getMat(); //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++ ) Mat( sortedBB ).copyTo( objBoundingBox );
obj.at<Vec4i>( i ) = sortedBB[i];
// List of the rectangles' objectness value // List of the rectangles' objectness value
unsigned long int valIdxesSize = finalBoxes.getvalIdxes().size(); 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