Skip to content

imgproc: preserve phaseCorrelate inputs when windowing - #30281

Merged
asmorkalov merged 3 commits into
opencv:4.xfrom
pbkx:fix-phasecorrelate-input-mutation-4x
Oct 14, 2026
Merged

asmorkalov merged 3 commits into
opencv:4.xfrom
pbkx:fix-phasecorrelate-input-mutation-4x

Conversation

@pbkx

@pbkx pbkx commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

phaseCorrelate() currently performs a shallow copy of input matrices provided they already match the optimal DFT size. This is unsafe when a window is supplied because the in-place multiplication would overwrite the contents pointed to by the input matrices' data pointers.

This PR makes the phaseCorrelate() function use separate storage for applying the window. This keeps the inputs read-only (while keeping the path behavior the same as the padded case). This PR also adds a regression test for DFT-optimal and padded sizes with CV_32F and CV_64F types. The test cases include input/window preservation, ROIs, same source headers, and equivalent shift/response results.

Pull Request Readiness Checklist

  • 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 opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Comment thread modules/imgproc/test/test_pc.cpp Resolved
@asmorkalov asmorkalov added this to the 4.15.0 milestone Oct 14, 2026
@asmorkalov asmorkalov self-assigned this Oct 14, 2026
@pbkx
pbkx requested a review from asmorkalov October 14, 2026 07:12
Comment thread modules/imgproc/test/test_pc.cpp Resolved
Comment thread modules/imgproc/test/test_pc.cpp Resolved
@asmorkalov asmorkalov added the port to 5.x is needed Label for maintainers. Authors of PR can ignore this label Oct 14, 2026
@pbkx
pbkx requested a review from asmorkalov October 14, 2026 08:02
@asmorkalov

Copy link
Copy Markdown
Contributor

@pbkx Thanks for the contribution! The same bug exists in 5.x branch too. Could you submit complementary PR there?

@asmorkalov
asmorkalov merged commit 0332904 into opencv:4.x Oct 14, 2026
30 of 32 checks passed
@asmorkalov asmorkalov added port/backport done Label for maintainers. Authors of PR can ignore this and removed port to 5.x is needed Label for maintainers. Authors of PR can ignore this labels Oct 16, 2026
@pbkx pbkx mentioned this pull request Nov 8, 2026
5 of 6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug category: imgproc port/backport done Label for maintainers. Authors of PR can ignore this

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants