Added support for Granite Docling 258M and PaddleOCR-VL - #29618
Adds `com.microsoft::GroupQueryAttention` to the engine-new ONNX importer, required by GraniteDocling-258M's ,end-to-end samples for GraniteDocling-258M and PaddleOCR-VL-1.5. Verified on Linux x86_64 / GCC / CPU
**companion opencv_extra PR** [Vlm ocr support engine new opencv/opencv_extra#1412](https://github.com/opencv/opencv_extra/pull/1412) for test data
upstream/5.x already lowers `GroupQueryAttention` to `AttentionOnnxAi`, but that path rejects `do_rotary=1`:
```cpp
CV_CheckEQ(params.get<int>("do_rotary", 0), 0, "GroupQueryAttention: do_rotary=1 is not supported");
```
GraniteDocling-258M's export sets it. Confirmed two ways: building a Llama checkpoint from its published `text_config` (9 heads / 3 KV heads, `rope_theta=100000`) and running onnxruntime-genai's `model_builder`; and reading the community export at `onnx-community/granite-docling-258M-ONNX`, which carries 30 `GroupQueryAttention` nodes with `do_rotary=1`, `num_heads=9`, `kv_num_heads=3`, `head_dim=64`.
## Changes
**Importer** (`onnx_importer2.cpp`, +49)
Routing as above, plus the input validation the op needs: packed QKV rejected, past_key / past_value required as a pair, `do_rotary=1` requires cos/sin, unsupported trailing inputs rejected, and `seqlens_k` shorter than the buffer recognised as a shared-buffer export rather than silently mis-attended.
**Layer** (`group_query_attention_layer.cpp`, +380)
Attention is built on `fastGemmBatch` and `fused_softmax_softcap_mask`, the same kernels `attention_onnxai_layer.cpp` uses. Grouping falls out of the batched-GEMM offset table (query head → `h / groupSize`), so no broadcast copy is needed, and the second GEMM writes straight into the `[B, S, num_heads*D]` output. Supports rotary (full and partial), sliding window, softcap, growing and preallocated caches, and optional `present_*` outputs.
**Core** (`persistence_json.cpp`, +92)
`\uXXXX` escapes are UTF-16 code units, so anything above the BMP arrives as a surrogate pair. These were encoded as two separate 3-byte sequences CESU-8, which is not valid UTF-8 - for keys and values alike. Now recombined into one 4-byte sequence, with unpaired surrogates rejected.
**Tests / perf / samples**
`test_layer_group_query_attention.cpp` (+93), `test_tokenizer.cpp` (+28), `test_tokenizer.py` (+42), `perf_layer.cpp` (+125: `Layer_GroupQueryAttention` MHA_ShortCache and Grouped_WithCache, plus `Layer_Sign`), and two samples (`granite_docling_inference.py`, `paddleocr_vl_inference.py`).
### 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
With hardware decoding, retrieveFrame() downloads the GPU frame into a new
AVFrame with av_hwframe_transfer_data(). That call copies the pixel data
only: colorspace, color_range, color_primaries, color_trc and
chroma_location are left unspecified in the system memory copy.
With swscale >= 8.12.100 the color conversion goes through
sws_scale_frame(), which configures itself from the properties of the source
frame. Given unspecified properties it falls back to BT.601 limited range, so
hardware-decoded frames are converted with the wrong matrix whatever the
stream signals, and full range streams additionally lose contrast. Software
decoding is not affected, the decoder output carries the properties.
fftools/ffmpeg_dec.c handles this by calling av_frame_copy_props() right
after the transfer; do the same. A failure is only logged: it can only be an
allocation failure on side data, and the picture itself is still valid.
With swscale < 8.12.100 the conversion context is initialized without the
frame properties, so this change has no effect on that path.
Measured on Windows x64 with the OpenCV 5.0.0 FFmpeg wrapper built by the
opencv_3rdparty MinGW recipe against FFmpeg n8.1.3 (libswscale 9.5.103),
D3D11VA decoding, on two synthetic BT.709 H.264 samples:
ffmpeg -f lavfi -i testsrc2=size=1280x720:rate=30 -t 2 -c:v libx264 \
-pix_fmt yuv420p -color_range tv -colorspace bt709 \
-color_primaries bt709 -color_trc bt709 bt709_tv.mp4
ffmpeg -f lavfi -i testsrc2=size=1280x720:rate=30 -t 2 -c:v libx264 \
-pix_fmt yuvj420p -color_range pc -colorspace bt709 \
-color_primaries bt709 -color_trc bt709 bt709_pc.mp4
Frame 0 is compared with a reference built from the same static FFmpeg
libraries: software decode, lossless repack to NV12 (the D3D11VA download
format), av_frame_copy_props(), then sws_scale_frame() to BGR24 exactly as
retrieveFrame() does.
sample before (mean / max abs diff) after
bt709_tv.mp4 7.424 / 94 bit-exact
bt709_pc.mp4 3.286 / 101 bit-exact
Before the patch the output is bit-exact with the same reference built
without the frame properties, which confirms the cause. Software decoding
output is unchanged (bit-exact before and after). Two real H.264 recordings
(BT.709, full and limited range) behave the same way.
Hardware and software decoding still do not produce identical pictures after
this patch: swscale converts NV12 and yuv420p differently around sharp chroma
edges. That difference exists with the same properties outside OpenCV too
and is not addressed here.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Extend TFLite importer to support more models on the new engine - #29569
Requires: https://github.com/opencv/opencv_extra/pull/1399
### 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
videoio: encoder controls for VideoWriter (bitrate, CRF, preset, GOP, pixel format) - #30064
Resolves [Issue#8961](https://github.com/opencv/opencv/issues/8961)
Until now, the only way to control encoder quality from VideoWriter was to write a GStreamer pipeline string by hand. This PR adds open-time properties that work with both the FFmpeg and GStreamer backends:
- VIDEOWRITER_PROP_BITRATE sets the target bitrate in bits per second.
- VIDEOWRITER_PROP_CRF sets the constant rate factor. It overrides bitrate if both are given.
- VIDEOWRITER_PROP_PRESET takes a value from the new VideoWriterPresets enum, ULTRAFAST through PLACEBO, using the x264/x265 preset names.
- VIDEOWRITER_PROP_GOP_SIZE sets the maximum interval between key frames.
- VIDEOWRITER_PROP_COLOR_SPACE used to be GStreamer-only and now works with FFmpeg too. It takes a fourcc, the same encoding as CAP_PROP_CODEC_PIXEL_FORMAT.
Tests are in test_ffmpeg.cpp and test_gstreamer.cpp. They check that CRF and bitrate change the output size, that GOP and preset values come back from get(), that the pixel format matches the capture property, that an unsupported property makes open() fail, and that nothing changes when no properties are set.
### 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
video: add input validation for OPTFLOW_USE_INITIAL_FLOW in calcOpticalFlowFarneback (port to 5.x) - #30100
This is a port of #30086 to the 5.x branch.
Added `CV_Assert` validation for `OPTFLOW_USE_INITIAL_FLOW` in `calcOpticalFlowFarneback` to ensure the initial flow matrix is not empty, matches the input size, and has the correct type (`CV_32FC2`). Also added corresponding unit tests in `test_OF_accuracy.cpp`.
Unified DNN graph fusion behind fuseChains - #30088
Requires: https://github.com/opencv/opencv_extra/pull/1417
### What This PR Does
Follow-up to #29656, which added the backend-agnostic chain mechanism. That PR introduced it and made pointwise fusion its first consumer; this one moves the rest of the fusion onto it.
- `Net::Impl::fuseBasic()` is gone. Its conv+BatchNorm, conv+activation and conv+residual branches now go through the chain mechanism.
- `fuseBN` and the six other passes now run from inside `fuseChains()`, in their existing order.
- `graph_fusion_basic.cpp` keeps `fuseBN()` and `fuseInstanceNormAffine()`.
- New `FusionOps::foldInputScale` folds a scale sitting before a conv directly into its weights, across the dense, depthwise, grouped and MLAS-prepacked layouts.
### Results
Measured on Intel Core i9-11900K
| Model | 5.x | this PR | speedup |
|-----------------------------|-----------|-----------|---------|
| inception_v2 | 15.04 ms | 11.80 ms | 1.27 |
| efficientnet-lite4 | 14.83 ms | 12.28 ms | 1.21 |
| pose_estimation_mediapipe | 5.66 ms | 5.25 ms | 1.08 |
| siglip_base_patch16_224 | 143.04 ms | 135.27 ms | 1.06 |
| densenet121 | 25.99 ms | 24.76 ms | 1.05 |
### 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
core: saturating float/double->intXY conversions in cvRound/cvFloor/cvCeil and the corresponding univ. intrinsics. - #30007
Merge pull request #30007 from vpisarev:fix_flt2int
Fixes#28557 (supersedes the tail-only fix from #29895).
### The problem
On x86 `cvtss2si`/`cvtsd2si`/`cvtps2dq` return the "integer indefinite" value `0x80000000` (`INT_MIN`) for any out-of-range input, so
```cpp
cvRound(3e9); // INT_MIN
saturate_cast<ushort>(60000.f*60000.f); // 0 instead of 65535 (#28557: the scalar tail of cv::multiply)
v_round(v_float32(1e10f)); // INT_MIN lanes
```
The problem is not x86-only. `cvRound()` on aarch64, riscv64 and loongarch64 went through `(int)lrint()`, which the compilers implement as a 64-bit conversion followed by truncation to 32 bits, i.e. large values *wrap* instead of saturating (`fcvtzs x0` + `mov w0`, `fcvt.l.d` + `sext.w`). NEON `v_round/v_floor/v_ceil/v_trunc(v_float64x2)` narrowed with a wrapping `vmovn`, and `saturate_cast<unsigned/int64/uint64>(float/double)` were plain UB above the target range.
### The fix
**`fast_math.hpp`**
- `cvRound()`, `cvFloor()`, `cvCeil()` saturate on every platform. New `cvTrunc()` (round towards zero, saturating; the scalar counterpart of `v_trunc`) and `cvRound64()` (round-half-to-even to `int64`, saturating).
- x86 (SSE2): the input is clamped from above (`min`) before `cvt*`; the "indefinite" value is already the correct result below `INT_MIN`. `cvFloor` also clamps from below because of the "-1" correction.
- aarch64 (`__GNUC__`/clang): one-instruction inline asm `fcvtns/fcvtms/fcvtps/fcvtzs` (GCC's `arm_neon.h` has no scalar f64→s32 ACLE functions, and inline asm needs no header).
- riscv64: `fcvt.w.{s,d}` / `fcvt.l.{s,d}` with an explicit rounding mode (`rne`, `rdn`, `rup`, `rtz`).
- loongarch64: `ftint*.w.{s,d}` + `movfr2gr.s` (the old `.l.d` + `movfr2gr.d` wrapped); `cvRound` got a branch too.
- MSVC ARM64: the 64-bit results are clamped before narrowing.
- Portable `#else` branch: hand-written clamp before the conversion, no new headers.
- Exact semantics: `double` saturates to `INT_MIN`/`INT_MAX` exactly. `INT_MAX` is not representable as `float`, so `float` inputs `>= 2^31` give **2147483520** (the largest float below 2^31, the clamp value) where the instruction does not saturate by itself (x86, portable) and `INT_MAX` where it does (ARM, RISC-V, LoongArch). Both are accepted by the tests and documented.
- **NaN handling is out of scope in this PR**.
**`saturate.hpp`**
- `float/double → unsigned/int64/uint64` now saturate and use round-half-to-even via `cvRound64()` (no libm `round()` call; OpenCV builds without `-ffast-math`, where `rint()`/`round()` are real calls).
- `int/int64 → schar/short/int` range checks are done in unsigned arithmetic. The old `(unsigned)(v - SHRT_MIN)` overflowed (UB) for `v > INT_MAX - 32768`; such values were unreachable before but are returned by the saturating `cvRound()` now, and GCC 15 actually exploits the UB (derives `v <= INT_MAX-32768` and folds neighbouring comparisons).
**Universal intrinsics**
- SSE, AVX2, AVX-512: clamp before `cvt` in `v_round/v_floor/v_ceil/v_trunc` (f32 and f64, `v_round(a, b)` included). AVX2 keeps `_mm256_floor_ps/_ceil_ps`.
- NEON f64: saturating narrow (`vqmovn_s64`); `v_floor/v_ceil` use `fcvtms/fcvtps` directly; `v_trunc` used `vcvtaq` (round-to-nearest-away) instead of truncation.
- WASM f32: clamp before the `-1/+1` corrections (they wrapped `INT_MIN`); `v_round` was `trunc_sat(a + 0.5)` (wrong for negatives and ties), now `f32x4.nearest`; f64 `v_trunc` via `cvTrunc`.
- MSA f64: clamp before `pckev.w`, which takes the low 32 bits of the saturated int64.
- RVV f16 `v_floor`: rounding mode `2` (RDN) instead of `1` (RTZ).
- VSX, LSX/LASX, RVV f32/f64, RVV 0.7.1: untouched, the conversion instructions saturate by ISA definition.
- `intrin_cpp.hpp`: `v_trunc` via `cvTrunc`; docs mention the saturation.
`arithm.simd.hpp` is not modified: `Core_Arithm.mul_overflow_28557` passes because the scalar tail's `saturate_cast<ushort>(float)` saturates now.
### Tests
- `Core_Arithm.mul_overflow_28557` re-enabled.
- `Core_Arithm.mul_overflow_tail_and_inplace`: 8U/8S/16U/16S, row lengths 1..70 (vector body + scalar tail), out-of-place and in-place `multiply`, `mul`, `pow(x, 2)`.
- `Core_ConvertTo.float_overflow_saturation`: 32F/64F → 8U/8S/16U/16S/32S/32U/64S/64U with `±1e10`, `±1e30`, `±inf`, `2147483647.5`, `x.5` etc.; vector body vs. scalar reference, extreme inputs must hit the type limits.
- `Core_FastMath.SaturatingRoundingOps`: boundary table (`2147483647.5`, `-2147483648.5`, `2147483520f`, `-2147483904f`, `±DBL_MAX`, `±inf`, ...) plus a 200k-value log-uniform random sweep against `nearbyint/floor/ceil/trunc` clamped to `int`.
- `Core_FastMath.Round64`: boundaries around `±2^63`, `.5` cases, random sweep.
- `Core_SaturateCast.FloatToIntSaturation`, `RoundHalfToEven`, `IntToNarrowerIntBoundaries` (regression for the signed-overflow UB).
- `test_intrin_utils.hpp` (`test_float_math`, `test_round_pair_f64`): overflow/boundary lanes for f32, f64 and f16, compared against the scalar functions and checked against explicit `INT_MIN` / `[2147483520, INT_MAX]` / `INT_MAX` limits. Runs on every backend and dispatch level.
### Verification
- x86-64, GCC 15.2, `CPU_BASELINE=SSE4_2 CPU_DISPATCH=AVX2,AVX512_SKX`: full `opencv_test_core` passes (16864 tests), i.e. SSE4.2 baseline, AVX2 dispatch and the CPP emulator paths. AVX-512 is compile-checked only (no AVX-512 hardware here).
- The standalone scalar checks also pass with the portable `#else` branch forced (`-U__SSE2__`) and under `-fsanitize=undefined`.
- aarch64 (`aarch64-linux-gnu-gcc-14`) and riscv64 (`riscv64-linux-gnu-gcc-14 -march=rv64gcv_zvfh`): compile-checked, generated code inspected (`fcvtns w0, d0`, `fcvt.w.d a0, fa0, rne`, `sqxtn`, `vfcvt.x.f.v`, ...). Not run (no hardware/qemu).
- **Not verified at all** (please watch CI): LoongArch (`ftint*.w.d`/`ftintrne.*` asm), WASM (`wasm_f32x4_nearest`), MSA, MSVC ARM64 (`vcvtd_s64_f64`, `vcvts_s32_f32`, `vcvtnd_s64_f64`).
### Behaviour changes worth noting
- `saturate_cast<unsigned/int64/uint64>(x.5)` now rounds half to even (was half away from zero), consistent with all the other integer targets.
- `cvRound(float)` for inputs `>= 2^31` returns **2147483520** on x86 (was `INT_MIN`); `INT_MAX` on ARM/RISC-V. It would be noticeably slower to implement true saturation to `INT_MAX`. Note that around `INT_MAX` float's cannot represent the integer's exactly anyway.
- `saturate_cast<int>(1e10)` is `INT_MAX` (documentation used to say "no clipping is done for 32-bit integers").
### 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 is proposed to the proper branch (`5.x`).
- [x] There is a reference to the original bug report and related work: #28557, #29895.
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable: accuracy tests added, no test data needed.
- [x] The feature is well documented and sample code can be built with the project CMake: doxygen comments of `cvRound`/`cvFloor`/`cvCeil`/`cvTrunc`/`cvRound64`, `saturate_cast` and the intrinsics conversion group updated.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01KVnDjvrFtxcyw7RFzSPews
calib: improve fisheye extrinsic refinement - #30070
This is #29940 cherry-pick to 5.x with adaptions to the new `LevMarq` interface.
Additionally included is a fix to a latent bug also present in 4.x but only exposed by the `3cams-hetero` dataset introduced in 5.x. The reason for this bug is #17454 which introduced sentinel values to `fisheye::undistortPoints` that can corrupt initial estimates and thus need to be filtered.
The bug fix should ideally be applied to the 4.x branch as well.
### 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
libopencv_imgproc grew noticeably with the HarfBuzz-based text engine. Measured on
macOS/arm64 (clang, Release, stripped) the text-related part of the library was
~830 KB: HarfBuzz 486 KB, the two Rubik fonts 296 KB, the engine ~25 KB, plus ~2 MB
of WenQuanYi when WITH_UNIFONT=ON (the previous default). With GCC and an unstripped
.so on Linux the HarfBuzz part alone is 700+ KB.
This patch brings it down to ~550 KB by default (HarfBuzz 377 KB + Rubik 146 KB +
engine 30 KB) without dropping functionality:
* 3rdparty/harfbuzz: build with -Os -fno-exceptions -fno-rtti -fno-threadsafe-statics
(like HarfBuzz's own build; shaping speed is irrelevant thanks to the glyph cache)
and HB_NO_VAR_COMPOSITES (VARC table, a 2024 format with no real fonts yet).
Variable-font support (wght axis etc.) is untouched. -22% of HarfBuzz code.
* Only the "sans" font (Rubik) is compiled into imgproc by default. Rubik Italic and
WenQuanYi Micro Hei became optional: WITH_ITALICFONT (new) and WITH_UNIFONT are
both OFF now. The build summary lists the built-in fonts.
* New API cv::FontFace::setBuiltinFont(name, path) fills or replaces any of the
three built-in slots ("sans", "italic", "uni") with an external font file. The
registered font takes part in the automatic fallback chain exactly like a
compiled-in one, so users can get CJK text or a true italic without rebuilding
OpenCV. The registry is process-wide; each thread's engine reloads its slots
lazily (generation counter), and the glyph cache is dropped on reload since
hb_font pointers are part of its key.
* "italic" resolves to "sans" when no italic font is built in or registered, so
FONT_ITALIC / FONT_HERSHEY_SCRIPT_* in the legacy putText keep working (upright).
* Fix: a character not covered by any font used to be drawn as '?' taken from the
last built-in slot, which can be empty now; the '?' is looked up like any other
character (user font first).
* Tests: opencv_test_imgproc registers Rubik-Italic.ttf.gz and
WenQuanYiMicroHei.ttf.gz from opencv_extra (testdata/highgui/drawing) as the
"italic"/"uni" slots, so Drawing.ttf_text reproduces the reference picture 1:1
with the default build and the legacy hershey-font tests are unchanged.
Drawing.builtin_font_slots covers the new API. Tests skip if the fonts are absent.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Add cv::linearAssignment() rectangular assignment solver - #29963
Adds `cv::linearAssignment()` to `modules/core`, next to `solveLP`: a Jonker-Volgenant solver that pairs the rows of a cost matrix with its columns at the lowest total cost. It pairs existing tracks with new detections in a tracking pipeline.
`costThreshold` is applied during the solve, so a pair that is too expensive is forbidden and a pair is only made when it beats the price of leaving it unmade. Implemented from Crouse 2016, cited in the doxygen.
Accuracy and performance tests are included and need no new test data.
### 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
SequenceTypeNode and ClassTypeNode always format as _typing.Sequence[...]
and _typing.Type[...], but ContainerTypeNode only reports the typing
import as required when compatible_to_runtime_usage is set. Stubs for
modules that use these nodes without any other _typing usage (e.g.
cv2/videoio_registry) reference _typing without importing it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
core: stop cv::sum() wrapping at 32 bits for CV_32U and CV_32S - #30003Fixes#30002
### Problem
`cv::sum()` returns doubles, but for single-channel `CV_32S` and `CV_32U` it accumulates part of
the total in 32 bits, so a sum beyond the 32-bit range wraps. For `CV_32S` that is signed integer
overflow.
```
Mat m(1, 8, CV_32S, Scalar(INT_MAX));
cv::sum(m)[0]; // -8 expected 17179869176
Mat u(1, 8, CV_32U, Scalar(UINT_MAX));
cv::sum(u)[0]; // 8589934584 expected 34359738360
```
`sum_()`'s unrolled single-channel step adds four elements **to each other** in `WT` before the
result reaches the `ST` accumulator, and `WT` defaults to the source type:
```cpp
s0 += (WT)src[0] + (WT)src[cn] + (WT)src[cn*2] + (WT)src[cn*3];
```
For `CV_8U`/`CV_16U`/`CV_16S` that is harmless — integer promotion widens the operands to `int`
first. For the 32-bit depths the additions happen in 32 bits.
The vectorized specialization only runs from `len >= 6 * vector_width`, so shorter arrays take the
scalar route entirely and longer ones still leave a wrapping tail; and `DEFINE_SUM_SIMD_32` is
instantiated only for `int` and `float`, so `CV_32U` has no vectorized path at all. Multi-channel
inputs are unaffected: those branches add each element straight into its own `double` accumulator.
### Fix
Pass an explicit 64-bit integer `WT` for the two entry points. Widening to 64-bit integers rather
than to `double` keeps the step in integer arithmetic, and four 32-bit values cannot come near the
64-bit range. The 16-bit float entry points already pass an explicit `WT` for the same reason.
### Performance
1920x1080, best of 5 runs of 50 iterations:
| depth | before (wrong) | this patch (int64 WT) | double WT, for comparison |
| --- | --- | --- | --- |
| `CV_32U` | 0.430 ms | 0.407 ms | 0.729 ms |
| `CV_32S` | 0.235 ms | 0.258 ms | 0.268 ms |
| `CV_16U` (not touched) | 0.111 ms | 0.095 ms | |
| `CV_32F` (not touched) | 0.244 ms | 0.254 ms | |
Accumulating in `double` would also fix the wrap but costs about 70% on `CV_32U`, which has no
vectorized path and therefore runs this step for every element. The integer widening has no
measurable cost; run-to-run noise on this machine is around 10%.
### Tests
`Core_SumWide.no_32bit_wraparound` is a `TEST_P` over depth, channel count and length (4, 8, 23,
24, 64, 127 — around the vectorized path's 6-vector-width threshold), asserting the exact total.
It fails on unpatched 5.x:
```text
[ FAILED ] Core_SumWide.no_32bit_wraparound/0, where GetParam() = (12, 1, 4)
Which is: 17179869180
Which is: 4294967292
```
and passes with the patch. Full `opencv_test_core`: 16897 of 16904. The 7 failures
(`Core_InputOutput.filestorage_base64_*`, `Core_globbing.accuracy`) reproduce identically on
unmodified 5.x in this environment and are unrelated.
### 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
dnn: fold Shape of static-shape inputs in constFold() - #30065
When a graph input has a fully known shape, `constFold()` now replaces `Shape` ops on it with constants. The usual const-folding cascade then also removes the Gather/Concat/Cast/Slice ops that follow.
**What it adds**
- `graph_const_fold.cpp`: tracks known shapes and types through the graph during folding and folds `Shape` layers whose input shape is known.
- `net_impl2.cpp`: once a `Shape` has been folded, `setGraphInput()` rejects an input of a different shape instead of running with stale constants. It also fixes `tryInferGraphShapes()` to report untyped const or empty inputs as `Mat().type()`. The extra folding exposed a Resize type-check failure without this fix.
- `test_fusion.cpp`: two tests, one checking that no `Shape` layer remains after folding, one checking that a different input shape is rejected.
**Effect on graphs** (outputs identical to 5.x)
CRNN 84 → 34 layers, ViT/DeiT 361 → 274, BEiT 373 → 286, MobileViT_XS 352 → 289.
**Performance** (OCV/CPU, 32 threads; median of 5 interleaved runs per side)
| Model | 5.x, ms | PR, ms | Speedup |
|---|---|---|---|
| MobileViT_XS | 6.50 | 6.23 | 1.04x |
| BEiT_Base_Patch16_224 | 30.03 | 29.23 | 1.03x |
| VIT_Base_Patch16_224 | 27.17 | 26.53 | 1.02x |
| DeiT_Tiny_Patch16_224 | 4.90 | 4.81 | 1.02x |
| CRNN | 2.52 | 2.51 | 1.01x |
| FacePaint | 328.1 | 329.5 | 1.00x |
**Dependency**
This depends on the upcoming CUDA integration in DNN and should be merged after it.
### 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
core: enable CV_64F arithmetic SIMD kernels for scalable SIMD - #30069
### Summary
The CV_64F element-wise arithmetic kernels in `modules/core/src/arithm.simd.hpp` are guarded by `CV_SIMD_64F`, which is 0 on scalable-vector (RVV) builds, while the kernels themselves are already written with width-independent universal intrinsics (`v_float64`, `vx_load`, `VTraits<>::vlanes()`). On RVV every CV_64F arithmetic operation therefore falls back to the scalar kernels even though `CV_SIMD_SCALABLE_64F` is 1 and `v_float64` is fully supported.
The same file already uses the dual guard `CV_SIMD_64F || CV_SIMD_SCALABLE_64F` in four other places (see the comment at L166: "scalable (RVV) has v_float64 without CV_SIMD_64F"), so the 12 remaining single-guard sites look like an oversight. This PR widens them.
### What becomes vectorized on RVV (VLEN=256 => 4 double lanes)
- `cv::add` / `cv::subtract` (CV_64F)
- `cv::multiply` (CV_64F, plus the 32U/32S f64-work-type kernels)
- `cv::divide` (DIVW group: 32U/32S/64U/64S/64F)
- `cv::min` / `cv::max` (CV_64F)
- `cv::absdiff` (CV_64F)
- `cv::compare` (CV_64F)
- `cv::addWeighted` (AWD group: 32U/32S/64U/64S/64F)
All affected kernels are element-wise with no cross-lane reductions, so results are identical to the scalar kernels (per-element IEEE operations). The only theoretical difference is that the addWeighted vector body uses fused `v_fma` while the scalar tail does separate mul+add (at most 1 ulp); the same code already passes x86 AVX2/AVX512 CI where FMA is used as well.
On fixed-width backends (x86, AArch64, LoongArch, MIPS MSA, Power VSX) `CV_SIMD_64F` is already 1, so the guard change compiles to exactly the same code as before — no impact on other architectures. ARMv7/AArch32 and WASM SIMD128 have no f64 vector type at all (`CV_SIMD128_64F=0` by design) and keep the scalar path unchanged.
### Scope
Generic `rv64gc + CPU_DISPATCH=RVV` builds do not benefit yet (`arithm` is not a dispatched file); the win applies to builds where the core library itself is compiled with RVV enabled (`CPU_BASELINE=RVV`, the common embedded configuration on SpacemiT K1/K3 boards).
### Build configuration
Cross-compiled for SpacemiT K1 (8x 1.6 GHz, RVV 1.0, VLEN=256), GCC 14.2.1, `-O3`, both sides built with identical flags:
```bash
cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=riscv64-spacemit-k1.toolchain.cmake \
-DCMAKE_BUILD_TYPE=Release -DCPU_BASELINE=RVV -DCPU_DISPATCH= \
-DBUILD_LIST=core,ts,calib,geometry -DBUILD_TESTS=ON -DBUILD_PERF_TESTS=ON \
-DWITH_LAPACK=OFF -DWITH_EIGEN=OFF -DWITH_OPENCL=OFF \
-DWITH_TIFF=OFF -DWITH_OPENJPEG=OFF -DWITH_JASPER=OFF -DWITH_OPENEXR=OFF \
-DWITH_GDAL=OFF -DWITH_GDCM=OFF -DWITH_AVIF=OFF -DWITH_JPEGXL=OFF -DWITH_IMGCODEC_GIF=OFF ..
ninja opencv_core opencv_test_core opencv_perf_core opencv_test_calib opencv_test_geometry
```
### Correctness validation (on board)
```bash
export OPENCV_TEST_DATA_PATH=.../opencv_extra/testdata
export OPENCV_OPENCL_RUNTIME=disabled
./bin/opencv_test_core --test_threads=4
./bin/opencv_test_calib --test_threads=4
./bin/opencv_test_geometry --test_threads=4
```
| suite | baseline | with this PR |
|---|---|---|
| `opencv_test_core` (16757 tests) | 16756 pass, 1 fail: `Samples.findFile` (missing samples data path, environment) | **identical failure set** |
| `opencv_test_calib` (34 tests) | 34/34 pass | 34/34 pass |
| `opencv_test_geometry` (323 tests) | 323/323 pass | 323/323 pass |
Zero new failures; the arithm accuracy suites (`Core_*ElemWiseTest`, `Core_AddWeighted*`, `Core_*Mixed/ArithmMixedTest`, compare) exercise the newly vectorized kernels at all depths and pass unchanged.
### Performance (SpacemiT K1, single-threaded)
This PR adds a CV_64F perf fixture (`F64ArithmTest`: 9 ops x 4 sizes x CV_64FC1 = 36 cases) to `modules/core/perf/perf_arithm.cpp`, since the existing `BinaryOpTest` fixture does not parametrize CV_64F (and has no `compare`/`addWeighted` cases at all). Numbers below are per-case minima over 4 alternating A/B rounds x 50 samples, reported with the standard `modules/ts/misc/summary.py` (`-m min`).
With the default build flags (`-O3`, GCC 14.2.1):
```
Min (ms)
Name of Test base cand cand
min4 min4 min4
vs
base
min4
(x-factor)
absdiff::F64ArithmTest::(127x61, 64FC1) 0.035 0.026 1.33
absdiff::F64ArithmTest::(640x480, 64FC1) 1.580 1.644 0.96
absdiff::F64ArithmTest::(1280x720, 64FC1) 4.533 5.049 0.90
absdiff::F64ArithmTest::(1920x1080, 64FC1) 10.059 10.936 0.92
add::F64ArithmTest::(127x61, 64FC1) 0.027 0.028 0.98
add::F64ArithmTest::(640x480, 64FC1) 1.529 1.561 0.98
add::F64ArithmTest::(1280x720, 64FC1) 4.560 4.450 1.02
add::F64ArithmTest::(1920x1080, 64FC1) 9.544 9.549 1.00
addWeighted::F64ArithmTest::(127x61, 64FC1) 0.033 0.028 1.14
addWeighted::F64ArithmTest::(640x480, 64FC1) 1.582 1.581 1.00
addWeighted::F64ArithmTest::(1280x720, 64FC1) 4.579 4.797 0.95
addWeighted::F64ArithmTest::(1920x1080, 64FC1) 10.255 9.885 1.04
compare::F64ArithmTest::(127x61, 64FC1) 0.099 0.035 2.85
compare::F64ArithmTest::(640x480, 64FC1) 3.834 1.300 2.95
compare::F64ArithmTest::(1280x720, 64FC1) 11.456 3.847 2.98
compare::F64ArithmTest::(1920x1080, 64FC1) 25.670 8.738 2.94
divide::F64ArithmTest::(127x61, 64FC1) 0.064 0.065 0.98
divide::F64ArithmTest::(640x480, 64FC1) 2.493 2.352 1.06
divide::F64ArithmTest::(1280x720, 64FC1) 7.359 7.192 1.02
divide::F64ArithmTest::(1920x1080, 64FC1) 16.306 15.548 1.05
max::F64ArithmTest::(127x61, 64FC1) 0.029 0.026 1.12
max::F64ArithmTest::(640x480, 64FC1) 1.583 1.600 0.99
max::F64ArithmTest::(1280x720, 64FC1) 4.746 4.963 0.96
max::F64ArithmTest::(1920x1080, 64FC1) 9.827 10.143 0.97
min::F64ArithmTest::(127x61, 64FC1) 0.029 0.026 1.10
min::F64ArithmTest::(640x480, 64FC1) 1.625 1.630 1.00
min::F64ArithmTest::(1280x720, 64FC1) 4.821 5.000 0.96
min::F64ArithmTest::(1920x1080, 64FC1) 9.363 11.126 0.84
multiply::F64ArithmTest::(127x61, 64FC1) 0.029 0.027 1.10
multiply::F64ArithmTest::(640x480, 64FC1) 1.680 1.762 0.95
multiply::F64ArithmTest::(1280x720, 64FC1) 4.835 4.929 0.98
multiply::F64ArithmTest::(1920x1080, 64FC1) 10.427 10.564 0.99
subtract::F64ArithmTest::(127x61, 64FC1) 0.027 0.026 1.06
subtract::F64ArithmTest::(640x480, 64FC1) 1.605 1.660 0.97
subtract::F64ArithmTest::(1280x720, 64FC1) 4.758 5.016 0.95
subtract::F64ArithmTest::(1920x1080, 64FC1) 11.156 10.594 1.05
```
x-factor geomean **1.13x**. `compare` is a robust ~2.9x; most other ops land near parity because GCC already auto-vectorizes the simple scalar f64 loops at `-O3` on RVV (exactly the issue #30066 works around with `-fno-tree-vectorize`). Per-case values near parity swing with the known K1 bimodal timing behavior.
With `-fno-tree-vectorize` added to the build flags (the direction proposed in #30066 for RVV), the same A/B shows the kernel-level gains directly:
```
Min (ms)
Name of Test nt nt nt
base cand cand
min4 min4 min4
vs
nt
base
min4
(x-factor)
absdiff::F64ArithmTest::(127x61, 64FC1) 0.087 0.026 3.41
absdiff::F64ArithmTest::(640x480, 64FC1) 3.351 1.423 2.36
absdiff::F64ArithmTest::(1280x720, 64FC1) 10.189 4.595 2.22
absdiff::F64ArithmTest::(1920x1080, 64FC1) 22.476 10.094 2.23
add::F64ArithmTest::(127x61, 64FC1) 0.037 0.027 1.35
add::F64ArithmTest::(640x480, 64FC1) 1.538 1.446 1.06
add::F64ArithmTest::(1280x720, 64FC1) 4.644 4.403 1.05
add::F64ArithmTest::(1920x1080, 64FC1) 10.316 9.629 1.07
addWeighted::F64ArithmTest::(127x61, 64FC1) 0.076 0.027 2.81
addWeighted::F64ArithmTest::(640x480, 64FC1) 2.978 1.363 2.18
addWeighted::F64ArithmTest::(1280x720, 64FC1) 9.141 4.118 2.22
addWeighted::F64ArithmTest::(1920x1080, 64FC1) 19.856 9.075 2.19
compare::F64ArithmTest::(127x61, 64FC1) 0.103 0.031 3.31
compare::F64ArithmTest::(640x480, 64FC1) 3.993 1.225 3.26
compare::F64ArithmTest::(1280x720, 64FC1) 11.801 3.596 3.28
compare::F64ArithmTest::(1920x1080, 64FC1) 26.611 8.125 3.28
divide::F64ArithmTest::(127x61, 64FC1) 0.156 0.065 2.41
divide::F64ArithmTest::(640x480, 64FC1) 6.095 2.330 2.62
divide::F64ArithmTest::(1280x720, 64FC1) 18.191 6.880 2.64
divide::F64ArithmTest::(1920x1080, 64FC1) 40.743 15.331 2.66
max::F64ArithmTest::(127x61, 64FC1) 0.085 0.025 3.36
max::F64ArithmTest::(640x480, 64FC1) 3.272 1.428 2.29
max::F64ArithmTest::(1280x720, 64FC1) 10.009 4.581 2.18
max::F64ArithmTest::(1920x1080, 64FC1) 21.962 10.130 2.17
min::F64ArithmTest::(127x61, 64FC1) 0.086 0.025 3.40
min::F64ArithmTest::(640x480, 64FC1) 3.316 1.417 2.34
min::F64ArithmTest::(1280x720, 64FC1) 10.133 4.583 2.21
min::F64ArithmTest::(1920x1080, 64FC1) 22.334 10.160 2.20
multiply::F64ArithmTest::(127x61, 64FC1) 0.062 0.024 2.61
multiply::F64ArithmTest::(640x480, 64FC1) 2.430 1.362 1.78
multiply::F64ArithmTest::(1280x720, 64FC1) 7.427 4.344 1.71
multiply::F64ArithmTest::(1920x1080, 64FC1) 16.160 9.370 1.72
subtract::F64ArithmTest::(127x61, 64FC1) 0.038 0.025 1.48
subtract::F64ArithmTest::(640x480, 64FC1) 1.696 1.523 1.11
subtract::F64ArithmTest::(1280x720, 64FC1) 4.794 4.805 1.00
subtract::F64ArithmTest::(1920x1080, 64FC1) 12.058 10.820 1.11
```
x-factor geomean **2.09x** (36 cases, 1.00-3.41x): compare ~3.3x, divide ~2.6x, min/max ~2.2x, absdiff ~2.2x, addWeighted ~2.2x, multiply ~1.7-2.6x. `add`/`subtract` stay near parity in both regimes — they appear to be served by a different (already-vectorized) path before the kernel table is consulted.
### 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
core: RVV HAL transpose2d for 3-channel element sizes - #30075
### Summary
`cv::transpose` for 3-channel types (`8UC3`/`8SC3`, `16UC3`/`16SC3`/`16FC3`, `32SC3`/`32FC3`) falls back to the scalar core path on RISC-V. The RVV HAL `transpose2d` dispatches on *element size* and only implements `esz ∈ {1, 2, 4, 8}`. This PR adds kernels for
`esz = 3, 6, 12`, and an accuracy test that covers the new paths including non-continuous ROI.
### Root cause
- `hal/riscv-rvv/src/core/transpose.cpp`: the `Transpose2dFunc tab[]` table has entries only at indices 1/2/4/8, so `cv_hal_transpose2d` returns `CV_HAL_ERROR_NOT_IMPLEMENTED` for every 3-channel type and the caller runs the generic path.
- On the scalable RVV backend (`intrin_rvv_scalable.hpp`) `CV_SIMD128` is never defined, so the existing `transpose_8/16/32/48bit_simd` fast paths `modules/core/src/matrix_transform.cpp` are compiled out entirely; what runs is the scalar 4x4 element loop. 8UC3 (the default color type) is the most visible case.
### Implementation
The new kernels deinterleave the three channels of several source rows with `vlseg3e{L}` and emit the transposed rows with strided segment stores (`vssseg{6,8}e{L}`). The number of source rows per block was picked experimentally: 8 rows for 8-bit lanes, 2 rows for 16/32-bit lanes. For 16/32-bit lanes, taller blocks e.g. 8 rows will add register pressure and cause regression. A one-row tail covers the remainder; unaligned 16/32-bit inputs fall back to the generic path.
### Performance
SpacemiT K1 / X60, OpenCV 5.x, `--perf_force_samples=20
--perf_min_samples=20`, `BinaryOpTest.transpose2d`:
| type (esz) | 640x480 | 1280x720 | 1920x1080 |
|---|---:|---:|---:|
| `CV_8UC3` (3) | 2.758 -> 1.648 ms (**1.67x**) | 16.772 -> 10.575 ms (**1.59x**) | 42.901 -> 39.552 ms (1.09x) |
| `CV_16SC3` (6) | 8.384 -> 3.556 ms (**2.36x**) | 31.112 -> 19.450 ms (**1.60x**) | 71.921 -> 62.460 ms (1.15x) |
Untouched element sizes (esz 1/2/4/8, 16 cases at 640x480 + 1280x720): geomean **1.005x**,
range 0.977x ... 1.058x.
### Accuracy
New test `Core_Transpose.C3ElementSizesWithRoi` (`modules/core/test/test_mat.cpp`) sweeps
`CV_8UC3, CV_8UC(6), CV_16SC3, CV_16FC3, CV_8UC(12), CV_32FC3` over sizes `1x1, 2x3, 137x5, 133x4` through non-continuous ROI views, byte-compares every element against the source, and asserts the bytes outside the destination ROI are untouched. On K1:
```
[ PASSED ] 4 tests. # Core_Transpose.C3ElementSizesWithRoi
# Core_Transpose/ElemWiseTest.accuracy/0
# Core_Rotate/ElemWiseTest.accuracy/0
```
`BinaryOpTest.transpose2d` already provides the performance coverage; no `opencv_extra` data is needed.
### 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
Improve fisheye extrinsic refinement for ill-conditioned views and
poorly scaled object points. Replace the Gauss-Newton update with a
Levenberg-Marquardt solver and normalize translation parameters to make
convergence less sensitive to problem scale.
Fisheye undistortion marks points it cannot undistort with a sentinel
coordinate. Poor intermediate intrinsics, such as those following a bad
initial guess, produce such points, which then corrupt the initial pose
estimate. Exclude them from the estimate.
The linear solver rejects singular normal equations only if rounding
yields a sufficiently small pivot. Whether degenerate views update the
intrinsics arbitrarily thus depends on the input and the platform.
Detect the singularity from the per-view blocks and their Schur
complement instead, and skip the update.
Carotene resize left edge clamp 5x - #30076
### 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
handleMessage() resets the state only when an error message is already on the bus. When the state change fails before the streaming thread posts its error, the pipeline was released in PAUSED with streaming threads still running, which logs 'Trying to dispose element ... but it is in PAUSED instead of the NULL state' and can crash the process.
dnn: reduce coordinate work in CPU Deconvolution - #30001
CPU `Deconvolution` computes coordinates and checks kernel bounds for each output value. This change builds valid tap tables for each axis, reuses outer coordinates per row, and uses SIMD for consecutive inputs at horizontal stride 1 or 2. It computes input addresses once per run and reuses them for each group of four outputs. Other positions use the scalar loop. Each output keeps the same sum order. The 1×1 path adds bias one channel segment at a time.
The table compares `5.x` at `8d126c4a` with this patch at `d0d1825`. It measures layer `forward()`, including GEMM, table setup, output reconstruction, and bias. The host is a Core Ultra 7 255H, with GCC 13.3, Release, one thread, and WSL2. IPP and OpenCL are disabled.
| Input, channels in/out | Kernel, stride | Upstream | PR | Speedup |
| --- | --- | ---: | ---: | ---: |
| 128×128, 16/16 | 1×1, 1 | 3.023 ms | 0.089 ms | 34.2× |
| 128×128, 16/16 | 2×2, 2 | 76.145 ms | 0.489 ms | 155.9× |
| 64×64, 16/16 | 3×3, 1, pad 1 | 10.709 ms | 0.239 ms | 44.8× |
| 16×16×16, 8/8 | 3×3×3, 1 | 21.843 ms | 0.472 ms | 46.3× |
Each time is the median of seven process medians, with two warmup calls and 31 measured calls per process. Version order alternates. Speedup uses the unrounded times.
Each worker reuses its address lists across rows. Their measured buffer capacities are 16 bytes for the 2×2 case and 96 bytes for the 3×3 case, excluding vector objects and allocator overhead. The SIMD run table is shared by the workers and uses one `size_t` per output column.
All 56 accuracy tests (8 new, 48 existing) pass with one and four threads. The eight performance tests pass. The 768 output comparisons match the base version. The extracted helper passes ASan/UBSan checks with SIMD and scalar code. The new accuracy tests use an independent scatter reference; duplicate pointwise and dynamic-weight cases were removed.
[Test code, raw results, and build steps](https://github.com/Hosi121/opencv/tree/bench/dnn-col2im-workspace/col2im-bench).
This changes the legacy CPU `Deconvolution` path. The new ONNX `ConvTranspose2` path is separate. These are layer results, not complete-model results. ARM hardware was not tested.
English is not my first language, so I used AI to help write this post.
Verify assembler can encode AVX-VNNI before enabling it - #29844
Closes: https://github.com/opencv/opencv/issues/29840
### 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
v_select had no 64-bit integer form on any backend except WASM, so code
that needs to blend v_int64/v_uint64 through a comparison mask had to
apply the mask by hand. intrin_sse.hpp carried the two entries commented
out as TBD; the other backends simply stopped at 32-bit and float64.
Every backend already blends bitwise or through a byte/boolean cast, so
the lane width does not change the operation:
SSE _mm_blendv_pd under CV_SSE4_1, the xor/and/xor form otherwise
AVX _mm256_blendv_epi8, as the narrower types already use
NEON vbslq_u64 / vbslq_s64
MSA msa_bslq_u8 over the byte reinterpretation
VSX vec_sel with the same boolean cast v_float64x2 uses
LSX/LASX __lsx_vbitsel_v / __lasx_xvbitsel_v on the raw register
RVV 0.7.1 vmerge_vvm with the b64 mask
RVV __riscv_vmerge, as for the narrower types
WASM already had both and is unchanged, and the generic v_reg
implementation in intrin_cpp.hpp already covers every type.
The 64-bit test chains could not simply call test_mask(), because its
v_signmask() expectations assume more than two lanes. Added test_select(),
which exercises v_select alone, and called it from TheTest<v_uint64>() and
TheTest<v_int64>().