Skip to content

Commit 362a8ab

Browse files
committed
add assert to prevent empty img
1 parent a40edad commit 362a8ab

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

modules/saliency/samples/BackgroundContrastSample.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ int main(int argc, char* argv[])
4444
}
4545
else
4646
{
47-
bc.saliencyMapVisualize(bc.saliencyMapGenerator(img), 0);
47+
Mat saliency;
48+
bc.computeSaliency(img, saliency);
49+
bc.saliencyMapVisualize(saliency, 0);
4850
}
4951
return 0;
5052
} //main

modules/saliency/src/BackgroundContrast.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ BackgroundContrast::~BackgroundContrast(){}
3838

3939
Mat BackgroundContrast::saliencyMapGenerator( const Mat img, const Mat fgImg, int option )
4040
{
41+
CV_Assert( !(img.empty()) );
42+
CV_Assert( !(option == 1 && fgImg.empty()) );
4143
Mat idxImg, adjcMatrix, colDistM, posDistM, bdProb, wCtr, saliency;
4244
superpixelSplit(img, idxImg, adjcMatrix);
4345
vector<unsigned> bdIds = getBndPatchIds(idxImg);
@@ -151,7 +153,7 @@ bool BackgroundContrast::computeSaliencyImpl( InputArray image, OutputArray sali
151153
void BackgroundContrast::superpixelSplit( const Mat img, Mat& idxImg, Mat& adjcMatrix)
152154
{
153155
Ptr<SuperpixelSEEDS> seeds;
154-
seeds = createSuperpixelSEEDS( img.size().width, img.size().height, img.channels(), min(img.size().width * img.size().height / 600, limitOfSP), nOfLevel, usePrior, histBin, false);
156+
seeds = createSuperpixelSEEDS( img.size().width, img.size().height, img.channels(), max(min(img.size().width * img.size().height / 600, limitOfSP), 10), nOfLevel, usePrior, histBin, false);
155157
seeds->iterate( img, 4 );
156158
Mat mask;
157159
adjcMatrix = Mat::eye( seeds->getNumberOfSuperpixels(), seeds->getNumberOfSuperpixels(), CV_8U );

0 commit comments

Comments
 (0)