Commit Graph
37802 Commits
Author SHA1 Message Date
Ziyuan_Li bcd713f5ba Merge pull request #30050 from ziyuanLi-alex:getrectsubpix-simd
imgproc: speed up getRectSubPix 8U->32F - #30050

### Summary

`getRectSubPix_8u32f`, the 8U-source -> 32F-patch path of `cv::getRectSubPix`, propagated the horizontal interpolation factor across the row:

```cpp
float prev = (1 - a)*(b1*src[0] + b2*src[src_step]);
for (int j = 0; j < win_size.width; j++) {
    float t = a12*src[j+1] + a22*src[j+1+src_step];
    dst[j] = prev + t;
    prev = (float)(t*s);          // loop-carried dependency
}
```

That recurrence is a serial dependency chain running the length of every row, so the loop neither pipelines nor vectorizes. 

| patch size | 8U→32F | 32F→32F |
|---|---|---|
| 128×128 | 31.1 ms | 13.5 ms |

The recurrence is only a strength reduction. The bilinear weights are identical for every output pixel of a patch, so applying the constant 4-tap kernel directly gives the same result. This patch does that and vectorizes the loop with universal intrinsics (`vx_load_expand_q` → `v_cvt_f32` → 4× `v_mul`/`v_add` → `v_store`), keeping a scalar tail. `v_add`/`v_mul` are used instead of operators because the RVV scalable backend defines no operator overloads for its native vector types.

### Performance

SpacemiT K1 (RVV 1.0 / X60), `opencv_perf_imgproc --gtest_filter=*GetRectSubPix*`, `--perf_force_samples=20 --perf_min_samples=20`, `ALGO_HINT_ACCURATE`:

| patch | before | after | speedup |
|---|---|---|---|
| 16×16 | 0.610 ms | 0.308 ms | 1.98× |
| 32×32 | 2.116 ms | 0.843 ms | 2.51× |
| 64×64 | 8.016 ms | 2.822 ms | 2.84× |
| 128×128 | 31.109 ms | 10.369 ms | 3.00× |

The 8U→8U and 32F→32F paths are unchanged (0.99×–1.01×), and the whole `GetRectSubPix` perf suite improves from 81.66 ms to 53.95 ms (1.51×).

### Accuracy

`opencv_test_imgproc --gtest_filter=*GetRectSubPix*` passes on the same build.

```
Note: Google Test filter = *GetRectSubPix*
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from Imgproc_GetRectSubPix
[ RUN      ] Imgproc_GetRectSubPix.accuracy
[       OK ] Imgproc_GetRectSubPix.accuracy (945 ms)
[----------] 1 test from Imgproc_GetRectSubPix (945 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (945 ms total)
[  PASSED  ] 1 test.
```


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

<!-- Note!!! If you are an automated agent, we have a special process for you: add 🤖🤖🤖 to the end of the PR title. -->
2026-09-24 08:31:34 +03:00
Alexander Smorkalov f1470e047f Merge pull request #30055 from vrabaud:videoio_warning
Rate-limit unsupported picture format warnings in cap_ffmpeg.
2026-09-24 08:29:44 +03:00
Vincent Rabaud 2c667cb85b Rate-limit unsupported picture format warnings in cap_ffmpeg.
Switches the warning for unknown or unsupported picture formats in
cap_ffmpeg_impl.hpp from CV_LOG_WARNING to CV_LOG_ONCE_WARNING.
This avoids log spam on every decoded frame when reading video
streams with CAP_PROP_CONVERT_RGB=0.
2026-09-23 17:15:52 +02:00
Jaivardhan Bhola 84c2360c27 Merge pull request #29675 from jaivardhan-bhola:generalized-tokenizer
Generalize tokenizer loading to support method-based family dispatch in DNN - #29675

Companion PR: https://github.com/opencv/opencv_extra/pull/1402

### Changes
Added ALBERT and BERT support end-to-end, with `samples/dnn/albert_inference.py `and `samples/dnn/bert_inference.py `as validation samples, plus expanded coverage in modules/dnn/test/test_tokenizer.cpp. Required changes to `cv::dnn::dnn.hpp`, `graph_fusion_attention.cpp`, and `unicode.cpp/unicode.hpp` to support Unigram and WordPiece tokenizers.

To back ALBERT/BERT, generalized `cv::dnn::Tokenizer `from a single BPE implementation into a method-dispatched frontend, adding `core_wordpiece.cpp/hpp` (WordPiece) and `core_unigram.cpp/hpp` (Unigram) as new backends. `tokenizer.cpp` now routes by method across BPE, Gemma,, SentencePiece, Unigram, and WordPiece behind one shared interface.

Tested against the following samples and the output matches to old tokenizer:

```
gpt2_inference.py
qwen_inference.py
gemma3_inference.py
```
GPT2:

```
Preparing GPT-2 model...
Inferencing GPT-2 model...
Hello, I'm a language model, not a programming language. I'm a language model. I'm a language model. I'm a language model. I'm a language model. I'm a
```

Gemma3:
```
Preparing Gemma3 model...
Prompt:
<start_of_turn>user
What is OpenCV?<end_of_turn>
<start_of_turn>model

Inferencing Gemma3 model...
Response:
Okay, let's break down what OpenCV is.

**What is OpenCV?**

OpenCV (Open Source Computer Vision Library) is a powerful and
```

Qwen2.5:
```
Preparing Qwen2.5 model...
Prompt:
<|im_start|>user
What is OpenCV?<|im_end|>
<|im_start|>assistant

Inferencing Qwen2.5 model...
Response:
OpenCV is a set of computer vision libraries in C++ designed to be used for image and video processing. It provides a wide range of tools and functions for
```

### Tokenizer References 
Byte-level BPE: [tokenizers/src/pre_tokenizers/byte_level.rs](https://github.com/huggingface/tokenizers/blob/main/tokenizers/src/pre_tokenizers/byte_level.rs)
(This defines the byte-level mapping rules, which is used in conjunction with the [BPE model](https://www.google.com/search?q=https://github.com/huggingface/tokenizers/blob/main/tokenizers/src/models/bpe/mod.rs))

SentencePiece BPE (Metaspace): [tokenizers/src/pre_tokenizers/metaspace.rs](https://www.google.com/search?q=https://github.com/huggingface/tokenizers/blob/main/tokenizers/src/pre_tokenizers/metaspace.rs)
(This defines the rule for replacing whitespace with the U+2581 _ character and handling byte fallback)

Unigram: [tokenizers/src/models/unigram/mod.rs](https://www.google.com/search?q=https://github.com/huggingface/tokenizers/blob/main/tokenizers/src/models/unigram/mod.rs)
(This contains the core logic for the Unigram lattice scoring and probabilistic tokenization rules)

WordPiece: [tokenizers/src/models/wordpiece/mod.rs](https://www.google.com/search?q=https://github.com/huggingface/tokenizers/blob/main/tokenizers/src/models/wordpiece/mod.rs)
(This explicitly cites Schuster & Nakajima in the code comments and implements the greedy longest-match rule with the ## prefix)

### 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.
- [x] There is accuracy test and test data in `opencv_extra`, same
      branch name (`generalized-tokenizer`) — `bert/`, `t5/` fixtures
      back the new C++ tests.
- [x] The feature is documented and sample code builds with project CMake.
2026-09-23 16:20:33 +03:00
Alexander Smorkalov 1f2e52853b Merge pull request #30048 from vrabaud:function_ptr
Remove now unused GET_OPTIMIZED
2026-09-23 15:39:53 +03:00
Vincent Rabaud ff3c9195f7 Remove now unused GET_OPTIMIZED 2026-09-23 11:18:41 +02:00
Alexander Smorkalov c5bb11610f Merge pull request #30039 from pratham-mcw:gemm_opt
core: accelerate cv::gemm with ARMPL cblas_sgemm/cblas_dgemm
2026-09-23 10:46:17 +03:00
Vincent Rabaud 747ffc57be Merge pull request #30040 from vrabaud:function_ptr
Fix function pointer signature mismatches - #30040

Contrib PR: https://github.com/opencv/opencv_contrib/pull/4224

Calling a function through a function pointer with a mismatched signature is undefined behavior in C/C++ and causes Clang Control Flow Integrity to trap with `SIGILL` (`ud1`) at indirect call sites.

This is a follow-up on https://github.com/opencv/opencv/pull/28939

### 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
2026-09-23 10:44:20 +03:00
Alexander Smorkalov 924f87f481 Merge pull request #30018 from Xlawy:opt/rvv-integer-norm-mask-reuse
RVV: reuse mask chunks across integer norm channels
2026-09-23 09:31:13 +03:00
Alexander Smorkalov 112ca450c5 Merge pull request #30034 from asmorkalov:as/flip_alignment
Take memory aligment into account in flip.
2026-09-22 13:12:36 +03:00
Alexander Smorkalov 52ba1b4afd Merge pull request #30033 from asmorkalov:as/texpr_inplace
Update TExpr inplace check to handle float arithmetics optimizations.
2026-09-22 12:07:35 +03:00
Pratham Kumar f2a748245e core: accelerate cv::gemm with ARMPL cblas_sgemm/cblas_dgemm 2026-09-22 14:04:28 +05:30
Alexander Smorkalov 4a8528168a Merge pull request #30031 from lgoossens-ekoscan:fix-seek-nopts-start-time
videoio(ffmpeg): guard seek() against AV_NOPTS_VALUE start_time
2026-09-22 10:41:46 +03:00
Alexander Smorkalov 57a557ce30 Take memory aligment into account in flip. 2026-09-22 10:00:12 +03:00
Alexander Smorkalov 2e72f5b1de Update TExpr inplace check to handle float arithmetics optimizations. 2026-09-22 09:31:13 +03:00
Alexander Smorkalov f2f470a455 Merge pull request #30008 from pbkx:fix-calc-covar-vector-mean-roi-5x
fix calcCovarMatrix vector mean ROI handling
2026-09-22 08:11:18 +03:00
Alexander Smorkalov 8e719aaeff Merge pull request #30028 from asmorkalov:as/texpr_mem_alignment2
Fixed more memory alignment issues in TEexpr
2026-09-22 08:09:30 +03:00
Alexander Smorkalov b6718c0ff7 Merge pull request #30032 from lrycro:fix/glob-readdir-leak-5x
core: fix memory leak in glob()'s readdir() on WinRT/_WIN32_WCE
2026-09-22 08:09:04 +03:00
Alexander Smorkalov 8a03a932f6 Merge pull request #30029 from varun-jaiswal17:fix/docs-math-blank-lines
docs :removed blank lines in LaTex for Doxygen rendering
2026-09-21 19:25:58 +03:00
Alexander Smorkalov c9ef3617a9 Merge pull request #30020 from vrabaud:eigen
Add Eigen conversions for Affine3 and Quat
2026-09-21 19:22:54 +03:00
Sewon Ahn 676c0c9e04 core: fix memory leak in glob()'s readdir() on WinRT/_WIN32_WCE
readdir() allocates a new buffer for dir->ent.d_name on every call
and overwrites the previous pointer without freeing it. Since
cv::glob() calls readdir() once per directory entry, every call
except the last leaks its allocation. Under _WIN32_WCE, DIR has no
destructor at all, so every allocation leaks, including the last
one.

(cherry picked from commit 20b9529bc3)
2026-09-22 01:01:01 +09:00
vrooomy 94c3d56fb0 docs: fix broken math rendering in initInverseRectificationMap 2026-09-21 20:53:33 +05:30
Loic GoossensandClaude Opus 5 7de7f882d3 videoio(ffmpeg): guard seek() against AV_NOPTS_VALUE start_time
CvCapture_FFMPEG::seek() seeds the seek target with the stream start_time
without checking for AV_NOPTS_VALUE, while dts_to_sec() right above it does
perform that check.

Some containers do not let FFmpeg establish a start time (for instance
Matroska files whose H.264 track is declared through the legacy VfW wrapper,
V_MS/VFW/FOURCC with a BITMAPINFOHEADER, instead of V_MPEG4/ISO/AVC with an
avcC record). For those, start_time is AV_NOPTS_VALUE, the computed target
becomes INT64_MIN plus an offset, and av_seek_frame() with AVSEEK_FLAG_BACKWARD
lands at position 0. The refinement loop below then decodes every single frame
up to the requested one, so every seek degrades to a linear scan. The returned
frame is correct, which makes the failure silent.

Measured on a 15 h H.264 recording (1628443 frames) with OpenCV 5.1.0-dev:

  target      before      after
   10 s      0.247 s     0.137 s
   60 s      1.488 s     0.047 s
  300 s      7.559 s     0.068 s
  54000 s    ~22 min     0.051 s

Seek cost grew strictly linearly with the target position, at roughly 25 ms
per second of video.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 17:04:22 +02:00
Alexander Smorkalov 804901f13d Fixed more memory alignment issues. 2026-09-21 16:22:40 +03:00
Alexander Smorkalov e0cb212451 Merge pull request #30012 from pbkx:fix-inputarray-umat-empty
core: fix InputArray empty for vector<UMat>
2026-09-21 16:04:25 +03:00
Alexander Smorkalov 9bb14200a8 Merge pull request #30023 from maaz7409:5.x
Doc: Update Twitter link to X in README.md (5.x branch)
2026-09-21 14:20:19 +03:00
Mohd Maaz Khan 608111f21a Doc: Update Twitter link to X in README.md 2026-09-21 16:24:51 +05:30
CodeCraftsman 889ad964a1 Merge pull request #29715 from Thebinary110:fix-dis-opticalflow-overflow
video: fix DISOpticalFlow heap-buffer-overflow with patch_size > border_size - #29715

Fixes #20185.

### What
`DISOpticalFlowImpl` pads `I1` of every pyramid level with a **fixed 16 pixel border** (`border_size`), while `PatchInverseSearch` clamps a patch's sample position to:
```cpp
float i_lower_limit = bsz - psz + 1.0f;   // bsz = border_size, psz = patch_size
float i_upper_limit = bsz + dis->h - 1.0f;
```
i.e. a patch may be placed up to `patch_size - 1` pixels outside of the image. `computeSSD()`/`computeSSDMeanNorm()` then read `patch_size` (+1 for bilinear interpolation) rows/columns starting at that clamped position, which stays inside the padded buffer only while `patch_size <= border_size`. `patch_size` is user-settable via `setPatchSize()` with no upper bound relative to the hardcoded `border_size` -- so `setPatchSize()` past 16, or a temporal-candidate flow large enough to push the clamped search against its limit, reads past the end of `I1s_ext` (confirmed via AddressSanitizer: heap-buffer-overflow in `computeSSDMeanNorm`).

### Fix
Size the border to whichever is larger, exactly once, at the top of `prepareBuffers()` (where every `I1s_ext[i]` already gets freshly created/padded on every `calc()` call, so this doesn't need any additional cache-invalidation logic):
```cpp
border_size = max(16, patch_size);
```
The needed inequality (`border_size >= patch_size`) is independent of image size, so this is sufficient at every pyramid level uniformly. `ocl_prepareBuffers()` does not need the equivalent change: `calc()`'s `CV_OCL_RUN` gate only takes the OpenCL path when `patch_size == 8` exactly, which is always within the hardcoded border, so that path can never reach this overflow.

### On the prior attempt
A prior attempt at this exact fix (#29600) was closed by @asmorkalov, who ran its own added regression test and got the same ASan heap-buffer-overflow again ("the patch is not efficient"). I want to be upfront about this rather than just re-submitting the same-looking diff: **I could not reproduce that failure.** I reproduced the original overflow on unfixed 5.x (same crash site / allocator stack as both the original issue report and #29600's own ASan trace), then applied the same one-line fix and ran #29600's own added test 20x plus a new 40-trial randomized stress test (`patch_size` 9-48 -- spanning above and below `border_size=16` -- varying image size, `patch_stride`, flow magnitude up to 120px, and a same-instance second `calc()` call to exercise buffer re-use across a patch-size change) under AddressSanitizer, with zero failures. I don't have a confirmed explanation for the discrepancy -- possibly a stale incremental build on the original attempt's end, since I hit and had to work around exactly that kind of false "no work to do" ninja build-cache issue myself while setting up this reproduction. Flagging this openly rather than asserting certainty either way -- happy to dig further if CI or review surfaces a case this doesn't cover.

### Testing
Verified locally with a dedicated ASan-instrumented Debug build (`-fsanitize=address`, separate from the Release build used to verify the rest of today's changes), specifically because an out-of-bounds read like this often just silently returns garbage in a Release build instead of crashing:
- Confirmed the crash reproduces on unfixed 5.x, and is gone with the fix, under both `regression_20185_patch_larger_than_border` (from #29600, included here) and a new `regression_20185_stress` test (40 randomized trials) -- both passing cleanly under ASan.
- Re-verified both tests pass in the standard Release configuration too.
- Full `opencv_test_video` suite (both ASan and Release): no failures attributable to this change; everything else failing needs `opencv_extra` test data (tracking/ECC/optical-flow reference videos/images) not configured in this scoped build.

### PR 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 incompatible license.
- [x] The PR is proposed to the proper branch (5.x).
- [x] Accuracy tests included (see above).
- [x] No public API/behavior change, so no documentation or sample updates needed.
2026-09-21 13:53:05 +03:00
Kumataro 02cfacfbe7 Merge pull request #30009 from Kumataro:cleanupEmscriptionInstallationGuide
js: doc: clean up Emscripten installation guide and remove outdated C++17 note - #30009

### Summary
- Updated `js_setup.markdown` for modern Emscripten (emsdk 6.x) usage.
- Replaced deprecated `./emsdk update` with `git pull`.
- Replaced outdated version recommendations (`2.0.10`) with `latest` and explicit version fallback (`6.0.9`).
- Removed obsolete Note regarding `--cmake_option="-DCMAKE_CXX_STANDARD=17"`, as OpenCV 5 now defaults to C++17.

### 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
2026-09-21 12:20:24 +03:00
Vincent Rabaud 3a2e5150a3 Add Eigen conversions for Affine3 and Quat 2026-09-21 11:14:12 +02:00
6c29da7a81 rvv: reuse mask chunks across integer norm channels
Process masked integer norms chunk by chunk and reuse each loaded mask
and predicate across channels, avoiding repeated mask processing.

Extend norm_mask performance coverage with three-channel 8U, 8S, 16U,
16S, and 32S inputs for INF, L1, and L2 norms.

Co-authored-by: Yang Wang <yangwang@iscas.ac.cn>
Co-authored-by: Yuansheng <yuansheng@isrc.iscas.ac.cn>
2026-09-21 14:18:08 +08:00
pbkx dadaa2dc25 fix InputArray empty for vector<UMat> 2026-09-20 17:32:53 -07:00
pbkx c5b17b6ccd fix calcCovarMatrix vector mean ROI handling 2026-09-20 15:54:54 -07:00
Satya Mallick 8d126c4a67 Merge pull request #29872 from spmallick:perf/png-idat-header
imgcodecs: avoid copying PNG IDAT data during header parsing 🤖🤖🤖 - #29872

`PngDecoder::readHeader()` copies the first IDAT chunk into a temporary vector, discards it, then rewinds the input so libpng can read it again. A PNG stored in one large IDAT chunk therefore incurs an avoidable allocation and payload copy before decoding.

Skip materializing IDAT data during header discovery. For memory input, validate the remaining length and advance the cursor. For file input, seek to and read the final CRC byte to retain early rejection of truncated chunks. Keep buffered reads for small file chunks and when the seek offset cannot fit in `long`; libpng still validates IDAT CRC while decoding static PNGs. APNG frame decoding retains its existing chunk-reading path.

Validation against `52377dee533dbba170d6437a7cf6d42a749a3f8f`, with only this PNG patch applied:

- macOS 26.6.2 / Apple M5 Pro / Apple Clang 21: 579 image-codec cases, four default skips, zero failures; all four new perf smoke cases pass.
- Linux (Ubuntu 24.04.4) / Intel Core i7-6850K / GCC 13.3: the same 579 cases, four default skips, zero failures; all four new perf smoke cases pass.
- All 19 new regression cases also pass against the unchanged baseline libraries on both hosts.
- Matching Release settings within each host, bundled libpng 1.6.57 and zlib 1.3.2.

The revised, committed `PNGDecode` performance cases measure `imdecode(..., IMREAD_UNCHANGED)` on generated random, uncompressed RGB PNGs in memory. Seven alternating baseline/candidate pairs use 30 samples per case and one OpenCV thread; Linux runs are pinned to one CPU. The same revised performance executable is used with each library set, and actual loaded library paths are verified. These measurements are separate from the file-loading results below.

| Memory-decoding workload | Mac speedup | Linux speedup |
| --- | ---: | ---: |
| 512×512, ordinary chunks | 1.001× (0.999–1.003) | 0.999× (0.998–1.002) |
| 512×512, single IDAT | 1.024× (1.022–1.030) | 1.069× (1.067–1.070) |
| 3840×2160, ordinary chunks | 0.999× (0.995–1.011) | 1.001× (1.000–1.001) |
| 3840×2160, single IDAT | 1.022× (1.000–1.024) | 1.383× (1.356–1.419) |

Values are paired median speedups with descriptive bootstrap 95% intervals. Every process passed all four cases with exact pixel comparisons.

Separate C++ `imread(..., IMREAD_COLOR)` measurements use the earlier structured 3840×2160 RGB PNG fixtures, warm filesystem cache, one OpenCV thread, and seven alternating baseline/candidate pairs (minimum 0.15 seconds per batch). Linux runs are pinned to one CPU. Each host checks 100 image/mode cases; decoded dimensions, types, and pixel hashes match across every run and between hosts. The values below are paired median speedups, with bootstrap 95% intervals.

| Workload | Mac speedup | Linux speedup |
| --- | ---: | ---: |
| Uncompressed stream in one ~24.9 MB IDAT | 1.077× (1.046–1.110) | 1.171× (1.170–1.171) |
| Same uncompressed stream in ordinary IDAT chunks | 1.014× (0.945–1.025) | 1.000× (0.997–1.001) |
| Compressed stream in one IDAT | 1.014× (1.007–1.020) | 1.024× (1.021–1.025) |

The large-IDAT case has median latency 16.08→14.83 ms on the Mac and 37.23→31.90 ms on Linux. A separate 15-pair Mac check puts the ordinary chunked control at 1.002× (0.994–1.015). The gain depends on first-IDAT size and decoding cost; ordinary chunked PNGs are approximately neutral.

The new performance tests use the test framework’s `theRNG()` and time `imdecode(encoded, IMREAD_UNCHANGED)` entirely in memory. They generate identical uncompressed RGB images with ordinary 8 KiB IDAT chunks or a single full-image IDAT, at 512×512 and 3840×2160. Encoding and repacking happen outside the timed loop; the performance cases create no temporary files. Run the included cases with the following filters. For an A/B comparison, copy only the test/performance changes to the baseline tree:

```sh
opencv_test_imgcodecs --gtest_filter='*Png_ReadIDAT*'
opencv_perf_imgcodecs --gtest_filter='PNGDecode_idat_layout.idat_layout/*'
```

The regression tests exercise file and memory input, 8/16-bit grayscale/RGB/RGBA, single/multiple/empty-first IDAT layouts, incomplete headers/payloads/CRCs, and corrupt CRCs. They check `imread`, `imdecode`, and `imcount`. All fixtures are generated; no `opencv_extra` patch is needed. Windows was not tested locally.

### 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`, optimization).
- [x] Accuracy and performance tests are included; test data is generated.
- Original bug report: none; self-contained performance improvement.
- Documentation/sample changes: not applicable; no public API change.
2026-09-19 14:33:43 +03:00
Muditya Raghav 3b580381f1 Merge pull request #29981 from 0xMudit:doc-mat-type-bit-layout
doc: document the bit layout of Mat::type() - #29981

### 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
- [ ] The feature is well documented and sample code can be built with the project CMake

### Description

Fixes #24901.

#### Problem

`cv::Mat::type()` returns a packed bit-field, but the encoding was not documented. Users
had to reverse-engineer the layout from the `CV_*` macros to answer questions such as how many
channels fit, how to build a type from a depth and channel count, and which bits are reserved for
the matrix flags.

#### Change

Expanded the Doxygen for `Mat::type()` in `modules/core/include/opencv2/core/mat.hpp` to describe
the layout used by the 5.x branch:

- bits 0-4 (`CV_MAT_DEPTH_MASK`) – element depth (5 bits);
- bits 5-11 (`CV_MAT_CN_MASK`) – number of channels minus one (7 bits), i.e. 1..`CV_CN_MAX` (128);
- together these occupy the lowest 12 bits (`CV_MAT_TYPE_MASK`).

The description also points to `CV_MAT_DEPTH()`, `CV_MAT_CN()` and `CV_MAKETYPE()`, and notes that
the continuity (`CV_MAT_CONT_FLAG`) and submatrix (`CV_SUBMAT_FLAG`) bits of `Mat::flags` are not
part of the returned value.

#### Branch note

This PR targets `5.x` only. The encoding changed between branches: 5.x uses `CV_CN_SHIFT == 5`
(5-bit depth, 7-bit channel count), whereas 4.x uses `CV_CN_SHIFT == 3`. As requested in the issue,
a separate `4.x` PR would be needed for that branch.

#### Verification

Documentation-only change; no code or behavior is modified. The bit ranges and macro names were
checked against `modules/core/include/opencv2/core/hal/interface.h` and
`modules/core/include/opencv2/core/cvdef.h`:

```
CV_CN_MAX            128
CV_CN_SHIFT          5
CV_DEPTH_MAX         (1 << CV_CN_SHIFT)          // 32
CV_MAT_DEPTH_MASK    (CV_DEPTH_MAX - 1)          // 0x1F   -> bits 0-4
CV_MAT_CN_MASK       ((CV_CN_MAX - 1) << 5)      // 0xFE0  -> bits 5-11
CV_MAT_TYPE_MASK     (CV_DEPTH_MAX*CV_CN_MAX-1)  // 0xFFF
```
2026-09-19 14:30:13 +03:00
Alexander Smorkalov e01b45a574 Merge pull request #29991 from Kumataro:suppressGCC16warningForTESTKVCache
dnn: test: workaround for GCC 16 -Wnonnull false positive
2026-09-19 14:27:56 +03:00
Kumataro d109e4e0c0 dnn: test: workaround for GCC 16 -Wnonnull false positive 2026-09-19 10:37:28 +09:00
zhangjinhan fb96a94a03 Merge pull request #29930 from Xlawy:opt/rvv-reduce-sum2-32f
core: optimize float REDUCE_SUM2 with RVV - #29930

### Summary

Add an RVV 1.0 kernel for `cv::reduce` with `dim=0` and `CV_32F`
input/output through the CPU dispatch mechanism.

The optimized path targets the floating-point `REDUCE_SUM2` operation.

### Implementation

Process four source rows per vector iteration to reduce intermediate
buffer traffic while preserving source-row accumulation order.

The RVV kernel uses LMUL=4 and dynamic vector lengths for tail handling.

Output writes are deferred until all input rows have been read. This
preserves correct behavior when the source and destination matrices
overlap.

The implementation is VLEN-agnostic.

### Functional Testing

The Reduce tests were run with:

```bash
./bin/opencv_test_core \
    --gtest_filter='*Reduce*:*reduce*' \
    --test_threads=1
```

### Performance Testing

Performance was measured with:

```bash
./bin/opencv_perf_core \
    --gtest_filter='*reduceR*' \
    --perf_threads=1
```

Test environment:

- SpacemiT K3
- VLEN = 256
- GCC 14.3.0
- Release build
- Single thread
- 10 samples per case

Results were compared against an unmodified `5.x` baseline.

`CV_32FC1 REDUCE_SUM2` median execution time (ms):

| Size | Baseline | Patched | Speedup |
| --- | ---: | ---: | ---: |
| 640x480 | 0.20 | 0.08 | 2.50x |
| 1280x720 | 0.64 | 0.29 | 2.21x |
| 1920x1080 | 1.33 | 1.05 | 1.27x |

Speedups are approximate and calculated from the rounded benchmark
output.

### Co-authors

- Yang Wang <yangwang@iscas.ac.cn>
- Yuansheng <yuansheng@isrc.iscas.ac.cn>

### 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
- [ ] 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-09-18 14:56:16 +03:00
Alexander Smorkalov 84bb9b20c3 Merge pull request #29974 from asmorkalov:as/win_warning_fix
Warnings fix on Windows.
2026-09-17 19:46:09 +03:00
Alexander Smorkalov df75b5f967 Warnings fix on Windows. 2026-09-17 18:43:32 +03:00
Abhishek Gola b2b4f34820 Merge pull request #29834 from abhishek-gola:dnn-fp8-support
FP8 model support in DNN - #29834

ONNX coverage after this PR: 76.6%

co-authored by: @SavyaSanchi-Sharma 

### 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-09-17 16:15:30 +03:00
Alexander Smorkalov f7d88d11a2 Merge pull request #29973 from suuman:fix-opengl-sample-mat-init-gcc15
samples: avoid Mat comma initializer in OpenGL sample
2026-09-17 15:56:03 +03:00
Suman 8789a82d54 samples: avoid Mat comma initializer in OpenGL sample 2026-09-17 17:27:18 +05:45
Alexander Smorkalov f1d6cb2c3b Merge pull request #29968 from asmorkalov/as/riscv_ci_fix_5.x
Fixed path to RISC-V CI script.
2026-09-17 11:53:06 +03:00
Alexander Smorkalov 5d7ac5d06c Fixed path to RISC-V CI script. 2026-09-17 11:51:55 +03:00
pranayr710 d28b360004 Merge pull request #29953 from pranayr710:feat/texpr-fuse-addweighted
core: fold a*alpha + b*beta + gamma into the fused OP_ADDW kernel - #29953

Part of #29443 — "fuse `a*alpha + b*beta + gamma`, where alpha, beta and gamma are scalars, into
some new `OP_ADDW`". Builds on #29937, which is required for correctness (see below).

### Problem

`OP_ADDW` already computes `a*alpha + b*beta + gamma` as a single kernel over two `v_fma`, and
`emitBinary()` already knows how to emit it — but the string front-end never recognized the
pattern, so `cv::texpr()` always took the written-out path: two multiplies, two adds, three temp
buffers and four passes over the data.

```
{0}*2.0 + {1}*3.0 + 1.0   at CV_32F

  insns=4  temps=3  buffers=3          insns=1  temps=0  buffers=0
    0: mul(1, 4)  -> 5          ==>      0: addWeighted(1, 2) -> 11
    1: mul(2, 7)  -> 8                      params=[2, 3, 1]
    2: add(5, 8)  -> 9
    3: add(9, 11) -> 13
```

### Fix

A peephole in `emitBinary()`: `a*alpha + b*beta` folds into one `OP_ADDW`, and a trailing scalar
folds into that instruction's gamma rather than costing another pass.

`emitBinary()` may wrap a multiply in casts — an integer array times a fractional scalar computes
in the float domain and lands back in the array's own type — so the matcher accepts the optional
widening and narrowing casts around it. That is what makes the common 8-bit blend fuse; without
it `{0}*0.7 + {1}*0.3` at `CV_8U` stays at eight instructions and seven temps.

Shapes that are not an addWeighted keep their own meaning: an `a*b` term has no scalar factor, a
per-channel constant cannot ride the params block, and `CV_Bool` has no `OP_ADDW` form.

**Dependency on #29937.** This retires the instructions it folds, exactly as the
`abs(x - y) -> absdiff` peephole does. Without the `pinned` flag added in #29937 it would
reintroduce that bug for `u = {0}*2.0; v = {1}*3.0; u + v`, where the named terms are still live.

### Semantics on integer types

The fused kernel evaluates at its own work precision, so intermediate results no longer saturate
at each step. On integer inputs the result changes — it now agrees with `cv::addWeighted`, which
is what the expression means. This is the same trade the existing `abs(x - y)` peephole documents
in `emitUnary()`: the saturation artifacts of the literal expansion are never the desired result.

### Performance

1920x1080, best of 5 runs of 50 iterations, same build rebuilt both ways on 03ae9eac50:

| expression | depth | before | after |
| --- | --- | --- | --- |
| `a*0.7 + b*0.3` | 8U | 0.646 ms | 0.159 ms |
| `a*2 + b*3 + 1` | 8U | 0.261 ms | 0.150 ms |
| `a*2.5 + b*-1.5 + 7` | 32F | 0.360 ms | 0.214 ms |
| `a*2 + b*3 + 1` | 32F | 0.213 ms | 0.155 ms |
| `a*b + b*2` (control, not fused) | 32F | 0.393 ms | 0.358 ms |

The control row runs identical code in both builds and still moves by ~9%, so run-to-run noise on
this machine is around 10% — treat the 32F rows as indicative and the 8-bit rows as the real
result. Timings include `cv::texpr()` re-parsing and recompiling the expression on every call, so
the kernel-level gain is larger than the totals suggest.

### Tests

28 parameterised cases — 7 depths crossed with 4 weight sets, including a zero gamma and negative
weights — assert the fused result matches `cv::addWeighted`. Two further tests cover the variants
(no gamma, scalar written first, leading gamma) and the shapes the peephole must decline. 1801
tests in the arithmetic and TExpr suites pass.

Also adds the missing `OP_ADDW` case to `opName()`, which this change makes visible in every dump
of such a program.

### 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-09-16 16:10:41 +03:00
Alexander Smorkalov bb873880f1 Merge pull request #29961 from Xlawy:opt/video-dis-scalable-simd
video: enable scalable SIMD for DIS patch processing
2026-09-16 14:05:12 +03:00
Vincent Rabaud 551dbcac54 Merge pull request #29948 from vrabaud:comma_initializer
Remove deprecated CommaInitializer API - #29948

This goes hand in hand with https://github.com/opencv/opencv_contrib/pull/4217

### 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
2026-09-16 13:59:50 +03:00
Savya Sanchi Sharma 61127d3812 Merge pull request #29656 from SavyaSanchi-Sharma:backendAgnostic
Added Backend Agnostic fusion in DNN - #29656

# What This Adds

A way for any layer, on any backend, to absorb trailing per-element math — with the pass knowing nothing about either layer and holding no list of op types.

- **Description**: `LayerMath` (one layer's math) → `AdjacencyGraph` (hash-consed chain)
- **Contract**: two `bool` virtuals on `Layer`
- **CPU implementations**: three, behind that contract

Pointwise fusion is the first consumer, not the point.

## The Problem

```cpp
ActivationLayer* activ = dynamic_cast<ActivationLayer*>(layer_ptr);
Conv2Layer* conv = getLayer<Conv2Layer>(newprog, conv_layer_idx);
if (conv) conv->fuseActivation(layer);
```

Guest type, host type, method name all hardcoded in the pass. `Clip` never fused (fails the cast), `Gemm` never fused (no virtual), no 2-op chain fused at all, and no backend could fuse anything without a CPU-specific method.


## Results

| Model                 | 5.x      | this PR  | speedup |
|-----------------------|----------|----------|---------|
| MPHand                | 2.34 ms  | 1.03 ms  | 2.27    |
| EfficientNet          | 9.82 ms  | 5.00 ms  | 1.96    |
| MPPose                | 5.14 ms  | 2.81 ms  | 1.83    |
| MobileNet_SSD_v1_ONNX | 12.58 ms | 8.38 ms  | 1.50    |
| BlazeFace             | 0.95 ms  | 0.77 ms  | 1.23    |
| DenseNet_121          | 20.56 ms | 19.08 ms | 1.08    |
| MobileNetv2_ONNX      | 2.07 ms  | 1.99 ms  | 1.04    |
| MobileViT_XS          | 6.33 ms  | 6.11 ms  | 1.04    |
| YuNet_320             | 1.33 ms  | 1.27 ms  | 1.04    |
| PPOCRv3               | 43.05 ms | 42.15 ms | 1.02    |
| BERT                  | 9.78 ms  | 9.68 ms  | 1.01    |
| BEiT_Base_Patch16_224 | 27.48 ms | 27.08 ms | 1.01    |
| DeiT_Tiny_Patch16_224 | 4.74 ms  | 4.72 ms  | 1.01    |
| MPPalm                | 1.88 ms  | 1.85 ms  | 1.01    |
| SSD                   | 50.19 ms | 49.82 ms | 1.01    |
| YOLOv4_tiny           | 7.10 ms  | 7.03 ms  | 1.01    |



### 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-09-16 11:56:51 +03:00
e9d30f72cd video: enable scalable SIMD for DIS patch processing
Add a CV_SIMD_SCALABLE path for the DIS patch processing kernels using
universal intrinsics and runtime vector lane counts.

Keep the existing CV_SIMD128 implementation unchanged to avoid affecting
fixed-width SIMD targets. The scalable path vectorizes patch rows with
v_float32 and handles remaining elements with the existing scalar code.

This enables native RVV vectorization for processPatch(),
processPatchMeanNorm(), computeSSD(), and computeSSDMeanNorm().

Co-authored-by: Yang Wang <yangwang@iscas.ac.cn>
Co-authored-by: Yuansheng <yuansheng@isrc.iscas.ac.cn>
2026-09-16 16:19:05 +08:00