suppress GaussianBlur to generate empty images

* sharp Gaussian kernel causes over flow and ends up in blank image
This commit is contained in:
Tomoaki Teshima 2021-10-01 23:17:02 +09:00
parent 1e0d290f2e
commit 1e74f5850b
3 changed files with 17 additions and 3 deletions

View File

@ -445,8 +445,8 @@ PARAM_TEST_CASE(GaussianBlur, cv::cuda::DeviceInfo, cv::Size, MatDepth, Channels
CUDA_TEST_P(GaussianBlur, Accuracy)
{
cv::Mat src = randomMat(size, type);
double sigma1 = randomDouble(0.1, 1.0);
double sigma2 = randomDouble(0.1, 1.0);
double sigma1 = randomDouble(0.0, 1.0);
double sigma2 = randomDouble(0.0, 1.0);
cv::Ptr<cv::cuda::Filter> gauss = cv::cuda::createGaussianFilter(src.type(), -1, ksize, sigma1, sigma2, borderType);

View File

@ -1958,7 +1958,10 @@ public:
}
else if (kxlen % 2 == 1)
{
hlineSmoothFunc = hlineSmoothONa_yzy_a;
if (kx[(kxlen - 1)/ 2] == FT::one())
hlineSmoothFunc = hlineSmooth1N1;
else
hlineSmoothFunc = hlineSmoothONa_yzy_a;
for (int i = 0; i < kxlen / 2; i++)
if (!(kx[i] == kx[kxlen - 1 - i]))
{

View File

@ -249,4 +249,15 @@ TEST(GaussianBlur_Bitexact, regression_9863)
checkGaussianBlur_8Uvs32F(src8u, src32f, 151, 30);
}
TEST(GaussianBlur_Bitexact, overflow_20792)
{
Mat src(128, 128, CV_16UC1, Scalar(255));
Mat dst;
double sigma = theRNG().uniform(0.0, 0.2); // a peaky kernel
GaussianBlur(src, dst, Size(7, 7), sigma, 0.9);
int count = (int)countNonZero(dst);
int nintyPercent = (int)(src.rows*src.cols * 0.9);
EXPECT_GT(count, nintyPercent);
}
}} // namespace