Skip to content

Commit 7c10e2c

Browse files
committed
Merge branch 'bd_dev' into saliency_shengxin_gsoc2017
2 parents c712d7c + 07efdf3 commit 7c10e2c

File tree

4 files changed

+462
-1
lines changed

4 files changed

+462
-1
lines changed

modules/saliency/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ endif()
44

55
set(the_description "Saliency API")
66

7-
ocv_define_module(saliency opencv_imgproc opencv_datasets opencv_features2d opencv_dnn WRAP python)
7+
ocv_define_module(saliency opencv_imgproc opencv_datasets opencv_features2d opencv_dnn opencv_ximgproc WRAP python)
88

99
ocv_warnings_disable(CMAKE_CXX_FLAGS -Woverloaded-virtual)

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,47 @@ class CV_EXPORTS_W DeepGaze1 : public StaticSaliency
196196
std::vector<unsigned> fixationLoc( Mat, Size );
197197
};
198198

199+
/** @brief the Deep Gaze 1 Saliency approach from
200+
201+
This method use the convolution layers of the pretrained AlexNet, linear combination, center bias and softmax to generate saliency map
202+
*/
203+
class CV_EXPORTS_W BackgroundContrast : public StaticSaliency
204+
{
205+
private:
206+
int limitOfSP;
207+
int nOfLevel;
208+
int usePrior;
209+
int histBin;
210+
double bgWei;
211+
public:
212+
BackgroundContrast( double = 5, int = 600, int = 4, int = 2, int = 5 );
213+
virtual ~BackgroundContrast();
214+
CV_WRAP static Ptr<BackgroundContrast> create()
215+
{
216+
return makePtr<BackgroundContrast>();
217+
}
218+
CV_WRAP bool computeSaliency( InputArray image, OutputArray saliencyMap )
219+
{
220+
if( image.empty() )
221+
return false;
222+
return computeSaliencyImpl( image, saliencyMap );
223+
}
224+
Mat saliencyMapGenerator( const Mat, const Mat = Mat(), int = 0 );
225+
void saliencyOptimize( const Mat, const Mat, const Mat, const Mat, Mat&, double = 5, double = 14 );
226+
Mat saliencyMapVisualize( InputArray _saliencyMap, int = 0 );
227+
protected:
228+
bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap );
229+
void superpixelSplit( const Mat, Mat&, Mat& );
230+
std::vector<unsigned> getBndPatchIds( const Mat, int = 8);
231+
void getColorPosDis( const Mat, const Mat, Mat&, Mat&, int );
232+
void boundaryConnectivity( const Mat, const Mat, Mat&, std::vector<unsigned>, double = 3.0, double = 7.0 );
233+
void getWeightedContrast( const Mat, const Mat, const Mat, Mat& );
234+
void dist2WeightMatrix( Mat&, Mat&, double );
235+
void rgb2lab( Mat&, Mat& );
236+
};
237+
238+
239+
199240

200241

201242
/************************************ Specific Motion Saliency Specialized Classes ************************************/
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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 <opencv2/ximgproc.hpp>
11+
#include <vector>
12+
#include <string>
13+
#include <iostream>
14+
#include <fstream>
15+
16+
using namespace std;
17+
using namespace cv;
18+
using namespace saliency;
19+
20+
21+
int main(int argc, char* argv[])
22+
{
23+
const char *keys =
24+
"{ help h usage ? | | show this message }"
25+
"{ img_path | | path to img }"
26+
"{ foregroundImg_path| | path to saliency img generated by other method }"
27+
"{ optimization |0 | 0 for aggregated optimized with no outside saliency, 1 for optimizaed with outside saliency }";
28+
29+
CommandLineParser parser(argc, argv, keys);
30+
if (parser.has("help"))
31+
{
32+
parser.printMessage();
33+
return 0;
34+
}
35+
string img_path = parser.get<string>("img_path");
36+
string foregroundImg_path = parser.get<string>("foregroundImg_path");
37+
38+
Mat img = imread(img_path);
39+
Mat fgImg = imread(foregroundImg_path);
40+
BackgroundContrast bc;
41+
if ( parser.get<bool>( "optimization" ) )
42+
{
43+
bc.saliencyMapVisualize(bc.saliencyMapGenerator(img, fgImg, 1), 0);
44+
}
45+
else
46+
{
47+
Mat saliency;
48+
bc.computeSaliency(img, saliency);
49+
bc.saliencyMapVisualize(saliency, 0);
50+
}
51+
return 0;
52+
} //main

0 commit comments

Comments
 (0)