Skip to content

Commit c712d7c

Browse files
committed
Merge branch 'sp_dev' into saliency_shengxin_gsoc2017
2 parents 2cfb0ac + 55326e4 commit c712d7c

File tree

3 files changed

+451
-0
lines changed

3 files changed

+451
-0
lines changed

modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,53 @@ class CV_EXPORTS_W MotionSaliencyBinWangApr2014 : public MotionSaliency
302302

303303
};
304304

305+
/** @brief the Deep Gaze 1 Saliency approach from
306+
307+
This method use the convolution layers of the pretrained AlexNet, linear combination, center bias and softmax to generate saliency map
308+
*/
309+
class CV_EXPORTS_W DiscriminantSaliency : public MotionSaliency
310+
{
311+
private:
312+
Size imgProcessingSize;
313+
unsigned hiddenSpaceDimension;
314+
unsigned centerSize;
315+
unsigned windowSize;
316+
unsigned patchSize;
317+
unsigned temporalSize;
318+
unsigned stride;
319+
public:
320+
struct DT
321+
{
322+
Mat A;
323+
Mat C;
324+
Mat Q;
325+
Mat R;
326+
Mat S;
327+
Mat MU;
328+
double VAR;
329+
};
330+
// DiscriminantSaliency();
331+
DiscriminantSaliency(unsigned = 1, Size = Size(127, 127), unsigned = 10, unsigned = 8, unsigned = 96, unsigned = 400, unsigned = 11);
332+
virtual ~DiscriminantSaliency();
333+
CV_WRAP static Ptr<DeepGaze1> create()
334+
{
335+
return makePtr<DeepGaze1>();
336+
}
337+
CV_WRAP bool computeSaliency( InputArray image, OutputArray saliencyMap )
338+
{
339+
if( image.empty() )
340+
return false;
341+
return computeSaliencyImpl( image, saliencyMap );
342+
}
343+
void dynamicTextureEstimator( const Mat, DT& );
344+
void patchGenerator( const std::vector<Mat>& img_sq, unsigned index, unsigned r, unsigned c, Mat& center, Mat& surround, Mat& all );
345+
std::vector<Mat> saliencyMapGenerator( std::vector<Mat>, std::vector<Mat>& );
346+
void saliencyMapVisualize( InputArray _saliencyMap );
347+
protected:
348+
bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap );
349+
double KLdivDT( const DT&, const DT& );
350+
};
351+
305352
/************************************ Specific Objectness Specialized Classes ************************************/
306353

307354
/**
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// This file is part of OpenCV project.
2+
// It is subject to the license terms in the LICENSE file found in the top-level directory
3+
// of this distribution and at http://opencv.org/license.html.
4+
5+
6+
#include <opencv2/core.hpp>
7+
#include <opencv2/imgproc.hpp>
8+
#include <opencv2/highgui.hpp>
9+
#include <opencv2/saliency.hpp>
10+
#include <vector>
11+
#include <string>
12+
#include <iostream>
13+
#include <fstream>
14+
15+
using namespace std;
16+
using namespace cv;
17+
using namespace saliency;
18+
19+
20+
int main(int argc, char* argv[])
21+
{
22+
const char *keys =
23+
"{ help h usage ? | | show this message }"
24+
"{ start_frame |0 | start frame index }"
25+
"{ length |12 | # of frames video contain }"
26+
"{ default |1 | use default deep net(AlexNet) and default weights }"
27+
"{ video_name |skiing| the name of video in UCSD background subtraction }"
28+
"{ img_folder_path|JPEGS| path to folder with frames }"
29+
"{ res_level | 3 | resolution level of output saliency map. Suggested Range [0, 4]. The higher the level is, the fast the processing is, the lower the resolution is }";
30+
31+
CommandLineParser parser(argc, argv, keys);
32+
if (parser.has("help"))
33+
{
34+
parser.printMessage();
35+
return 0;
36+
}
37+
vector<Mat> img_sq;
38+
DiscriminantSaliency t;
39+
if ( parser.get<bool>( "default" ) )
40+
{
41+
t = DiscriminantSaliency();
42+
}
43+
else
44+
{
45+
t = DiscriminantSaliency(parser.get<int>( "res_level" ));
46+
}
47+
for ( unsigned i = 1; i < parser.get<unsigned>( "length" ); i++ )
48+
{
49+
char index[256] = {0};
50+
sprintf(index, "%d", i + parser.get<int>( "start_frame" ));
51+
Mat temp = imread(parser.get<string>("img_folder_path") + "/" + parser.get<string>("video_name") + "/frame_" + index + ".jpg", 0);
52+
//Mat temp = imread(string("JPEGS/traffic/frame_") + index + ".jpg", 0);
53+
//resize(temp, temp, Size(127, 127));
54+
img_sq.push_back(temp);
55+
}
56+
vector<Mat> saliency_sq;
57+
t.computeSaliency(img_sq, saliency_sq);
58+
for ( unsigned i = 0; i < saliency_sq.size(); i++ )
59+
{
60+
resize(saliency_sq[i], saliency_sq[i], Size(1024, 768));
61+
t.saliencyMapVisualize(saliency_sq[i]);
62+
}
63+
return 0;
64+
} //main

0 commit comments

Comments
 (0)