Skip to content

5.x merge 4.x#28774

Merged
asmorkalov merged 39 commits intoopencv:5.xfrom
asmorkalov:5.x-merge-4.x
Apr 10, 2026
Merged

5.x merge 4.x#28774
asmorkalov merged 39 commits intoopencv:5.xfrom
asmorkalov:5.x-merge-4.x

Conversation

@asmorkalov
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov commented Apr 7, 2026

OpenCV Contrib: opencv/opencv_contrib#4104
OpenCV Extra: opencv/opencv_extra#1333

#28397 from 0AnshuAditya0:fix-simd-oob-read-28396
#28461 from Ron12777:opt-clean
#28535 from AhmadDurrani579:4.x
#28589 from nmizonov:fix_ippiw_binary_usage
#28609 from pratham-mcw:core-rotate-neon-optimization
#28611 from Arths17:4.x
#28652 from mvanhorn:osc/28651-fix-reprojection-error-rmse
#28655 from usernotfound-101:cvmixchannels-warning-fix
#28684 from abhishek-gola:AVX_VNNI_support_4.x
#28686 from Lurie97:fix_inplace
#28698 from PDGGK:fix/android-utils-resource-leak
#28699 from PDGGK:fix/highgui-system-exit
#28701 from cuiweixie:fix/dnn-batchnorm-bias-blob-index
#28723 from akretz:fix-mean-perf
#28724 from ssam18:fix/resize-ngraph-two-inputs-28707
#28727 from asmorkalov:as/calibrate_perf_data
#28737 from vrabaud:asan
#28739 from pratham-mcw:core/fix-MeanStdDeviation-accuracytest
#28742 from asmorkalov:as/webp_win32_arm
#28747 from LHOOL1109:fix/python-zero-channel-crash
#28751 from asmorkalov:as/read_write_video_alpha
#28753 from vrabaud:asan
#28754 from vrabaud:intrin

Previous "Merge 4.x": #28673

nmizonov and others added 30 commits March 2, 2026 05:03
…copy (opencv#28608)

- Replace execute_process(tar) with file(ARCHIVE_EXTRACT) for native .zip support
  and better Windows path handling when CMAKE_VERSION >= 3.18
- Replace execute_process copy with file(COPY) and existence check for reliable
  CMakeLists.txt copying to avoid timing/path issues on Windows
- Maintains backward compatibility with older CMake versions and Linux behavior

Fixes issue opencv#28608
The tutorial code used cv.NORM_L2 (which takes a square root) and then
averaged those values. The correct RMSE formula should use NORM_L2SQR
to get squared errors, average them, and take the square root at the
end. Updated the explanatory text to match.

Fixes opencv#28651
…arning-fix

Add static integer casting for cvMixChannels, safer
When hasBias is true, CV_Assert must reference blobs[biasBlobIndex], not blobs[weightsBlobIndex], for the bias tensor.
Replace System.exit(-1) with exceptions in HighGui.java (opencv#28696) opencv#28699

## Summary

Library code should never call System.exit() as it kills the entire JVM. Replaced all 3 instances with appropriate exceptions.

Closes opencv#28696

## Changes

- `imshow()` with empty image: `System.exit(-1)` -> `throw new IllegalArgumentException("Image is empty")`
- `waitKey()` with no windows: `System.exit(-1)` -> `throw new IllegalStateException("No windows created. Call imshow() first")`
- `waitKey()` with null window image: `System.exit(-1)` -> `throw new IllegalStateException("No image set for window: ... Call imshow() first")`
- `InterruptedException` catch: `printStackTrace()` -> `Thread.currentThread().interrupt()`
…ion-error-rmse

calib3d: fix reprojection error RMSE calculation in Python tutorial
Convert exportResource() and loadResource() to use try-with-resources
to ensure InputStream, FileOutputStream, and ByteArrayOutputStream are
properly closed even when exceptions occur.

Also remove printStackTrace() in exportResource(), as the exception is
already rethrown as CvException with the original exception details.

Signed-off-by: ffccites <99155080+PDGGK@users.noreply.github.com>
Benchmark cv::mean instead of cvtest::mean
Optimize calibrateCamera with Schur‑complement LM and parallel Jacobian accumulation opencv#28461

## Summary

- Optimized `calibrateCamera` for faster runtime without changing outputs using Schur‑complement LM, Parallel Jacobian accumulation, alongside other optimizations.
- Reduced time complexity from O(n^3) to O(n)
- Add a perf test that uses a 500-image chessboard dataset for performance testing.

## Performance
<img width="1200" height="800" alt="base_vs_fast_results" src="https://github.com/user-attachments/assets/6dafa19f-f9cb-4f7f-ba40-0940373712e8" />
<img width="1200" height="800" alt="fast_vs_ceres_results" src="https://github.com/user-attachments/assets/7157af27-8a2b-4810-8b53-3cc9972a8493" />
<img width="1200" height="800" alt="base_vs_fast_param_deviation" src="https://github.com/user-attachments/assets/fe4f954c-34f9-4b9a-b1b2-46e4c76ce08c" />


[Testing repo
](https://github.com/Ron12777/OpenCV-benchmarking)
## Testing
- All local tests pass 

## Related

- [opencv_extra PR with test images](opencv/opencv_extra#1312)


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
- [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
…-leak

Fix resource leaks in Android Utils.java (opencv#28697)
Replace calibration images with saved image points.
…28396

Fixes opencv#28396 : out-of-bounds read in SIMD type conversion opencv#28397

Fixes opencv#28396
Fixes opencv#27080

The vx_load_expand function in WASM intrinsics was using 
wasm_v128_load which always loads a full 128-bit register 
(16 bytes), even when the function only needed 8 elements.

For example, when converting uint8 to float32:
- vx_load_expand needs 8 uint8 elements
- But wasm_v128_load reads 16 bytes from memory
- This causes an 8-byte out-of-bounds read

### 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
…uts-28707

dnn: fix Resize initNgraph for two-input case opencv#28724

## Summary

Fixes the issue opencv#28707

When a Resize/Upsample layer has two inputs, the data tensor and a reference tensor whose **shape** defines the output spatial size, the OpenVINO/NGRAPH backend's `initNgraph()` was ignoring `nodes[1]` entirely and relying solely on the `outHeight`/`outWidth` member variables.

These variables are set by `finalize()` from the pre-computed output blob dimensions. However, when the output shape is determined dynamically at runtime from the second input, `finalize()` sets them from the live tensor, but the OpenVINO backend calls `initNgraph()` to build a static compiled graph. If the member variables are 0 at that point, the compiled `Interpolate` node gets hardcoded with `{0, 0}` output dimensions, causing CV_Assert failure: {N,C,0,0} vs {N,C,H2,W2}
Otherwise, ASAN could return an error:
"runtime error: addition of unsigned offset"
Force step to be ptrdiff_t in resize
Fix Windows build issues with IPPICV unpack and IPPIW CMakeLists.txt …
…ation-accuracytest

core: fix meanStdDev bug by using separate variables v2, v3 in sumsqr_
…imization

core: add NEON implementation for rotate function opencv#28609

- This PR adds a NEON intrinsics-based implementation for the rotate function in matrix_transform.cpp for Windows-ARM64.
- The optimized implementation uses  ARM NEON intrinsics to accelerate the internal transpose step used by the rotate function.
- In the x64 architecture, the rotate operation benefits from IPP-based optimized implementations. However, on ARM64, the execution falls back to the scalar implementation, which results in lower performance.
- To achieve performance parity with x64, a NEON-based SIMD implementation has been added for ARM64. 
- After introducing these changes, the rotate function showed noticeable performance improvements on ARM64 platforms.
<img width="1009" height="817" alt="image" src="https://github.com/user-attachments/assets/8bec0041-b19c-4fc8-9103-532746224515" />

 
- [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
Do not use AVX options on Windows ARM in libwebp.
…-blob-index

dnn: fix BatchNorm bias blob index in validation
videoio(gstreamer): fix timestamp drift and color negotiation on Apple opencv#28535

This commit addresses two issues on macOS with Apple M3 hardware:
1. Replaces floating-point timestamp math with gst_util_uint64_scale_int to ensure nanosecond precision.
2. Explicitly forces I420 format in the encoding profile to prevent hardware encoder negotiation failure.

### 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
vrabaud and others added 8 commits April 2, 2026 16:01
Compilation fails on platforms that are case-dependent, apparently
some windows arm 64. The source of truth is lower case:
https://github.com/yuikns/intrin/blob/master/intrin.h
…l-crash

python: fix segfault on 0-channel numpy array input opencv#28747

### Pull Request Readiness Checklist

- [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
      N/A: a Python unit test is added in `modules/python/test/test_mat.py`. No external test data required.
- [x] The feature is well documented and sample code can be built with the project CMake
      N/A: this is a bug fix, not a new feature. No documentation update needed.

### Problem

Passing a numpy array with shape `(H, W, 0)` (0 channels) to any OpenCV function that accepts a `Mat` argument (e.g. `cv2.resize`, `cv2.warpAffine`, `cv2.blur`) causes a **segfault**.

**Reproducer:**
```python
import cv2
import numpy as np

arr = np.zeros((100, 100, 0), np.uint8)
cv2.resize(arr, (200, 200))  # segfault
```

### Root Cause

In `modules/python/src2/cv2_convert.cpp`, the numpy→Mat conversion checks channel validity only against `CV_CN_MAX` (upper bound):

```cpp
if (channels > CV_CN_MAX)   // channels=0 passes this check
```

With `channels=0`, `CV_MAKETYPE(0, 0)` produces `type=-8`, which corrupts the Mat's internal type field and causes undefined behavior downstream.

### Fix

Extend the check to also reject `channels < 1`:

```cpp
if (channels < 1 || channels > CV_CN_MAX)
```

**After fix:**
```
cv2.error: src unable to wrap channels, invalid count (0, must be in [1, 512])
```

### Notes

- This affects all functions that accept a `Mat` input, not just `cv2.resize`
- The same bug exists in the `5.x` branch
- A 0-channel array has no valid OpenCV Mat representation; rejecting it with a clear error is the correct behavior and poses no backward-compatibility risk (the previous behavior was a crash)
core(opencl): fix inplace transpose race by enforcing LLSS ordering via local barrier opencv#28686

The former inplace transpose implementation allowed a reordering of global-memory operations across work-items. Specifically, the intended LLSS (Load–Load–Store–Store) access pattern could be reordered by the GPU into LSLS (Load–Store–Load–Store), causing partially written tiles to be observed by other work-items and producing incorrect output.

This patch introduces a tiled LDS-based algorithm and adds an explicit:

    barrier(CLK_LOCAL_MEM_FENCE);

between the load and store phases.

### 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
…lpha

Added alpha channel support to VideoWriter and VideoCapture.
@asmorkalov asmorkalov requested review from abhishek-gola, dkurt and mshabunin and removed request for mshabunin April 10, 2026 07:48
@asmorkalov
Copy link
Copy Markdown
Contributor Author

@dkurt @abhishek-gola @mshabunin Could you take a look?

@asmorkalov asmorkalov merged commit 1a6f669 into opencv:5.x Apr 10, 2026
24 of 25 checks passed
@asmorkalov asmorkalov self-assigned this Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.