From f5592fd21b8dd881fcf31e91881ca140458ed7e8 Mon Sep 17 00:00:00 2001 From: Vladislav Sovrasov Date: Mon, 24 Oct 2016 17:22:44 +0300 Subject: [PATCH] Fix wrong default mask value in floodFill --- modules/imgproc/src/floodfill.cpp | 2 +- modules/imgproc/test/test_floodfill.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/imgproc/src/floodfill.cpp b/modules/imgproc/src/floodfill.cpp index a818539..0df59d3 100644 --- a/modules/imgproc/src/floodfill.cpp +++ b/modules/imgproc/src/floodfill.cpp @@ -586,7 +586,7 @@ int cv::floodFill( InputOutputArray _image, InputOutputArray _mask, else CV_Error( CV_StsUnsupportedFormat, "" ); - uchar newMaskVal = (uchar)((flags & ~0xff) == 0 ? 1 : ((flags >> 8) & 255)); + uchar newMaskVal = (uchar)((flags & 0xff00) == 0 ? 1 : ((flags >> 8) & 255)); if( type == CV_8UC1 ) floodFillGrad_CnIR( diff --git a/modules/imgproc/test/test_floodfill.cpp b/modules/imgproc/test/test_floodfill.cpp index bb34449..fe2fba6 100644 --- a/modules/imgproc/test/test_floodfill.cpp +++ b/modules/imgproc/test/test_floodfill.cpp @@ -528,4 +528,18 @@ void CV_FloodFillTest::prepare_to_validation( int /*test_case_idx*/ ) TEST(Imgproc_FloodFill, accuracy) { CV_FloodFillTest test; test.safe_run(); } +TEST(Imgproc_FloodFill, maskValue) +{ + const int n = 50; + Mat img = Mat::zeros(n, n, CV_8U); + Mat mask = Mat::zeros(n + 2, n + 2, CV_8U); + + circle(img, Point(n/2, n/2), 20, Scalar(100), 4); + + int flags = 4 + CV_FLOODFILL_MASK_ONLY; + floodFill(img, mask, Point(n/2 + 13, n/2), Scalar(100), NULL, Scalar(), Scalar(), flags); + + ASSERT_TRUE(norm(mask.rowRange(1, n-1).colRange(1, n-1), NORM_INF) == 1.); +} + /* End of file. */ -- 2.7.4