Skip to content

ximgproc: EdgeDrawing must not modify the caller's input when Sigma < 1.0 - #4206

Open
purehol wants to merge 1 commit into
opencv:4.xfrom
purehol:fix-edgedrawing-input-aliasing
Open

ximgproc: EdgeDrawing must not modify the caller's input when Sigma < 1.0#4206
purehol wants to merge 1 commit into
opencv:4.xfrom
purehol:fix-edgedrawing-input-aliasing

Conversation

@purehol

@purehol purehol commented Sep 2, 2026

Copy link
Copy Markdown

Root cause

When Params::Sigma < 1.0, detectEdges() set smoothImage = srcImage, aliasing
the caller's input Mat. detectEllipses() then runs an in-place GaussianBlur
into smoothImage (the PFmode path in detectEdges() does the same), silently
overwriting the user's input image and any later reads of it.

Fix

Clone the image so the input stays read-only, matching the reference implementation
ED_Lib (which always blurs into a separately allocated buffer). Cost is one
width*height copy when Sigma < 1.0; correctness takes priority.

Verification

Added TEST_F(ximgproc_ED, detectEllipsesDoesNotModifyInput): with Sigma = 0.0
it asserts the input Mat is unchanged after detectEdges() + detectEllipses().
Fails before this change (1916 input pixels modified) and passes after it;
existing *ED* tests still pass.

Fixes #4203

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in the repository, if applicable
  • The feature is well documented and sample code can be built with the project CMake

… 1.0

When Params::Sigma < 1.0, detectEdges() set `smoothImage = srcImage`, aliasing
the caller's input Mat. detectEllipses() then runs an in-place GaussianBlur into
smoothImage (the PFmode path in detectEdges() does the same), silently
overwriting the user's input image and any later reads of it. Clone the image so
the input stays read-only, matching the reference implementation ED_Lib.

Adds a regression test that fails before this change (1916 pixels of the input
were modified) and passes after it.
@purehol
purehol marked this pull request as ready for review September 2, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant