EdgeDrawing::detectEllipses() modifies the caller's input image when Params::Sigma < 1.0
Author: pureholCreated Sep 2, 2026Updated Sep 2, 2026
System information (version)
- OpenCV => 4.x head (reproduced on 4.14.0)
- Operating System / Platform => Ubuntu (Linux 5.15) 64 Bit
- Compiler => gcc 9.4
Detailed description
When EdgeDrawing::Params::Sigma < 1.0, detectEdges() sets
smoothImage = srcImage; (modules/ximgproc/src/edge_drawing.cpp:411 on 4.x), so
smoothImage aliases the caller's input Mat. detectEllipses() then runs
GaussianBlur(srcImage, smoothImage, Size(), 0.50) (:2718) — an in-place blur
that silently overwrites the user's input image (the PFmode path in detectEdges()
at :430 does the same with sigma 0.4). This violates the InputArray read-only
contract and also corrupts any later use of the source image.
The reference implementation ED_Lib always blurs into a separately allocated smoothImage; the aliasing shortcut is unique to the OpenCV port.
Steps to reproduce (C++)
#include <opencv2/imgproc.hpp>
#include <opencv2/ximgproc.hpp>
#include <cstdio>
using namespace cv;
int main() {
Mat img(200, 200, CV_8UC1, Scalar(255));
circle(img, Point(100, 100), 60, Scalar(0), 2);
Mat backup = img.clone();
Ptr<ximgproc::EdgeDrawing> ed = ximgproc::createEdgeDrawing();
ed->params.Sigma = 0.0; // Sigma < 1.0
ed->detectEdges(img);
std::vector<Vec6d> ellipses;
ed->detectEllipses(ellipses);
printf("input pixels modified = %d (expected 0)\n",
countNonZero(img != backup)); // prints 1916
return 0;
}Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files
Source: opencv/opencv_contrib