mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-23 00:49:38 +08:00
ximgproc: fix weightedMedianFilter crash on zero mask
This commit is contained in:
@@ -493,7 +493,7 @@ Mat filterCore(Mat &I, Mat &F, float **wMap, int r=20, int nF=256, int nI=256, M
|
|||||||
// Move cut-point to the left
|
// Move cut-point to the left
|
||||||
if(balanceWeight >= 0)
|
if(balanceWeight >= 0)
|
||||||
{
|
{
|
||||||
for(;balanceWeight >= 0 && curMedianVal; curMedianVal--)
|
for(;balanceWeight >= 0 && curMedianVal > 0; curMedianVal--)
|
||||||
{
|
{
|
||||||
float curWeight = 0;
|
float curWeight = 0;
|
||||||
int *nextHist = H[curMedianVal];
|
int *nextHist = H[curMedianVal];
|
||||||
@@ -539,8 +539,13 @@ Mat filterCore(Mat &I, Mat &F, float **wMap, int r=20, int nF=256, int nI=256, M
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Weighted median is found and written to the output image
|
// Weighted median is found and written to the output image
|
||||||
if(balanceWeight<0)outImg.ptr<int>(y,x)[0] = curMedianVal+1;
|
if(curMedianVal != -1)
|
||||||
else outImg.ptr<int>(y,x)[0] = curMedianVal;
|
{
|
||||||
|
if(balanceWeight < 0)
|
||||||
|
outImg.ptr<int>(y,x)[0] = curMedianVal+1;
|
||||||
|
else
|
||||||
|
outImg.ptr<int>(y,x)[0] = curMedianVal;
|
||||||
|
}
|
||||||
|
|
||||||
// Update joint-histogram and BCB when local window is shifted.
|
// Update joint-histogram and BCB when local window is shifted.
|
||||||
int fval,gval,*curHist;
|
int fval,gval,*curHist;
|
||||||
|
@@ -102,6 +102,16 @@ TEST(WeightedMedianFilterTest, ReferenceAccuracy)
|
|||||||
EXPECT_LE(cvtest::norm(res, ref, NORM_L2), totalMaxError);
|
EXPECT_LE(cvtest::norm(res, ref, NORM_L2), totalMaxError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(WeightedMedianFilterTest, mask_zeros_no_crash)
|
||||||
|
{
|
||||||
|
Mat img = imread(getDataDir() + "cv/ximgproc/sources/01.png");
|
||||||
|
Mat mask = Mat::zeros(img.size(), CV_8U);
|
||||||
|
Mat filtered;
|
||||||
|
weightedMedianFilter(img, img, filtered, 3, 20, WMF_EXP, mask);
|
||||||
|
|
||||||
|
EXPECT_EQ(cv::norm(img, filtered, NORM_INF), 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
INSTANTIATE_TEST_CASE_P(TypicalSET, WeightedMedianFilterTest, Combine(Values(szODD, szQVGA), Values(WMF_EXP, WMF_IV2, WMF_OFF)));
|
INSTANTIATE_TEST_CASE_P(TypicalSET, WeightedMedianFilterTest, Combine(Values(szODD, szQVGA), Values(WMF_EXP, WMF_IV2, WMF_OFF)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user