Commit 1c1a9cde authored by jaco's avatar jaco

BING objectness porting finished

parent d9728347
...@@ -210,6 +210,7 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness ...@@ -210,6 +210,7 @@ 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 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]);} 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 //Non-maximal suppress
static void nonMaxSup(CMat &matchCost1f, ValStructVec<float, Point> &matchCost, int NSS = 1, int maxPoint = 50, bool fast = true); static void nonMaxSup(CMat &matchCost1f, ValStructVec<float, Point> &matchCost, int NSS = 1, int maxPoint = 50, bool fast = true);
......
...@@ -94,6 +94,9 @@ int main( int argc, char** argv ) ...@@ -94,6 +94,9 @@ int main( int argc, char** argv )
std::cout << "-----------------OBJECTNESS-----------" << std::endl; std::cout << "-----------------OBJECTNESS-----------" << std::endl;
std::cout << "OBJ BB VECTOR SIZE" << saliencyMap.size() << std::endl; std::cout << "OBJ BB VECTOR SIZE" << saliencyMap.size() << std::endl;
std::cout << " " << saliencyMap[0] << std::endl;
std::cout << " " << saliencyMap[1] << std::endl;
std::cout << " " << saliencyMap[2] << std::endl;
} }
} }
......
...@@ -75,10 +75,10 @@ ObjectnessBING::~ObjectnessBING() ...@@ -75,10 +75,10 @@ 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() );
// _trainDirSI = _voc.localDir + string(format("TrainS1B%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 = _voc.resDir + 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());
} }
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
...@@ -387,6 +387,18 @@ void ObjectnessBING::getObjBndBoxesForSingleImage( Mat img, ValStructVec<float, ...@@ -387,6 +387,18 @@ void ObjectnessBING::getObjBndBoxesForSingleImage( Mat img, ValStructVec<float,
tm.Stop(); tm.Stop();
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);
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]);
}
fclose( f ); */
} }
struct MatchPathSeparator struct MatchPathSeparator
...@@ -411,15 +423,15 @@ std::string inline removeExtension( std::string const& filename ) ...@@ -411,15 +423,15 @@ std::string inline removeExtension( std::string const& filename )
// Read matrix from binary file // Read matrix from binary file
bool ObjectnessBING::matRead( const string& filename, Mat& _M ) bool ObjectnessBING::matRead( const string& filename, Mat& _M )
{ {
String filenamePlusExt(filename.c_str()); String filenamePlusExt( filename.c_str() );
filenamePlusExt+=".yml.gz"; filenamePlusExt += ".yml.gz";
FileStorage fs2( filenamePlusExt, FileStorage::READ ); FileStorage fs2( filenamePlusExt, FileStorage::READ );
//String fileNameString( filename.c_str() ); //String fileNameString( filename.c_str() );
Mat M; Mat M;
fs2[String(removeExtension( basename( filename ) ).c_str())] >> M; fs2[String( removeExtension( basename( filename ) ).c_str() )] >> M;
/*FILE* f = fopen(_S(filename), "rb"); /* FILE* f = fopen(_S(filename), "rb");
if (f == NULL) if (f == NULL)
return false; return false;
char buf[8]; char buf[8];
...@@ -460,21 +472,15 @@ bool ObjectnessBING::computeSaliencyImpl( const InputArray image, OutputArray ob ...@@ -460,21 +472,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>
//objBoundingBox = finalBoxes.getSortedStructVal(); vector<Vec4i> sortedBB = finalBoxes.getSortedStructVal();
/* vector<Vec4i> tmp=finalBoxes.getSortedStructVal();
objBoundingBox.create(tmp.size(), 1, CV_8U);
Mat obj= objBoundingBox.getMat();
obj=tmp;*/
objBoundingBox.create( 1, sortedBB.size(), CV_MAKETYPE( CV_32S, CV_MAT_CN(objBoundingBox.type()) ) );
Mat obj = objBoundingBox.getMat(); Mat obj = objBoundingBox.getMat();
obj = Mat(finalBoxes.getSortedStructVal());
/* Mat obj2 = objBoundingBox.getMatRef();
obj2 = Mat(finalBoxes.getSortedStructVal());*/
for ( uint i = 0; i < sortedBB.size(); i++ )
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