Commit e7955998 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #1412 from berak:fix_saliency

parents 087db723 00ea0f49
......@@ -464,7 +464,7 @@ private:
void setColorSpace( int clr = MAXBGR );
// Load trained model.
int loadTrainedModel( std::string modelName = "" );// Return -1, 0, or 1 if partial, none, or all loaded
int loadTrainedModel();// Return -1, 0, or 1 if partial, none, or all loaded
// Get potential bounding boxes, each of which is represented by a Vec4i for (minX, minY, maxX, maxY).
// The trained model should be prepared before calling this function: loadTrainedModel() or trainStageI() + trainStageII().
......
......@@ -52,7 +52,7 @@ static const char* keys =
{ "{@saliency_algorithm | | Saliency algorithm <saliencyAlgorithmType.[saliencyAlgorithmTypeSubType]> }"
"{@video_name | | video name }"
"{@start_frame |1| Start frame }"
"{@training_path |1| Path of the folder containing the trained files}" };
"{@training_path |ObjectnessTrainedModel| Path of the folder containing the trained files}" };
static void help()
{
......@@ -150,11 +150,28 @@ int main( int argc, char** argv )
saliencyAlgorithm = ObjectnessBING::create();
vector<Vec4i> saliencyMap;
saliencyAlgorithm.dynamicCast<ObjectnessBING>()->setTrainingPath( training_path );
saliencyAlgorithm.dynamicCast<ObjectnessBING>()->setBBResDir( training_path + "/Results" );
saliencyAlgorithm.dynamicCast<ObjectnessBING>()->setBBResDir( "Results" );
if( saliencyAlgorithm->computeSaliency( image, saliencyMap ) )
{
std::cout << "Objectness done" << std::endl;
int ndet = int(saliencyMap.size());
std::cout << "Objectness done " << ndet << std::endl;
// The result are sorted by objectness. We only use the first maxd boxes here.
int maxd = 7, step = 255 / maxd, jitter=9; // jitter to seperate single rects
Mat draw = image.clone();
for (int i = 0; i < std::min(maxd, ndet); i++) {
Vec4i bb = saliencyMap[i];
Scalar col = Scalar(((i*step)%255), 50, 255-((i*step)%255));
Point off(theRNG().uniform(-jitter,jitter), theRNG().uniform(-jitter,jitter));
rectangle(draw, Point(bb[0]+off.x, bb[1]+off.y), Point(bb[2]+off.x, bb[3]+off.y), col, 2);
rectangle(draw, Rect(20, 20+i*10, 10,10), col, -1); // mini temperature scale
}
imshow("BING", draw);
waitKey();
}
else
{
std::cout << "No saliency found for " << video_name << std::endl;
}
}
......
......@@ -76,7 +76,7 @@ bool CmFile::MkDir( std::string &_path )
buffer[i] = '/';
}
}
mkdir( _path.c_str(), 0 );
mkdir( _path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH );
return true;
#endif
}
......
......@@ -95,16 +95,14 @@ void ObjectnessBING::setBBResDir(const String &resultsDir )
_resultsDir = resultsDir;
}
int ObjectnessBING::loadTrainedModel( std::string modelName ) // Return -1, 0, or 1 if partial, none, or all loaded
int ObjectnessBING::loadTrainedModel() // Return -1, 0, or 1 if partial, none, or all loaded
{
if( modelName.size() == 0 )
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;
if( !matRead( s1, filters1f ) || !matRead( sI, idx1i ) )
{
printf( "Can't load model: %s or %s\n", s1.c_str(), sI.c_str() );
printf( "Can't load model: %s or %s\r\n", s1.c_str(), sI.c_str() );
return 0;
}
......@@ -384,7 +382,9 @@ void ObjectnessBING::getObjBndBoxesForSingleImage( Mat img, ValStructVec<float,
for ( int clr = MAXBGR; clr <= G; clr++ )
{
setColorSpace( clr );
loadTrainedModel();
if (!loadTrainedModel())
continue;
CmTimer tm( "Predict" );
tm.Start();
......@@ -439,6 +439,9 @@ bool ObjectnessBING::matRead( const std::string& filename, Mat& _M )
String filenamePlusExt( filename.c_str() );
filenamePlusExt += ".yml.gz";
FileStorage fs2( filenamePlusExt, FileStorage::READ );
if (! fs2.isOpened()) // wrong trainingPath
return false;
Mat M;
fs2[String( removeExtension( basename( filename ) ).c_str() )] >> M;
......
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