Commit Graph

27422 Commits

Author SHA1 Message Date
Kaustubh Arora
a25e124d2b dnn: enable test_quantizelinear_blocked_symmetric
The case quantizes with block_size=2 to output_dtype=INT16, so it is
covered by the int16 support added in the previous commit.
2026-10-25 18:04:02 +05:30
Kaustubh Arora
92c551df0e dnn: support int16/uint16 in QuantizeLinear and DequantizeLinear
ONNX opset 21 allows INT16 and UINT16 as the quantized type of
QuantizeLinear and DequantizeLinear. The importer already maps them to
CV_16S/CV_16U, but both layers stopped at a CV_Assert that only listed the
8-bit, int32 and fp8 types, so the four conformance cases for these dtypes
were on the parser denylist.

Accept CV_16U/CV_16S in both layers and add the dispatch branches for the
fp32/fp16 scale and activation combinations, mirroring the existing
CV_8U/CV_8S ones. The shared kernels already handle the wider types via
saturate_cast. Remove the four cases from the denylist.

Verified on macOS arm64: before the change the 8 cases
(test_{de}quantizelinear_{u,}int16 x OCV/CPU, OCV/CPU_FP16) fail on the
assertion; after it the whole Test_ONNX_conformance suite passes
(3584 tests) and the quantization unit tests pass (118 tests).
2026-10-25 03:57:01 +05:30
Varun Jaiswal
56dabe2b19 Merge pull request #30289 from varun-jaiswal17:dnn-int8-cpu-perf
dnn : int8 optimisation - #30289

### Correctness
- **AVX-VNNI 1x1 conv, leftover pixels:** the last `H*W % 8` output pixels read the VNNI-repacked
  weights in the wrong order. Fixes the wrong top-1 of MobileNetV2 and DenseNet121 int8 with VNNI.
- **Padded taps in scalar paths:** the depthwise (AVX2) tail and the NEON kxk scalar path skipped
  out-of-image taps instead of using the input zero point. The VNNI kxk kernel now never leaves a
  tile under 8 pixels. 
### Speed
- **First conv:** quantizing the float image is now parallel and vectorized. A float-input conv
  with up to 4 channels runs as a 1x1 conv over each pixel's window. First conv 5-6x faster
  (ResNet50: 0.88 -> 0.16 ms). `OPENCV_DNN_INT8_CONV_WINDOW_PACKING=0` disables the window packing.
- **AVX-VNNI depthwise conv:** a new kernel transposes input rows into one row per channel and
  adds 4 taps for 8 pixels with one `pshufb` + `vpdpbusd`. Depthwise about 2x faster, output
  bit-identical.
- **int8 MatMul at batch 1:** uses all threads instead of one. AlexNet int8: 2.75 -> 1.52 ms.
- **Asymmetric padding:** convs with TF "SAME" padding at stride 2 are now fused to int8 instead of
  running in float between Dequantize and Quantize. Float convs in EfficientNet-Lite4 and MP hand
  pose: 5 -> 0-1.
- **Broadcast int8 Add/Mul:** copies whole contiguous runs in parallel instead of computing an
  index per element. 
- **int8 Quantize/Dequantize:** AVX2 fast path for signed int8; per-tensor Q/DQ keep the block
  layout.

### Tests

- Companion PR : opencv/opencv_extra#1436 (test data).

### Results (ms, i9-14900KS , default threads)

| Model | 5.x before (ms) | this PR (ms) | ONNX Runtime 1.30 (ms) | Speedup vs 5.x | ORT / this PR |
|---|---|---|---|---|---|
| DenseNet121 int8 | 109.4 | 14.7 | 16.1 | 7.43x | 1.09x |
| PP-OCRv3 det int8 | 65.7 | 12.7 | 33.1 | 5.15x | 2.60x |
| SFace int8 | 8.1 | 3.0 | 19.0 | 2.75x | 6.43x |
| EfficientNet-Lite4 int8 | 4.1 | 2.9 | 1.9 | 1.40x | 0.67x |
| EfficientNet-Lite4 qdq | 4.6 | 3.1 | 2.0 | 1.49x | 0.65x |
| MP hand pose int8 | 2.5 | 0.8 | 2.2 | 3.06x | 2.69x |
| PPHumanSeg int8 | 2.6 | 1.9 | 5.6 | 1.41x | 3.02x |


Co-authored with @Prasadayus

### 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
- [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
2026-10-24 12:31:46 +03:00
Alexander Smorkalov
048f050d5d Merge pull request #30475 from asmorkalov:as/tanh_clamp_amrv7a
Clamp tanh layer input to -9..9  as it saturates near the values.
2026-10-24 12:03:58 +03:00
Alexander Smorkalov
4058787c82 Merge pull request #30407 from asmorkalov:as/ocl_fp64
Fixed FP64 build in matchTemplate kernel
2026-10-23 18:34:50 +03:00
Alexander Smorkalov
3f12ad88ab Merge pull request #30476 from asmorkalov:as/pre_5.1.0
Pre-release 5.1.0 versions update
2026-10-23 15:31:14 +03:00
Kumataro
d23780fb56 Merge pull request #30431 from Kumataro:trial/avif_update_test_for_each_bitdepth
imgcodecs(avif): fix norm calculation and extend 16-bit tests - #30431

- Correct lossy test normalization from dividing by total samples (N)  to root-mean-square (RMS) error divided by sqrt(N), and recalibrate  thresholds with margin for 8/10/12/16-bit tests.
- Extend 16-bit AVIF tests to cover all supported channel counts  (1, 3, and 4 channels) using testing::Combine.

### 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.
- [ ] The feature is well documented and sample code can be built with the project CMake
2026-10-23 15:02:23 +03:00
Alexander Smorkalov
54fbb6bd86 Pre-release 5.1.0 versions update 2026-10-23 14:28:38 +03:00
Alexander Smorkalov
fb2779ba6a Clamp tanh layer input to -9..9 as it saturates near the values. 2026-10-23 12:27:15 +03:00
sanjayk9
f62288c4a1 Merge pull request #30297 from sanjayk9:dnn-matmul-nobias-gemm
dnn: skip MatMul's zero-fill when there is no bias - #30297

Without a bias, MatMul pre-zeroed the whole output with a single-threaded memset and then still passed beta = 1 into the gemm, forcing every kernel to read and multiply-add against that zeroed buffer. Passing beta = 0 instead removes the memset and lets MLAS/fastGemmThin write the product directly. Measured 31-50% faster on a small, write-heavy, no-bias shape (512x32x512, 8 threads); `MatMul.matmul/41` and the new `MatMul.matmul_dynamicB/41` cover the constant-B and dynamic-B paths.

### 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
- [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.
- [ ] The feature is well documented and sample code can be built with the project CMake
2026-10-23 11:42:16 +03:00
Lazizbek Ergashev
7c3d04a044 Merge pull request #29799 from lazerg:fix/issue-29798-dilate-bool
imgproc: accept CV_Bool input in morphological operations - #29799

### Pull Request Readiness Checklist

Fixes #29798

In 5.0 `cv::Mat_<bool>::depth()` returns `CV_Bool` instead of `CV_8U`, so the morphology filter factories in `morph.simd.hpp` no longer matched any branch and threw `Unsupported data type`. This worked in 4.x.

`CV_Bool` is a 1-byte 0/1 type, so it is dispatched through the same `uchar` min/max filters as `CV_8U`, and the default border value follows the `CV_8U` case (1 for erode, 0 for dilate). The OpenCL path bails out for `CV_Bool` and falls back to the CPU implementation, since `ocl::typeToStr` has no mapping for it.

Accepting `CV_Bool` also exposed a latent bug in `FilterEngine::init`: `borderElemSize` was computed from `CV_MAT_DEPTH(srcType) >= CV_32S`, which assumes the depth enum is ordered by element size. `CV_Bool` is 9, so a 1-byte type took the `sizeof(int)` branch and `borderElemSize` became 0, leaving `borderTab` empty and making every non-`BORDER_CONSTANT` erode/dilate read through a null pointer. It now keys off `CV_ELEM_SIZE1` instead. `CV_16F`/`CV_16BF` had the same latent miscomputation.

Added a test comparing `Mat_<bool>` against the equivalent `CV_8UC1` mask for erode, dilate, open and close over the three structuring element shapes and four border types, plus in-place and multi-iteration calls.

`MORPH_GRADIENT`/`TOPHAT`/`BLACKHAT` remain unsupported for `CV_Bool`: they subtract two masks, which has no meaning for a boolean type, and they throw rather than returning a wrong result.

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
2026-10-23 10:56:49 +03:00
Alexander Smorkalov
de4682420c Fixed FP64 build in matchTemplate kernel 2026-10-23 10:20:39 +03:00
Vincent Rabaud
7bd8de1f31 Merge pull request #29909 from vrabaud:gemm
Do not call Lapack for small operations. - #29909

This reduces the cache for GEMM in calibration: the transposed Jacobian is 6 x 2Number points while the result is 6 x 1.

The previous code was only looking at the input number of rows.

### 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
2026-10-23 09:26:44 +03:00
Hanbin Bae
2dfe422d7f Merge pull request #30405 from Anemptyship:leader/attention-memory
dnn: avoid unused quadratic workspace for MLAS attention - #30405

`AttentionLayerImpl` allocates a dense `[batch * heads, sequence, sequence]` probability buffer before calling MLAS FlashAttention, even though that path never uses it. With 12 heads and 8,192 tokens, this is an unused 3 GiB allocation that can make inference fail before the tiled kernel runs.

This patch shares the existing fast-path eligibility check between memory planning and execution. It keeps one-element placeholders for the unused probability and output workspaces, preserving the internal buffer indices used by RoPE. If MLAS declines the call, the generic path allocates the dense buffers it needs. Masked attention and builds without MLAS keep their existing workspace plans. The numerical kernels are unchanged.

I reproduced the allocation with a generated FP32 ONNX Attention model loaded through `readNetFromONNX`, using the 5.x graph engine. For batch 1, 12 heads, head width 16 and 8,192 tokens:

| Measurement | Before | After |
| --- | ---: | ---: |
| Largest `cv::Mat` allocation | 3 GiB | 18 MiB |
| Peak live `cv::Mat` storage | 3,279,180,288 bytes | 51,663,368 bytes |
| Forward with a 512 MiB address-space limit | Allocation failure | Completes |
| Peak RSS without the limit | 65,664 KiB | 65,616 KiB |

The allocation trace goes through `allocateLayerOutputs` and `Mat::fit` before the layer's `forward`. The same failure is resolved at 4,096 and 16,384 tokens; at 16,384 tokens, the largest allocation drops from 12 GiB to 36 MiB. Outputs from the constrained runs match the unrestricted runs byte for byte.

The limit above is Linux `RLIMIT_AS`, which limits virtual address space. RSS barely changes because the unused buffer is not touched. The allocation measurements cover `cv::Mat` storage only.

Validation on Linux x86-64:

- 40 targeted tests pass with MLAS in Release, and the same 40 pass under ASan/UBSan with MLAS and SIMD disabled. The workspace regression test fails against the baseline library.
- 56 ONNX baseline/patch comparisons are byte-identical, covering sequence lengths, 1/6 threads, static and dynamic weights, masks, and RoPE. Four of these force `mlasFlashAttention` to return false after dispatch to exercise fallback from a compact workspace plan.
- Reusing a graph across changing sequence lengths passes 40 comparisons against fresh graphs on each version. A separate layer-level matrix adds 144 byte-identical comparisons.
- The existing Attention perf fixture passes all five cases at 1 and 6 threads with `--perf_verify_sanity=true` and no regression data files. This includes new constant-weight cases at 257, 1,024, and 4,096 tokens. Separate longer pinned timing runs measured approximately +0.5% at 257 tokens and -1.1% at 1,024 tokens; timings vary on this shared host, so this PR makes no speedup claim.

The half-input audit passed six configurations that the graph promotes to FP32. Static, unmasked FP16 constants exposed a separate existing weight-packing issue: the baseline already produces invalid outputs, and ASan reports an out-of-bounds read in unchanged packing code. Those cases are excluded from passing validation. ARM and other platforms still need CI.

This follows the MLAS integration in #29126. #30126 addresses a different source of memory use (weight ownership), but touches the same class. `AttentionOnnxAiLayerImpl` is outside this change.

### 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 code under GPL or another license incompatible with OpenCV.
- [x] The PR targets the proper branch (`5.x`).
- [x] Related work is referenced above; the reproducer and measurements describe the bug.
- [x] Accuracy and performance tests are included. They generate their inputs and require no new `opencv_extra` data.
- [x] No public API changes or new samples requiring documentation.
2026-10-23 08:19:07 +03:00
Alexander Smorkalov
059f94689e Merge pull request #30469 from sunhaiyong1978:5.x
core: Add the missing `<climits>` include to intrin_lsx.hpp.
2026-10-23 08:07:01 +03:00
Alexander Smorkalov
e57ee0c93b Merge pull request #30454 from asmorkalov:as/ffmpeg_interlaced
Port of videoio(ffmpeg): fix black frames for interlaced video 30300 to 5.x
2026-10-23 08:05:28 +03:00
Kumataro
0d0804b567 Merge pull request #30308 from Kumataro:fixGCC16warning
core/dnn: resolve GCC 16 -Wmaybe-uninitialized and -Warray-bounds warnings - #30308

- core(nd_copy): ensure copyBatch only executes runPlans when np > 0.
- dnn(test): add reserve(3) to input vector to quiet compiler bounds checks.

### 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.
- [ ] The feature is well documented and sample code can be built with the project CMake
2026-10-23 08:02:21 +03:00
Alexander Smorkalov
a1bd572bd2 Merge pull request #30457 from asmorkalov:fix-getrectsubpix-ipp-border-5.x
imgproc: don’t use ippiCopySubpixIntersect for windows crossing the image border - #30363
2026-10-23 08:00:20 +03:00
Alexander Smorkalov
1bafb36701 Merge pull request #30455 from asmorkalov:as/armv7_round_relax_test
Relaxed v_round vs cvRound checks.
2026-10-23 07:44:42 +03:00
Alexander Smorkalov
1de42d414e Merge pull request #30458 from asmorkalov:as/armv7_divide
Updated test data for division to satisfy armv7a.
2026-10-23 07:44:21 +03:00
Sun Haiyong
330c0dbfd5 core: Add the missing <climits> include to intrin_lsx.hpp.
When compiling with GCC 16.2.0, I encountered the following error:

modules/core/include/opencv2/core/hal/intrin_forward.hpp:204:49: error: 'INT_MAX' was not declared in this scope
  204 |     SV32 sat  = v_xor(v_shr<31>(hi), SETALL_S32(INT_MAX)); \
2026-10-23 10:10:05 +08:00
Shiven Solanki
ce58bb1ee7 Merge pull request #30448 from sshivensolanki:fix-ocl-convertto-32s-macos
core: accept both float->int saturation results in OCL ConvertToSaturate test - #30448

Fixes the `macOS-x64 / BuildAndTest` failure from #30386, which makes 5.x macOS-x64 CI red for every PR (e.g. #30302):

```
[ RUN      ] OCL_MatrixOperation/ConvertToSaturate.Accuracy/16, where GetParam() = (CV_32F, CV_32S)
test_matrix_operation.cpp:247: Failure
  cv::countNonZero(diff)
    Which is: 2
```

INT_MAX isn't representable in float, so a saturated `CV_32F -> CV_32S` result can legitimately be either value:

- x86 CPU (`v_round` / `cvRound`) clamps to `CV__FLT2INT_MAX_F` = 2147483520 before converting (since #30007).
- OpenCL `convert_int_sat_rte` and NEON `vcvtnq_s32_f32` give INT_MAX = 2147483647.

So on an x86 host the out-of-range inputs `3e9` and `1e20` differ by 127 between `Mat` and `UMat`. On Apple M1 both sides give INT_MAX, which is why it only shows up on macOS-x64.

For this pair the test now clamps both results to 2147483520 before the exact comparison, i.e. it accepts any value in [2147483520, INT_MAX] as saturated. In-range values and all other depth pairs are still compared exactly.

**Testing** (Apple M1 Pro, OpenCL on; native arm64 build and an x86_64 build run under Rosetta 2)

`Mat::convertTo` vs `UMat::convertTo` for `CV_32F -> CV_32S`:

| input | arm64 CPU | x86_64 CPU | OpenCL |
|---|---|---|---|
| 3e9  | 2147483647 | 2147483520 | 2147483647 |
| 1e20 | 2147483647 | 2147483520 | 2147483647 |

The x86_64 build reproduces the CI mismatch. With this change, on both builds:

- `opencv_test_core --gtest_filter=*ConvertToSaturate*`: 135 passed.
- `opencv_test_core --gtest_filter=OCL_*:*ConvertTo*:*convertTo*:*Core_ConvertScale*`: 7549 passed.

### 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.
- [ ] The feature is well documented and sample code can be built with the project CMake
2026-10-22 18:55:31 +03:00
Alexander Smorkalov
e552fd3c2d Updated test data for division to satisfy armv7a. 2026-10-22 17:20:33 +03:00
Pulk17
a90814606d imgproc: don’t use ippiCopySubpixIntersect for windows crossing the image border - #30363 2026-10-22 17:11:33 +03:00
Alexander Smorkalov
9502376b96 Relaxed v_round vs cvRound checks. 2026-10-22 15:46:42 +03:00
xieofxie
83f8d6e6c6 Merge pull request #30332 from xieofxie:hualxie/enable-mlas-windows-arm64
dnn: enable vendored MLAS on Windows ARM64 with MSVC - #30332

Close https://github.com/opencv/opencv/issues/30330
After https://github.com/opencv/opencv/pull/30331

### Summary

Enable OpenCV DNN’s vendored MLAS implementation on Windows ARM64 using Microsoft’s C++ compiler (`cl.exe`).

This change builds on the separate MLAS target architecture detection fix.

MLAS is currently disabled on all Windows targets. Enabling ARM64 requires more than removing that restriction: the GNU-style `.S` sources cannot be used by the MSVC toolchain, and the vendored Windows sources lack the SGEMV kernel used by the single-row fast path.

This change:

- Adds the Windows ARM64 SGEMV kernel from the same ONNX Runtime revision as the existing vendored sources.
- Preprocesses the native SGEMM and SGEMV `.asm` files with `cl.exe`, then assembles them with `armasm64`.
- Includes the generated assembly objects in `opencv_dnn`, with configuration-specific output paths.
- Enables MLAS only for Microsoft `cl.exe` targeting ARM64. Other Windows toolchains and targets remain disabled.
- Adds GEMM and SDPA accuracy coverage and documents the Windows build requirements.

The implementation uses the existing upstream `MlasHGemmSupported` probe. No additional HGEMM or FP16 workaround is introduced.

### Validation

On Windows ARM64, based on upstream commit `3074f64`:

- Release and Debug DNN builds linked successfully.
- MLAS and both NEON assembly kernels were enabled.
- All **116 selected tests passed in each configuration**, covering GEMM, single-row GEMV through FlashAttention, transposition, odd-sized tails, and accumulation across FlashAttention blocks.
- CMake guard checks confirmed unsupported Windows compiler/target combinations remain disabled.

A complete Python wheel has not been rebuilt, and performance benchmarks have not been run.

### Related work

- [[opencv/opencv#29343](https://github.com/opencv/opencv/pull/29343)](https://github.com/opencv/opencv/pull/29343): temporary blanket Windows disable; this PR enables only the supported MSVC ARM64 configuration.
- [[opencv/opencv#29885](https://github.com/opencv/opencv/issues/29885)](https://github.com/opencv/opencv/issues/29885): related Windows x86/x64 and clang-cl problems, outside this PR’s scope.
- [[opencv/opencv#29362](https://github.com/opencv/opencv/pull/29362)](https://github.com/opencv/opencv/pull/29362): existing HGEMM capability-probe fix, retained unchanged.

### 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
2026-10-22 14:39:57 +03:00
Alexander Smorkalov
4b25e3b32e Port of videoio(ffmpeg): fix black frames for interlaced video 30300 to 5.x 2026-10-22 13:53:03 +03:00
Abhishek Gola
781f49134b Merge pull request #30430 from sshivensolanki/opt-findnonzero-simd
core: SIMD fast path for findNonZero on 8-bit inputs
2026-10-22 14:30:34 +05:30
Alexander Smorkalov
a9a1805e09 Merge pull request #30365 from ternaus:codex/box-filter-roi-inplace
fix(imgproc): preserve ROI halos in in-place box filtering 🤖🤖🤖
2026-10-22 11:54:13 +03:00
Alexander Smorkalov
d4041cc565 Merge pull request #30220 from vrabaud:small
check element count in isScalarLikeMat for 1x1 multi-channel Mats
2026-10-22 11:34:51 +03:00
Savya Sanchi Sharma
4c20250a62 Merge pull request #29474 from SavyaSanchi-Sharma:extra_parsers
Remove Tensorflow Importer - #29474

[PR OpenCV Extra](https://github.com/opencv/opencv_extra/pull/1390)
[PR OpenCV Contrib](https://github.com/opencv/opencv_contrib/pull/4171)
Removed tensorflow importers

### 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
2026-10-22 11:06:53 +03:00
熊建祐
1d740084b7 Merge pull request #30433 from JoyBoy900908:fix/js-mat-clone-emscripten
fix(js): restore deep copy behavior of Mat.clone() - #30433

## Description

Fixes #30408.

With Emscripten 4+, the existing `onRuntimeInitialized` callback can be registered after runtime initialization has already completed. As a result, the override of Emscripten's shallow `ClassHandle.clone()` is never applied, causing `cv.Mat.clone()` to perform a shallow copy instead of the expected deep copy.

This PR applies the `mat_clone` override immediately when `cv.Mat` is available, while retaining the initialization callback as a fallback.

## Changes

- Restore deep-copy behavior for `cv.Mat.clone()`.
- Preserve the existing `onRuntimeInitialized` callback.
- Add regression tests for matrix data independence and cloning non-contiguous ROIs.

## Testing

Environment:
- OpenCV 5.x
- Emscripten 6.0.12
- Node.js 22.23.3

Results:
- Confirmed the original shallow-copy behavior before the fix.
- Verified deep-copy behavior after the fix.
- Verified that cloning a non-contiguous ROI produces independent, continuous data.
- `CoreMat.test_mat_creation`: 91/91 assertions passed.
- Full OpenCV.js test suite: 414 passed, 8 failed.

The remaining eight failures involve heap-memory views and unavailable JavaScript bindings. These failures have not yet been verified against an unmodified baseline.
2026-10-22 10:34:34 +03:00
Alexander Smorkalov
e32e4da189 Merge pull request #30449 from uwezkhan:ply-vertex-count-bound
ptcloud: reject PLY vertex count above INT_MAX in readNamedProperties 🤖🤖🤖
2026-10-22 10:26:09 +03:00
Alexander Smorkalov
f1c1be300d Merge pull request #30437 from sneumueller-cloudflight:fix/dnn-opencl-stdpow-5x
dnn: use pow not std::pow in OpenCL kernels
2026-10-22 09:05:48 +03:00
Alexander Smorkalov
b1f6fdae9b Merge pull request #30441 from pratham-mcw:pyrMeanShiftFiltering_opt
imgproc: parallelize cv::pyrMeanShiftFiltering's per-row loop
2026-10-22 09:03:53 +03:00
Uwez Khan
95bc3725d4 ptcloud: reject PLY vertex count above INT_MAX in readNamedProperties 2026-10-22 10:33:28 +05:30
Vincent Rabaud
a8584653db Fix wasm compilation
Move v_pack_trunc down after v_shr is declared. Otherwise, the error is:
error: use of undeclared identifier 'v_shr'
  474 | OPENCV_HAL_IMPL_SATURATING_PACK_64(v_int64x2, v_uint64x2, v_int32x4, v_uint32x4, v_setall_s32, v_pack_trunc, v_pack_trunc)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
OpenCV/core/hal/intrin_forward.hpp:202:28: note: expanded from macro 'OPENCV_HAL_IMPL_SATURATING_PACK_64'
  202 |     SV32 hi = PACK_TRUNC_S(v_shr<32>(a), v_shr<32>(b)); \
2026-10-21 17:34:39 +02:00
Pratham Kumar
6f3b841a56 imgproc: parallelize cv::pyrMeanShiftFiltering's per-row loop 2026-10-21 19:37:46 +05:30
Alexander Smorkalov
c8628d471e Merge pull request #30348 from pranayr710:fix/absdiff-64s
core: saturate cv::absdiff on CV_64S instead of returning a negative value
2026-10-21 15:56:07 +03:00
Alexander Smorkalov
711bc1b0b1 Merge pull request #30170 from officialarghya29:fix/video-trackervit-normalization
video: fix the TrackerVit input scaling factor
2026-10-21 15:51:13 +03:00
Vladimir Iglovikov
bed8a96706 Merge pull request #30325 from ternaus:codex/pow-simd-mask
core: interleave SIMD pow math and combine masks 🤖🤖🤖 - #30325

Partially addresses #30324.

Interleave the two independent SIMD log/exp chains used by fractional `pow` and combine their nonpositive-mask reductions. Arithmetic, scalar fallback, load widths, and alias-tail guards are preserved.

On Apple M4 Max / AppleClang 21 / one thread, the RGB float32 reproduction takes **3.308 → 2.901 ms** for `p=1.5` and **3.324 → 2.956 ms** for `p=1.4` (before → after). This recovers part of the 5.x regression; parity with 5.0.0 is not established.

Validation: 404 accuracy tests and 36 public performance cases pass; 84 native before/after cases are bitwise identical. Half performance outputs are converted before sanity checking. Linux performance remains unmeasured.

### Pull Request Readiness Checklist

- [x] I agree to contribute under Apache 2 License.
- [x] No GPL/incompatible source was used.
- [x] Proposed to 5.x.
- [x] Linked to the original report and related work.
- [x] Accuracy and performance tests included; inputs are generated, so no opencv_extra data patch is required.
- [x] No public API/documentation change; core accuracy/perf targets build locally.
2026-10-21 15:07:53 +03:00
Stefan Neumüller
948f03613f dnn: use pow not std::pow in OpenCL kernels
5622958189 replaced pow() with std::pow() in three OpenCL C kernel
files. OpenCL C is a C99-derived language and has no std namespace, so
these kernels fail to compile at runtime on the GPU (e.g.
CL_BUILD_PROGRAM_FAILURE: use of undeclared identifier 'std') and dnn
silently falls back to CPU for the affected activations, LRN and fused
conv layers. Revert to the plain built-in pow() in the kernels.
2026-10-21 11:47:17 +00:00
Vincent Rabaud
9548c94917 check element count in isScalarLikeMat for 1x1 multi-channel Mats
isScalarLikeMat(sc, cn) previously returned true whenever rows == 1 and
cols == 1 (as long as nval <= 4), without checking whether nval matches
1 or the other operand's channel count cn.

As a result, a 1x1 multi-channel Mat (e.g. 1x1 CV_32FC3, nval == 3) was
mistakenly treated as a scalar for a different channel count (e.g.
cn == 1 when multiplied by a cv::Scalar converted to a 4x1 CV_64FC1 Mat
in Mat::mul). In arithm_op, this caused s1 and s2 to both be true,
demoting the actual scalar operand s2 to false and broadcasting the
operands into a 4x1 CV_32FC3 result instead of a 1x1 CV_32FC3 result.

Require nval == 1 || nval == cn in isScalarLikeMat so that a 1x1 Mat is
only treated as scalar-like when its total element count is compatible
with the target channel count.
2026-10-21 14:41:44 +03:00
sanjayk9
336f5fafa1 Merge pull request #30396 from sanjayk9:dnn-deconv-gemm
dnn: faster ConvTranspose2 on CPU - #30396

Merge pull request #30395 from uwezkhan:onnx-qconv-scale-bias-bound

- With MLAS, every fp32 ConvTranspose2 runs as a packed GEMM per group, followed by a col2im that adds each kernel tap into the output. Threads own bands of output rows, so col2im needs no locking. When taps overlap, output channels are processed in chunks so the column buffer stays in cache. When kernel == stride, each output pixel gets one tap and value + bias is written directly.
- conv2_deconv is now CPU-dispatched (AVX, AVX2, NEON) and uses four accumulators, so the FMAs no longer wait on each other. It is still used when MLAS is not available or the input is not fp32.
- Attention accepts [..., S, C] and treats the leading dims as batch; the SAM3 decoder feeds it a 4D input and failed before.

opencv_extra: https://github.com/opencv/opencv_extra/pull/1442 (test models for the single-tap path, channel chunks, and groups that start inside a channel block)

Measured on an i9-14900KS, times in ms.

**Whole decoder**

| Model | Threads | 5.x | This PR | ORT 1.30 |
|---|---:|---:|---:|---:|
| SAM2 decoder | 1 | 68.5 | **36.8** | 36.5 |
| SAM2 decoder | 8 | 14.0 | **9.7** | 8.2 |
| SAM2 decoder | 32 | 12.8 | **10.5** | 9.8 |
| SAM3 decoder | 1 | 87.9* | **51.1** | 47.1 |
| SAM3 decoder | 8 | 19.0* | **14.1** | 12.6 |
| SAM3 decoder | 32 | 16.4* | **14.4** | 13.0 |

\* SAM3 does not run on 5.x; this column includes the Attention change from this PR.

Best of several interleaved rounds, measured on the first commit. The col2im commit leaves the SAM ConvTranspose layers within a few percent.

**ConvTranspose layer**

| Layer | Threads | 5.x | This PR | ORT 1.30 |
|---|---:|---:|---:|---:|
| SAM2 256→64 ch, 2×2 s2, 64×64 | 1 | 24.0 | **3.35** | 3.54 |
| | 8 | 3.30 | **0.59** | 0.92 |
| | 32 | 1.53 | **0.40** | 0.95 |
| SAM2 64→32 ch, 2×2 s2, 128×128 | 1 | 13.2 | **2.10** | 2.52 |
| | 8 | 1.76 | **0.31** | 1.15 |
| | 32 | 0.85 | **0.24** | 1.88 |
| SAM3 256→64 ch, 2×2 s2, 72×72 | 1 | 27.4 | **4.25** | 4.50 |
| | 8 | 3.85 | **0.59** | 1.16 |
| | 32 | 1.88 | **0.45** | 1.22 |
| SAM3 64→32 ch, 2×2 s2, 144×144 | 1 | 15.5 | **2.72** | 3.41 |
| | 8 | 2.08 | **0.41** | 1.44 |
| | 32 | 1.00 | **0.32** | 1.62 |
| U-Net 256→128 ch, 4×4 s2 p1, 32×32 | 1 | 46.6 | **7.63** | 6.70 |
| | 8 | 6.49 | **1.19** | 1.45 |
| | 32 | 4.50 | **0.97** | 1.68 |
| GAN 128→64 ch, 4×4 s2 p1, 64×64 | 1 | 50.1 | **8.57** | 7.51 |
| | 8 | 7.01 | **1.37** | 2.22 |
| | 32 | 4.28 | **1.16** | 2.53 |
| 128→64 ch, 3×3 s2 p1 op1, 64×64 | 1 | 28.3 | **4.70** | 4.24 |
| | 8 | 3.95 | **0.76** | 1.31 |
| | 32 | 1.79 | **0.66** | 1.75 |
| 64→64 ch, 3×3 s1 p1, 64×64 | 1 | 13.4 | **2.52** | 2.35 |
| | 8 | 1.91 | **0.45** | 0.97 |
| | 32 | 0.80 | **0.35** | 0.98 |
| 128→128 ch, 4 groups, 4×4 s2 p1, 32×32 | 1 | 6.73 | **1.65** | 1.30 |
| | 8 | 0.97 | **0.26** | 0.73 |
| | 32 | 0.44 | **0.21** | 1.00 |
| 64→64 ch, depthwise, 4×4 s2 p1, 64×64 | 1 | 30.1 | **7.54** | 1.54 |
| | 8 | 4.21 | **2.51** | 1.89 |
| | 32 | 1.92 | **1.96** | 2.77 |

### 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
2026-10-21 14:23:31 +03:00
uwezkhan
97a5d7e9ae Merge pull request #30395 from uwezkhan:onnx-qconv-scale-bias-bound
dnn: bound per-channel w_scale to bias length in onnx parseQConv 🤖🤖🤖 - #30395

OpenCV Extra: https://github.com/opencv/opencv_extra/pull/1445

`QLinearConv` import folds a constant int32 bias to float in `parseQConv` (`modules/dnn/src/onnx/onnx_importer2.cpp`): each bias element is multiplied by its per-channel weight scale and written into `bias_float`, which is sized from the bias tensor. The fold loop runs over the length of `w_scale`, but `w_scale` and the bias are independent inputs of the model, so a 1-D `w_scale` longer than the bias writes past `bias_float`. It is reached from `readNetFromONNX` on any `.onnx` carrying such a `QLinearConv`, and the scalar `x_scale` read is likewise unguarded against an empty tensor.

ASan on the default engine loading a model whose bias has one element and whose per-channel `w_scale` has 64:

```
==ERROR: AddressSanitizer: heap-buffer-overflow ... READ of size 4
    #0 ONNXImporter2::parseQConv(...)
    #1 ONNXImporter2::parseNode(...)
    #2 ONNXImporter2::parseGraph(...)
    #5 readNetFromONNX2(...)
    #6 readNetFromONNX(...)
0x... is located 0 bytes after 4-byte region allocated by Mat::convertTo in parseQConv
```

Require the per-channel `w_scale` to hold one entry per bias element before the loop, the per-axis quantization invariant that pairs one scale and one bias with each output channel, and check the scalar `x_scale` is non-empty before the read. A well-formed model is unaffected; a mismatched one now throws from the importer and the net loads empty instead of overrunning the buffer.

### 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
- [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.
- [ ] The feature is well documented and sample code can be built with the project CMake
2026-10-21 11:59:24 +03:00
Shiven Solanki
4943b4d65a core: simplify findNonZero accuracy test 2026-10-21 16:36:42 +08:00
viwe-monai
a233ea41f1 Merge pull request #30428 from viwe-monai:fix-js-mcc-whitelist-names
js: bind the mcc classes under their real 5.0 names (#30409) - #30428

Fixes #30409.

The JS whitelist still names the pre-5.0 mcc classes (`mcc_CheckerDetector`, `mcc_DetectorParameters`, `mcc_Checker`), but the classes now live in `modules/objdetect` as `mcc::CCheckerDetector`, `mcc::DetectorParametersMCC` and `mcc::CChecker` (`mcc_checker_detector.hpp`). The generator skips unmatched entries silently, so a default opencv.js build exports only the `mcc_ColorChart` enum.

Changes, following the working entry set from the issue:

- `platforms/js/opencv_js.config.py` and `modules/objdetect/misc/js/gen_dict.json` (both whitelist sources, kept identical): rename the three entries to the real class names and add `processWithROI` (the `CV_WRAP_AS` alias) and `CChecker::create`.
- Per the issue's findings, `getDetectionParams()` is left out (its `const DetectorParametersMCC&` return breaks the generated `select_overload` signature) and `getListColorChecker()`/`draw()` are left out (`std::vector<Ptr<CChecker>>` has no Embind registration, so they fail when called).
- `modules/js/src/core_bindings.cpp`: `using namespace cv::mcc;` in the objdetect block (next to `using namespace cv::aruco;`) and `typedef dnn::Net dnn_Net;` in the dnn block (for the `create(const dnn::Net&)` overload), mirroring the existing `aruco_DetectorParameters` / `QRCodeDetectorAruco_Params` typedef pattern.

Verification: every whitelisted method name was checked against `mcc_checker_detector.hpp` (all found; `processWithROI` is the `CV_WRAP_AS` alias of `process` at line 207). `gen_dict.json` parses and `opencv_js.config.py` compiles. A full `build_js.py --build_wasm` run needs Emscripten and is left to CI; the entry set itself is the one validated end-to-end against a downstream build in the issue (synthetic MCC24 chart detected, `getChartsRGB()` exact).
2026-10-21 10:24:03 +03:00
Shiven Solanki
155f4e18fd core: SIMD fast path for findNonZero on 8-bit inputs 2026-10-21 15:22:28 +08:00
pranayr710
afa5b1b5f3 core: saturate cv::absdiff on CV_64S instead of letting it return a negative
getAbsdiffFunc_() documents that a signed depth has two outputs: R == T, the saturating |a-b| kept
in the signed range, which is the depth cv::absdiff returns; and R == the unsigned type of the same
width. CV_8S, CV_16S and CV_32S each have both. CV_64S only had the unsigned one, so the signed
form fell through to a path that wraps:

    absdiff(INT64_MIN, 0)         -> -9223372036854775808
    absdiff(INT64_MIN, INT64_MAX) -> -1

at every length, scalar included, in a CV_64S destination. The narrower depths all saturate at
their maximum: absdiff(INT_MIN, INT_MAX) on CV_32S is INT_MAX.

The missing row now uses EwAbsdiffS, whose scalar step gains a 64-bit overload. The generic one
widens into the work type, which the narrower depths have (short, int, int64_t) and 64-bit does not,
and |INT64_MIN - b| does not fit in int64_t anyway. The difference is therefore taken in uint64,
which is exact for every pair, and clamped to INT64_MAX. The narrower depths reach that overload
only through their int64 work type, where |a - b| is at most 2^32 and the clamp is a no-op.

Core_AbsdiffSigned checks both properties - never negative, and saturating at the depth's maximum -
across CV_8S, CV_16S, CV_32S and CV_64S.
2026-10-21 09:49:45 +03:00
Alexander Smorkalov
58a176f509 Merge pull request #30426 from Kumataro:trial/support16bitAVIF_5.x
imgcodecs(avif): support 16-bit reading/writing with libavif v1.4.0+(5.x)
2026-10-21 09:21:40 +03:00