Skip to content

Commit 07efdf3

Browse files
committed
add background weight adjust option
1 parent 362a8ab commit 07efdf3

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ class CV_EXPORTS_W BackgroundContrast : public StaticSaliency
207207
int nOfLevel;
208208
int usePrior;
209209
int histBin;
210+
double bgWei;
210211
public:
211-
BackgroundContrast( int = 600, int = 4, int = 2, int = 5 );
212+
BackgroundContrast( double = 5, int = 600, int = 4, int = 2, int = 5 );
212213
virtual ~BackgroundContrast();
213214
CV_WRAP static Ptr<BackgroundContrast> create()
214215
{
@@ -221,7 +222,7 @@ class CV_EXPORTS_W BackgroundContrast : public StaticSaliency
221222
return computeSaliencyImpl( image, saliencyMap );
222223
}
223224
Mat saliencyMapGenerator( const Mat, const Mat = Mat(), int = 0 );
224-
void saliencyOptimize( const Mat, const Mat, const Mat, const Mat, Mat&, double = 14, double = 5 );
225+
void saliencyOptimize( const Mat, const Mat, const Mat, const Mat, Mat&, double = 5, double = 14 );
225226
Mat saliencyMapVisualize( InputArray _saliencyMap, int = 0 );
226227
protected:
227228
bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap );

modules/saliency/src/BackgroundContrast.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace cv
3333
namespace saliency
3434
{
3535

36-
BackgroundContrast::BackgroundContrast( int _limitOfSP, int _nOfLevel, int _usePrior, int _histBin ): limitOfSP(_limitOfSP), nOfLevel(_nOfLevel), usePrior(_usePrior), histBin(_histBin) {}
36+
BackgroundContrast::BackgroundContrast( double _bgWei, int _limitOfSP, int _nOfLevel, int _usePrior, int _histBin ): limitOfSP(_limitOfSP), nOfLevel(_nOfLevel), usePrior(_usePrior), histBin(_histBin), bgWei(_bgWei) {}
3737
BackgroundContrast::~BackgroundContrast(){}
3838

3939
Mat BackgroundContrast::saliencyMapGenerator( const Mat img, const Mat fgImg, int option )
@@ -62,6 +62,7 @@ Mat BackgroundContrast::saliencyMapGenerator( const Mat img, const Mat fgImg, in
6262
else
6363
{
6464
Mat temp = fgImg.clone();
65+
if (temp.channels() == 3) cvtColor(temp, temp, COLOR_BGR2GRAY);
6566
wCtr = Mat(adjcMatrix.size[0], 1, CV_64F, Scalar::all(0.0));
6667
resize(temp, temp, img.size());
6768
vector<int> szOfSP = vector<int>(adjcMatrix.size[0], 0);
@@ -78,7 +79,7 @@ Mat BackgroundContrast::saliencyMapGenerator( const Mat img, const Mat fgImg, in
7879
wCtr.at<double>(i, 0) /= szOfSP[i];
7980
}
8081
}
81-
saliencyOptimize(adjcMatrix, colDistM, bdProb, wCtr, wCtr);
82+
saliencyOptimize(adjcMatrix, colDistM, bdProb, wCtr, wCtr, bgWei);
8283
saliency = Mat(img.size[0], img.size[1], CV_64F, Scalar::all(0.0));
8384
for (int i = 0; i < img.size[0]; i++)
8485
{
@@ -90,7 +91,7 @@ Mat BackgroundContrast::saliencyMapGenerator( const Mat img, const Mat fgImg, in
9091
return saliency;
9192
}
9293

93-
void BackgroundContrast::saliencyOptimize( const Mat adjcMatrix, const Mat colDistM, const Mat bgWeight, const Mat fgWeight, Mat& saliencyOptimized, double neiSigma, double bgLambda )
94+
void BackgroundContrast::saliencyOptimize( const Mat adjcMatrix, const Mat colDistM, const Mat bgWeight, const Mat fgWeight, Mat& saliencyOptimized, double bgLambda, double neiSigma )
9495
{
9596

9697
Mat smoothWeight = colDistM.clone();

0 commit comments

Comments
 (0)