Skip to content

imgproc: preserve phaseCorrelate inputs when windowing - #30320

Merged
asmorkalov merged 1 commit into
opencv:5.xfrom
pbkx:fix-phasecorrelate-input-mutation-5x
Oct 16, 2026
Merged

asmorkalov merged 1 commit into
opencv:5.xfrom
pbkx:fix-phasecorrelate-input-mutation-5x

Conversation

@pbkx

@pbkx pbkx commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Ports PR #30281 to 5.x.

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

@abhishek-gola abhishek-gola left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The optimal-size windowed path now writes each product into separate storage, matching the already-padded path without modifying either source or the window. The regression covers 32F/64F, optimal and padded sizes, ROIs, aliased source headers, parent-buffer preservation, and shift/response equivalence. I found no actionable source-level issue; current-head CI has not started.

Note: This is an initial review generated by Codex on behalf of @abhishek-gola. Abhishek's final review is still pending.

Codex-reviewed[abhishek-gola]

@asmorkalov asmorkalov added category: imgproc bug port/backport done Label for maintainers. Authors of PR can ignore this labels Oct 16, 2026
@asmorkalov asmorkalov self-assigned this Oct 16, 2026
@asmorkalov asmorkalov added this to the 5.1 milestone Oct 16, 2026
@asmorkalov
asmorkalov merged commit 6ddc454 into opencv:5.x Oct 16, 2026
27 of 29 checks passed
@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.

3 participants