From b723ddd72bd48ff04c1d21743f09dd6ba8c5b6f0 Mon Sep 17 00:00:00 2001 From: sparklejin <1575275976@qq.com> Date: Sat, 30 May 2026 15:53:54 +0800 Subject: [PATCH] imgproc: fix floodFill simple path never being used MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The is_simple check used mask.empty() after the default mask had already been created, making it always false. This caused the fast path (floodFill_CnIR) to be dead code — every call went through the slower gradient-based path (floodFillGrad_CnIR). Fix: save _mask.empty() result before auto-creating the default mask and use it for the is_simple check. --- modules/imgproc/src/floodfill.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/imgproc/src/floodfill.cpp b/modules/imgproc/src/floodfill.cpp index 5ef019fb0f..262b539f74 100644 --- a/modules/imgproc/src/floodfill.cpp +++ b/modules/imgproc/src/floodfill.cpp @@ -494,7 +494,8 @@ int cv::floodFill( InputOutputArray _image, InputOutputArray _mask, if( connectivity != 0 && connectivity != 4 && connectivity != 8 ) CV_Error( cv::Error::StsBadFlag, "Connectivity must be 4, 0(=4) or 8" ); - if( _mask.empty() ) + bool noUserMask = _mask.empty(); + if( noUserMask ) { _mask.create( size.height + 2, size.width + 2, CV_8UC1 ); _mask.setTo(0); @@ -508,7 +509,7 @@ int cv::floodFill( InputOutputArray _image, InputOutputArray _mask, Mat mask_inner = mask( Rect(1, 1, mask.cols - 2, mask.rows - 2) ); copyMakeBorder( mask_inner, mask, 1, 1, 1, 1, BORDER_ISOLATED | BORDER_CONSTANT, Scalar(1) ); - bool is_simple = mask.empty() && (flags & FLOODFILL_MASK_ONLY) == 0; + bool is_simple = noUserMask && (flags & FLOODFILL_MASK_ONLY) == 0; for( i = 0; i < cn; i++ ) {