1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

imgproc: fix floodFill simple path never being used

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.
This commit is contained in:
sparklejin
2026-05-30 15:53:54 +08:00
parent b29ea17666
commit b723ddd72b
+3 -2
View File
@@ -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++ )
{