-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Description
System information (version)
- OpenCV => 4.2
Detailed description
When I tested seamlessClone, I have noticed that the placement of the crop that I used is different from the case where I use simple alpha-blend. Digging into the code, I have noticed this:
opencv/modules/photo/src/seamless_cloning.cpp
Lines 81 to 83 in 2b60166
| Rect roi_s = boundingRect(mask); | |
| if (roi_s.empty()) return; | |
| Rect roi_d(p.x - roi_s.width / 2, p.y - roi_s.height / 2, roi_s.width, roi_s.height); |
Meaning that seamless clone, crops the src image, and the mask to remove zero margins from the mask - this is probably for improving the performance of the module. In this process, seamlessClone places the cropped source image on the destination image where the Point p is the center of the cropped source (after margin removal) - and not the center of the original source. This will cause a deviation in relation to the original InputArray _src that is provided to the function.
I think that this behavior is wrong or at least misleading - as when a developer uses the seamlessClone function, the information that is generally available (in the debug phase) - is the shapes of the destination, source & the mask images (knowing the zero margins is not always trivial). If this is intentional, then it should be documented here:
https://docs.opencv.org/4.x/df/da0/group__photo__clone.html#ga2bf426e4c93a6b1f21705513dfeca49d
I suggest adding an offset to the destination ROI that will cancel the change of location of the original src image. The offset can be added here:
| Rect roi_d(p.x - roi_s.width / 2, p.y - roi_s.height / 2, roi_s.width, roi_s.height); |
Thanks,
Roee
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: videos, images, onnx, etc