Fixes issue with libavif >= 1.3.0 where subsampling with identity matrix
coefficients is invalid. Aligns OpenCV AVIF writer with updated libavif
conformance rules.
Add optional template mask for findTransformECC #27952
Supersedes #22997
**Summary**
Add optional template mask support to findTransformECC so that only pixels valid in both the template and the image are used in ECC. Backward compatibility is preserved (existing signatures unchanged; one new overload adds templateMask).
**Motivation**
- Real-world frames often contain moving foreground artifacts (e.g., a football over a static field). Masking the object in one frame only is insufficient because its position changes independently of the background. Since we don’t know the warp a priori, we can’t back-project a single mask across frames. The correct approach is to supply both masks and take their intersection.
- Templates may include uninformative/low-texture or noisy regions, or partial overlaps with other objects. Excluding such regions from the alignment improves robustness and convergence.
This PR completes and replaces https://github.com/opencv/opencv/pull/22997
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
Handle near-zero convexity in convexHull #28043
### Pull Request Readiness Checklist
resolves https://github.com/opencv/opencv/issues/21482
closes https://github.com/opencv/opencv/issues/14401
Also skip a code that determines orientation inside rotatingCalipers and rely on the order after convexHull
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
Undistort points convergence #27993
I have looked into the `undistortPoints()` problem of issue #27916 and have found a solution. The problem is, as @Linhuihang has correctly pointed out, that the fixed-point iterations do not converge. Here are the functions which are optimized for the undistortion problem:
$$
\begin{aligned}
r^2 &= x'^2 + y'^2 \\
f_1(x') &= \frac{1 + k_4 r^2 + k_5 r^4 + k_6 r^6}{1 + k_1 r^2 + k_2 r^4 + k_3 r^6} (x'' - 2p_1 x' y' - p_2(r^2 + 2 x'^2) - s_1 r^2 + s_2 r^4) = x' \\
f_2(y') &= \frac{1 + k_4 r^2 + k_5 r^4 + k_6 r^6}{1 + k_1 r^2 + k_2 r^4 + k_3 r^6} (y'' - p_1 (r^2 + 2 y'^2) - 2 p_2 x' y' - s_3 r^2 - s_4 r^4) = y'
\end{aligned}
$$
where $x', y'$ are the undistorted points we want to compute and and $x'', y''$ are the given distorted points. This problem is solved using fixed-point iterations like
$$
x'_{k+1} = f_1(x'_k),\quad
y'_{k+1} = f_2(y'_k)
$$
I guess the issue here is that the distortion function does not necessarily satisfy the [Banach fixed-point theorem](https://en.wikipedia.org/wiki/Banach_fixed-point_theorem), i.e. the slope of the function can be too large. This can be seen in @Linhuihang's comment https://github.com/opencv/opencv/issues/27916#issuecomment-3417883642 - the point series jumps around and doesn't converge.
A common solution is to instead do damped fixed-point iterations, so that the updates are "more smooth".
$$
x'_{k+1} = (1 - \alpha) x'_k + \alpha f_1(x'_k),\quad
y'_{k+1} = (1 - \alpha) y'_k + \alpha f_2(y'_k)
$$
I have implemented a simple logic which starts with $\alpha = 1$ (so just like it is now) and reduces $\alpha$ whenever the optimization error would increase. This seems reasonable to me: the initial logic is to do normal fixed-point iterations and to gradually become "more damped" when we notice that we don't converge. Perhaps there is a better way to ensure convergence, but this is the most straightforward modification to the current code that I have found.
This problem is not due to the $\tau_x, \tau_y$ parameters; it also occurs when they are zero. In fact, the fixed-point iterations are done when the tilt correction of $\tau_x, \tau_y$ has already been applied. I have added a test to reproduce the problem. This PR fixes#27916.
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
make cuda::GpuMatND compatible with InputArray/OutputArray #23913
continuation of [PR#19259](https://github.com/opencv/opencv/pull/19259)
Make cuda::GpuMatND wrappable in InputArray/OutputArray
The goal for now is just wrapping, some functions are not supported (InputArray::size(), InputArray::convertTo(), InputArray::assign()...)
No new feature for cuda::GpuMatND
- [X] I agree to contribute to the project under Apache 2 License.
- [X] 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
- [X] The PR is proposed to the proper branch
- [X] 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
core: add copyAt() for ROI operation #27318
Close https://github.com/opencv/opencv/issues/27320
Close https://github.com/opencv/opencv/issues/27298
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
Optimize audio buffer duration calculation in MSMF capture. Fixes#27969#28017
### Description
Cache the repeated calculation of `(bit_per_sample/8)*nChannels` in a local variable to avoid redundant computations in `grabFrame()` and `configureAudioFrame()` functions.
### Changes
- Added `bytesPerSample` local variable in both functions
- Replaced 6 repeated calculations with the cached variable
- Improves performance in frequently called audio processing code
Fixes#27969
Added BitShift option to CLAHE #28014
Briefly, this PR is the fix of https://github.com/opencv/opencv/issues/28002
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] 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
docs(py): add pip-based install tutorial #27943
- New tutorial: `doc/tutorials/py_tutorials/py_setup/py_pip_install/py_pip_install.markdown` with anchor `{#tutorial_py_pip_install}`.
- Python setup TOC updated to include the new page near the top.
- Windows/Ubuntu/Fedora pages: added **Quick start (pip)** callout
- Expanded troubleshooting in the pip tutorial (env mismatch, headless GUI notes, wheel mismatches, Raspberry Pi/ARM guidance).
This aligns with the issue request to make `pip install opencv-python` the default path for Python newcomers and reduce confusion from legacy content.
Fixes#24360
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
Building OpenCV with oneAPI #28003
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
resolves https://github.com/opencv/opencv/issues/27580
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
imgproc: supports CV_SIMD_SCALABLE in pointSetBoundingRect #27479
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] 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
Fixed standard HoughLines output shift for rho. #27992
Closes: https://github.com/opencv/opencv/issues/25038
Replaces: https://github.com/opencv/opencv/pull/25043
Merge with https://github.com/opencv/opencv_extra/pull/1288
The original implementation introduces systematic shift (-rho/2) for odd indexes. Integer division just gives proper rounding.
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
Added CMake define option to enforce IPP calls in IPP HAL when building with IPP integration #27925
Extra build option needed to simplify custom builds with IPP integration to ensure the IPP calls done even in cases when the results are not bitwise compliant to the reference OpenCV implementation. Option name is ```WITH_IPP_CALLS_ENFORCED```, and it is disabled by default.
Requested by some IPP customers and might be used in general as a way providing calls with better performance for the cases the aligned precision is not as important aspect.
Supposed to be used in HAL only, so added only in IPP HAL CMake, currently it affects only Warp Affine, Warp Perspective and Remap integrations since the results may vary depending on HW and algorithm implementations.
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] 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
Fixed unrichable code with MSVC on x86 32-bit systems. #27991
Suppress the following warnings:
```
Warning: C:\GHA-OCV-5\_work\opencv\opencv\opencv\modules\gapi\src\streaming\onevpl\file_data_provider.cpp(131): warning C4702: unreachable code [C:\GHA-OCV-5\_work\opencv\opencv\build\modules\gapi\opencv_gapi.vcxproj]
Warning: C:\GHA-OCV-5\_work\opencv\opencv\opencv\modules\gapi\src\streaming\onevpl\source.cpp(77): warning C4702: unreachable code [C:\GHA-OCV-5\_work\opencv\opencv\build\modules\gapi\opencv_gapi.vcxproj]
Warning: C:\GHA-OCV-5\_work\opencv\opencv\opencv\modules\gapi\src\streaming\onevpl\source.cpp(82): warning C4702: unreachable code [C:\GHA-OCV-5\_work\opencv\opencv\build\modules\gapi\opencv_gapi.vcxproj]
Warning: C:\GHA-OCV-5\_work\opencv\opencv\opencv\modules\gapi\src\streaming\onevpl\source.cpp(103): warning C4702: unreachable code [C:\GHA-OCV-5\_work\opencv\opencv\build\modules\gapi\opencv_gapi.vcxproj]
Warning: C:\GHA-OCV-5\_work\opencv\opencv\opencv\modules\gapi\src\streaming\onevpl\source.cpp(90): warning C4702: unreachable code [C:\GHA-OCV-5\_work\opencv\opencv\build\modules\gapi\opencv_gapi.vcxproj]
Warning: C:\GHA-OCV-5\_work\opencv\opencv\opencv\modules\gapi\src\streaming\onevpl\source.cpp(94): warning C4702: unreachable code [C:\GHA-OCV-5\_work\opencv\opencv\build\modules\gapi\opencv_gapi.vcxproj]
Warning: C:\GHA-OCV-5\_work\opencv\opencv\opencv\modules\gapi\src\streaming\onevpl\source.cpp(86): warning C4702: unreachable code [C:\GHA-OCV-5\_work\opencv\opencv\build\modules\gapi\opencv_gapi.vcxproj]
Warning: C:\GHA-OCV-5\_work\opencv\opencv\opencv\modules\gapi\src\streaming\onevpl\source.cpp(99): warning C4702: unreachable code [C:\GHA-OCV-5\_work\opencv\opencv\build\modules\gapi\opencv_gapi.vcxproj]
Warning: C:\GHA-OCV-5\_work\opencv\opencv\opencv\modules\gapi\src\streaming\gstreamer\gstreamersource.cpp(366): warning C4702: unreachable code [C:\GHA-OCV-5\_work\opencv\opencv\build\modules\gapi\opencv_gapi.vcxproj]
Warning: C:\GHA-OCV-5\_work\opencv\opencv\opencv\modules\gapi\src\streaming\gstreamer\gstreamersource.cpp(360): warning C4702: unreachable code [C:\GHA-OCV-5\_work\opencv\opencv\build\modules\gapi\opencv_gapi.vcxproj]
Warning: C:\GHA-OCV-5\_work\opencv\opencv\opencv\modules\gapi\src\streaming\gstreamer\gstreamerpipeline.cpp(77): warning C4702: unreachable code [C:\GHA-OCV-5\_work\opencv\opencv\build\modules\gapi\opencv_gapi.vcxproj]
```
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
Fix missing vec_cvfo on IBM POWER9 due to unavailable VSX float64 conversion #27990
Replaces https://github.com/opencv/opencv/pull/27633
Closes https://github.com/opencv/opencv/issues/27635
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
docs(js): Fix Mat.clone() documentation to use mat_clone() for deep copy #27985
- Update code example to use ```mat_clone()``` instead of ```clone()```
- Add explanatory note about shallow copy issue due to Emscripten embind
Problem
- OpenCV.js documentation shows ```Mat.clone()``` usage, but this method performs shallow copy instead of deep copy due to Emscripten embind limitations, causing unexpected behavior where modifications to cloned matrices affect the original.
Related Issues and PRs
- Fixes documentation aspect of issue #27572
- Related to PR #26643 (js_clone_fix)
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] 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
Force empty output type where it's defined in API #27972
The PR replaces:
- https://github.com/opencv/opencv/pull/27936
- https://github.com/opencv/opencv/pull/21059
Empty matrix has undefined type, so user code should not relay on the output type, if it's empty. The PR introduces some exceptions:
- copyTo documentation defines, that the method re-create output buffer and set it's type.
- convertTo has output type as parameter and output type is defined and expected.
Fix alpha handling for blending in PNG format #27981
### Pull Request Readiness Checklist
closes#27974
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] 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