Commit Graph

27294 Commits

Author SHA1 Message Date
sanjay
fefe7b7adc dnn: drop x86-only hybrid-CPU detection; add graph-level QKV grouping test
Always oversubscribe 4 tiles/thread in MLAS threading instead of detecting
mixed-core CPUs via CPUID, which never covers ARM big.LITTLE or Apple's
P/E cores. Matches the same tradeoff core/src/arithm_expr.cpp already
accepts for heterogeneous cores.

Also add Fusion.AttentionQKVGrouping{SeqMerge,BatchMerge}, which exercise
readQKVGrouping()/evalDims() against a real Shape/Gather/Mul/Concat chain
feeding the QKV Reshape, rather than injecting qkv_batch/qkv_seq directly
as a layer param like the existing AttentionLayer-level tests do.
2026-10-15 14:07:28 +05:30
sanjay
2c6130dc03 Merge 5.x: keep unconditional bias push, keep QKV grouping 2026-10-15 13:09:49 +05:30
Alexander Smorkalov
e13b74e9a7 Merge pull request #30294 from sshivensolanki:fix-fp8-split-merge
core: support fp8 depths in split, merge and mixChannels
2026-10-15 10:06:32 +03:00
sanjayk9
dc9d92c46d Merge pull request #30284 from sanjayk9:dnn-attention-fusion-missing-bias
dnn: fuse attention when a Q/K/V projection has no bias - #30284

The fused Attention layer needs the full QKV bias. Fill a missing projection bias with zeros in all three attention fusion paths, and leave the block unfused if a bias has the wrong length. The CLIP path dropped all three biases when one was missing, and the generic path read K/V bias blobs that may not exist. All three paths now emit a 1-D bias. Fixes the trOCR encoder.
some extra models and inputs added to opencv_extra: https://github.com/opencv/opencv_extra/pull/1433
### 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-15 08:18:10 +03:00
NIKHIL
50d26f4956 Merge pull request #30287 from Nikhi00718:fix/dnn-blob-rect-no-resize-5.x
dnn: fix blobRectsToImageRects when the image is not resized (5.x) - #30287

### 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. 5.x port of #30243, as requested there. Related: #30042.
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable. Accuracy test added; no test data needed.
- [ ] The feature is well documented and sample code can be built with the project CMake. Not applicable to this bug fix.

### Problem

Port of #30243 to 5.x. `Image2BlobParams::blobRectToImageRect()` and `blobRectsToImageRects()` are identical on 5.x and have the same bug:

- When `Image2BlobParams::size` equals the image size, every output rect is `Rect(0, 0, 0, 0)`, in all three padding modes.
- When `size` is empty (the default, which `blobFromImageWithParams()` treats as "keep the image size"), the mapping divides by zero and returns `INT_MIN` coordinates.

```python
import cv2 as cv

p = cv.dnn.Image2BlobParams()
p.size = (640, 640)
p.paddingmode = cv.dnn.DNN_PMODE_LETTERBOX
print(p.blobRectToImageRect((10, 20, 30, 40), (640, 640)))
# (0, 0, 0, 0), expected (10, 20, 30, 40)

p.size = (0, 0)
print(p.blobRectToImageRect((10, 20, 30, 40), (640, 480)))
# (-2147483648, -2147483648, -2147483648, -2147483648), expected (10, 20, 30, 40)
```

### Change

Same change as #30243, cherry-picked without conflicts. `blobRectsToImageRects()` now follows the same two rules as `blobFromImagesWithParams()` on 5.x: an empty `size` means the image size, and when the sizes match the input rects are returned unchanged. The resize, crop-center and letterbox mappings are unchanged. It also includes the Doxygen `@note` on both functions requested in the #30243 review.

The new `blobRectToImageRect.no_resize` test covers both cases for all three padding modes, and checks that the blob built with the same parameters is pixel-identical to the image.

#30042 contains an equivalent pass-through for the equal-size case as part of a larger Model API change. This PR is the standalone fix, including the empty-size case. If #30042 lands first, the conflict should be limited to `blobRectsToImageRects()`.

### Testing

Built `opencv_test_dnn` and the Python bindings from this branch (base 5.x `6dc5ff5c1f`) on Ubuntu 26.04 (WSL2), GCC 15.2, Ninja, `BUILD_LIST=dnn,python3,ts`.

- `opencv_test_dnn --gtest_filter=blobRectToImageRect*`: 4 passed. With only the `dnn_utils.cpp` change reverted, the new `blobRectToImageRect.no_resize` fails in all six mode/size combinations (`[0 x 0 from (0, 0)]` for equal sizes, `INT_MIN` for empty size).
- `opencv_test_dnn --gtest_filter='blob*:*Image2Blob*:*imagesFromBlob*'`: 11 passed.
- `modules/dnn/misc/python/test/test_dnn.py`: 8 passed, 2 skipped; 6 failed only because their opencv_extra files are not present locally (`dnn/googlenet_0.png`, `dnn/street.png`, ...).
- The Python reproducer above prints `(10, 20, 30, 40)` for both cases with this branch (`5.1.0-dev`).
- No compiler warnings in the build; `git diff --check` clean.
- Full `opencv_test_dnn` was not run (needs opencv_extra test data).
2026-10-15 08:13:13 +03:00
Alexander Smorkalov
c8b0c20076 Merge pull request #30290 from asmorkalov:aravis-enumerate-devices
videoio: implement camera enumeration for ARAVIS backend
2026-10-15 08:11:13 +03:00
Savya Sanchi Sharma
62037304f5 Merge pull request #30285 from SavyaSanchi-Sharma:opti/topk
dnn: accept TopK with K = 0 and fix broadcast eltwise ops in block layout - #30285

### TopK with K = 0
Detectors exported from TensorFlow (e.g. SSD MobileNet v1) sort the boxes kept by NMS
with TopK, where K is the number of kept boxes. On an image with no detections K = 0
and TopK2 failed with "dynamic K must be > 0". The ONNX spec asks for K > 0, but ONNX
Runtime accepts K = 0 and returns empty outputs; TopK2 now does the same.

### Broadcast eltwise ops in block layout
When every input of an eltwise op is in block layout (NCHWc), the op stays in block
layout even if one input has a single channel, e.g. BiRefNet's attention gating
`[1,1536,32,32] * [1,1,32,32]`. The single channel lives in lane 0 of its block, so 7 of
every 8 output channels were multiplied by padding, and the output shape lost its block
marking. The 1-channel input now has lane 0 copied into every lane before broadcasting,
and the output is marked as block with the full channel count.


### 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-15 08:10:46 +03:00
sanjay
fa0d4a06a1 dnn: group a fused Attention's tokens the way its QKV reshape does
The fusion read only num_heads and head_dim from the QKV Reshape target,
so a graph reshaping Q/K/V to [B, T*S, H, D] fused the same way as one
reshaping to [B*T, S, H, D], and the fused layer computed the second for
both, giving a wrong result for the first.

The fusion now records the first two target entries, the batch and the
sequence length the attention runs over, each as a constant times a
product of input dims, or as inferred. It reads constants and chains of
Shape, Gather, Mul, Unsqueeze, Squeeze and Cast (as in the SAM3 decoder).
If an entry is computed some other way, or Q, K and V disagree, the block
is left unfused. The layer evaluates the record against the input shape
and runs over that grouping, which is a view of the same contiguous
tokens. Without a record, as for the ONNX Attention op, the input must be
3D.
2026-10-14 21:13:31 +05:30
Shiven Solanki
19fc7d3052 core: support fp8 depths in split, merge and mixChannels 2026-10-14 21:20:21 +08:00
sanjay
692cd53518 dnn: address asmorkalov's review comments on #30277
- test_misc.cpp: merge forward_outputs_are_private/_ort into one
  TEST_P(Net_ForwardOutputsArePrivate, Accuracy) over EngineType,
  guarding the ENGINE_ORT value with #ifdef HAVE_ONNXRUNTIME.
- 3rdparty/mlas/patches/0001-mlasi-opencv-threading.diff: refresh the
  stale hunk header. The second hunk's "+" line number had drifted by
  one (1677 -> 1678) because an unrelated, already-merged MinGW/GCC
  portability fix added a line earlier in mlasi.h; verified by
  reconstructing the pristine upstream file at the documented base
  commit and confirming the patch now applies with no offset/fuzz.
2026-10-14 17:42:42 +05:30
Vincent Rabaud
670368ab56 Add missing ReduceParams wasm bindings 2026-10-14 13:55:26 +02:00
sanjay
8d2e13ec1a dnn: inline the Q/K/V projection parallel_for_ lambda
Pass the lambda directly to parallel_for_ instead of binding it to a
named fn variable first, matching the other parallel_for_ call sites
in this function. Requested by abhishek-gola on #30277.
2026-10-14 16:34:18 +05:30
Pierre Chatelier
b63e0d394b Merge pull request #30169 from chacha21:tiff_compression_level_5_x
Backport #30165 to 5.x branch - #30169

Port of https://github.com/opencv/opencv/pull/30165
- [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-10-14 13:45:36 +03:00
Lukasz Jobczyk
9974684d79 Merge pull request #30274 from LukaszJobczyk/port-ocl-color-vload4-overread-5.x
imgproc: fix out-of-bounds read in OpenCL color kernels for 3-channel input 🤖🤖🤖 - #30274

YUV2RGB, RGB2YCrCb, YCrCb2RGB and the PIX_PER_WI_X != 2 path of
RGB2YUV_YV12_IYUV load each source pixel with vload4 but only use the
first three components. With SCN == 3 the load of the last pixel reads
one element past the end of the source buffer, which may result in a
GPU page fault.

Use vload3, as RGB2YUV already does, and drop the now unused
DATA_TYPE_4 macro.

The same issue is fixed in RGB2XYZ, XYZ2RGB, BGR2Lab, Lab2BGR, RGB2HSV,
HSV2RGB, RGB2HLS, HLS2RGB and RGB2RGB5x5, which load each source pixel
with vload4 but only use the first three components when SCN == 3.

Add an OpenCL cvtColor test with a contiguous 3-channel source whose
size is a multiple of 1 MiB, so the last pixel ends exactly at the end
of the buffer, covering 8U and 32F conversions and RGB2RGB5x5.

### 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-14 13:17:38 +03:00
Abhishek Gola
6dc5ff5c1f Merge pull request #30181 from abhishek-gola:onnx-conformance-fixes-5x
dnn: fix ONNX conformance failures in layers and the graph engine - #30181

Fixes wrong results found by running the ONNX backend-scoreboard conformance suite (onnx 1.23.2) against the new DNN engine. No new ops are added; these are all ops OpenCV already claims to support but computed incorrectly.

Updated ONNX coverage is: `[scoreboard] passed=1740  failed=21  skipped=272  total=2033  (85.6% passed)`

**Graph engine / importer**
- Reshape+Reshape fusion now only fires when the outer shape is known and has no `0` entries, since a `0` copies a dim from the inner Reshape's output.
- Scan slices rank-1 inputs to scalars, so scalar loop-carried state keeps rank 0.
- Rank-0 tensors read from ONNX keep rank 0 instead of becoming 1x1.
- When a model is refused, `setInput()` now reports the actual import failure (including unknown ops that throw early) instead of a misleading "missing blob" error.

**Attention**
- Softcap is applied before the bias/mask, as the spec does, so masked keys no longer leak probability.
- `qk_matmul_output_mode` 1 and 2 now return the right tensors (checked against onnxruntime; the old denylist entries blaming the reference data were wrong).
- Attention-25 `left_window_size` / `right_window_size` are supported, including together with `attn_mask`.
- A fully masked row now gives all zeros instead of a uniform distribution.

**Layers**
- GRU: `direction="reverse"` is honoured.
- LSTM reverse: `Y_h` / `Y_c` are taken from the correct time step.
- SpaceToDepth: opset-28 `mode` (CRD / DCR) is supported.
- MaxPool: `storage_order` is respected for the indices output.
- OneHot: out-of-range indices produce an all-`off_value` row instead of wrapping.
- Mod with `fmod=0`: no longer truncates through int (wrong for float, lossy for int64).
- ReduceMax / ReduceMin on an empty bool set return the correct identity.
- Swish: `alpha` is respected (CPU and OpenCL).
- Quantize/DequantizeLinear: scale and zero_point may differ in shape when they're broadcast-compatible (e.g. rank-0 scale with `[1]` zero_point).
- BitShift: signed integer types are supported.

**Tests**
- 12 conformance tests removed from the denylists, a few OpenVINO filter entries added, and new 1D layer tests for the fixes.
- Full C++ conformance passes (5376/5376); `opencv_test_dnn` has no new failures compared with 5.x.

### 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-14 12:55:00 +03:00
Abhishek Gola
94a2431d7b Merge pull request #30103 from officialarghya29/fix/dnn-matmul-rank1-a-gemm
dnn: accept a rank-1 A in the MatMul -> Gemm rewrite
2026-10-14 14:16:27 +05:30
Abhishek Gola
261e4ca04d Merge pull request #30273 from SavyaSanchi-Sharma/opti/fusion
dnn: run fused per-channel scale/shift as a vectorized loop
2026-10-14 14:11:02 +05:30
sanjay
d8baaa6e82 dnn: size the Attention output from the V width
The output has v_hidden values per token, but getMemoryShapes() sized it
from the input width, so a V wider than the input wrote past the output
buffer. Size it from v_hidden for both output ranks, and test V widths
below, equal to and above the input width.
2026-10-14 14:01:50 +05:30
Abhishek Gola
3f426d1f1b Merge pull request #30207 from abhishek-gola:core-drop-nd-suffix
drop ND prefix from the functions - #30207

Merge pull request #30207 from abhishek-gola:core-drop-nd-suffix

### 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-14 11:26:22 +03:00
Kumataro
b4b631a698 Merge pull request #30264 from Kumataro:trial/support_webp_for_bundled_libtiff_5.x
3rdparty(libtiff): expand WebP compression support for bundled libtiff(5.x) - #30264

## Overview
This pull request enables WebP compression support in the bundled `libtiff` build for OpenCV.
Previously, even when both the bundled `libtiff` and libwebp were enabled, TIFF-WebP compression was unavailable because WebP support was not hooked up in `libtiff`.

Port from https://github.com/opencv/opencv/pull/30231

### 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-14 10:48:05 +03:00
Alexander Smorkalov
c29c66d453 Merge pull request #30272 from vrabaud:empty_mat
use float32 intermediate instead of float16 for CV_8U and CV_8S
2026-10-14 10:46:06 +03:00
sanjay
d5c8ad61fe dnn: faster transformer inference on CPU; accept rank > 3 Attention input
- Attention Q/K/V projection: pack each (Q/K/V, head) weight slice with
  MLAS and run all per-head GEMMs in one multithreaded
  mlasSgemmPackedBatch() call; the fastGemm loop stays as the fallback.
- MLAS: split each operation into 4 tiles per thread on hybrid CPUs.
- forward(): hand the private output Mats to the caller instead of
  copying them again.
- Attention: accept [..., S, C] input (SAM3 decoder).
2026-10-13 20:34:55 +05:30
SavyaSanchi-Sharma
ffc9500643 added numeration in the enum 2026-10-13 17:25:15 +05:30
Abhishek Gola
a633c3cef6 Merge pull request #30197 from Prasadayus/imgproc-boxfilter-rowsum-simd-5x
imgproc: add SIMD row sum for 32F boxFilter and blur
2026-10-13 17:23:48 +05:30
SavyaSanchi-Sharma
b8cee74a35 dnn: run fused per-channel scale/shift as a vectorized loop 2026-10-13 16:06:04 +05:30
Vincent Rabaud
57c4544b70 use float32 intermediate instead of float16 for CV_8U and CV_8S
On ARM with CV_SIMD_16F, getMulFunc_, getDivFunc_, and getAddWeightedFunc_
used float16 for 8-bit integer SIMD kernels, leading to precision loss
and overflow (> 65504). Switch to float32 to match x86 and ensure precision.
2026-10-13 11:35:33 +02:00
Kumataro
f4851d70ef imgcodecs(tiff): validate codec availability
If a specified compression schema is not available,
fallback to LZW (or NONE if LZW is also unavailable).
2026-10-13 18:22:42 +09:00
Alexander Smorkalov
d654f97d8e Merge pull request #30222 from vrabaud:autobuffer
reduce TExpr::exec stack buffer size from 16 KB to 4 KB
2026-10-13 08:48:34 +03:00
varun-projects
cabbcca5c2 Merge pull request #30225 from varun-projects:fix/issue-29854-connectedcomponents-empty
imgproc: fix segfault in connectedComponents on zero-size input - #30225

`cv::connectedComponents` and `cv::connectedComponentsWithStats` crash with SIGSEGV when passed an image with a zero-length dimension (e.g., shape `(0, 400)`), instead of raising a proper error. All other OpenCV functions handle empty input gracefully.

The root cause is that the labeling algorithms dereference pointers based on image dimensions without first checking for empty input, causing a null dereference when `rows == 0` or `cols == 0`.

The fix adds `CV_Assert(!img.empty())` at the entry point of both public API functions, so callers receive a `cv::Exception` / `cv2.error` consistently with the rest of the OpenCV API (`findContours`, `cvtColor`, `inRange`, etc.).

A regression test `Imgproc_ConnectedComponents.empty_input_29854` is included, covering all three zero-dimension shapes (`{0,400}`, `{400,0}`, `{0,0}`) for both `connectedComponents` and `connectedComponentsWithStats`.

Reproducer:
```python
import numpy as np, cv2
mask = np.zeros((0, 400), dtype=np.uint8)
cv2.connectedComponentsWithStats(mask)  # was: SIGSEGV; now: cv2.error
```

Fixes #29854
2026-10-12 17:55:12 +03:00
Alexander Smorkalov
2c99f21c8c videoio: implement camera enumeration for ARAVIS backend
Extends cv::videoio_registry::enumerateDevices() (#29843) to GigE and
USB3 Vision cameras handled by Aravis. The backend already resolves a
capture index to an entry of the Aravis device list, so the same list is
reported, which keeps VideoDeviceInfo::cam_idx valid for
cv::VideoCapture(idx, CAP_ARAVIS).

Device name is composed of vendor, model and the Aravis device ID, so
cameras of the same model remain distinguishable; all three strings are
optional and the registry falls back to "cam: <index>" if none of them
is available.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-10-12 17:39:57 +03:00
Savya Sanchi Sharma
a1de5285b0 Merge pull request #29843 from SavyaSanchi-Sharma:camurate
videoio: Added camera device enumeration - #29843#29843

 **Resolves** [Issue#4269](https://github.com/opencv/opencv/issues/4269)

### 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-12 16:38:07 +03:00
Savya Sanchi Sharma
303f83ef92 Merge pull request #29729 from SavyaSanchi-Sharma:vizsplat
Added Gaussian Splat Renderer Support - #29729

Adds 3D Gaussian Splatting support to `ptcloud`: a loader for trained scenes and a `viz3d` renderer that draws them alpha-blended and depth-sorted alongside existing opaque geometry.

### Result

<img width="1842" height="811" alt="splat" src="https://github.com/user-attachments/assets/abfa5c01-6dbb-4367-b426-a618e3748649" />

[.splat source](https://huggingface.co/cakewalk/splat-data/resolve/main/train.splat)

### 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-12 16:33:54 +03:00
Savya Sanchi Sharma
7510afe588 Merge pull request #30175 from SavyaSanchi-Sharma:fix/schur-determinism
calib: make Schur complement solver deterministic - #30175

The Schur-complement LM solver's Jacobian accumulation previously summed per-image contributions into shared `U`/`ea` matrices under a mutex, so results depended on thread-scheduling order. This partitions images into a fixed number of parallel "buckets" (nparts, capped at 16), accumulates each bucket independently without locking, then reduces them serially  removing the mutex and making results bit-identical regardless of thread count.

### Benchmark: CalibrateCamera

Median of 5 runs, native 5.x vs this branch:

| Threads | 5.x median (ms) | This branch median (ms) | Change |
|---|---|---|---|
| 32 | 838.8 (777.7–855.6) | 578.4 (574.5–583.2) | 1.45× faster |
| 1 | 1233.8 (1225.8–1236.8) | 1214.6 (1213.1–1214.8) | 1.6% faster |

Single-thread time is essentially unchanged, as expected removing the mutex has no effect without contention. The gain comes from splitting the Jacobian accumulation (`U`/`ea`) into lock-free per-bucket partials instead of serializing every image's update behind one mutex, which scales much closer to linear with thread count.
### 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-12 15:59:03 +03:00
Shiven Solanki
8050ce5809 Merge pull request #30252 from sshivensolanki:fix-ocl-threshold-depths
imgproc: reject unsupported depths in OpenCL threshold - #30252

Fixes #30251

### Problem

`ocl_threshold()` does not check the input depth. On 5.x a `UMat` of depth `CV_64U`, `CV_64S` or `CV_32U` gets through, because `ocl::typeToStr()` maps those depths to valid OpenCL types and the kernel compiles. The function then indexes the 8-entry `min_vals[]` table with a depth of 10, 11 or 12, which reads past the end of the array, and skips the `depth <= CV_32S` flooring of `thresh`.

The CPU implementation rejects these depths with `StsUnsupportedFormat`, so the same call throws for a `Mat` and returns an image for a `UMat`, depending on whether an OpenCL device is available.

`CV_16BF` and `CV_Bool` did not reach the table, but failed with `Assertion failed (result) in typeToStr` instead of `StsUnsupportedFormat`.

### Fix

Return `false` from `ocl_threshold()` for every depth above `CV_64F`, before the kernel is built. Those inputs now fall through to the CPU path, which reports `StsUnsupportedFormat` as it does for `Mat` input.

The depths the OpenCL branch accepted in 4.x (`CV_8U` to `CV_64F`) behave as before.

### Tests

`Imgproc_Threshold_Unsupported_Depth.umat` is parameterized over `CV_16F`, `CV_16BF`, `CV_Bool`, `CV_64U`, `CV_64S`, `CV_32U` and `THRESH_BINARY`, `THRESH_TRUNC`. It checks that `threshold()` on `Mat` and `UMat`, and `thresholdWithMask()` on `UMat`, throw.

On current 5.x with an OpenCL device (Apple M1 Pro, OpenCL 1.2) it fails for `threshold()` on `UMat` with `CV_64U`, `CV_64S` and `CV_32U`. With this patch it passes with OpenCL enabled and with `OPENCV_OPENCL_DEVICE=disabled`. The other `threshold()` tests in `opencv_test_imgproc`, including the OpenCL ones, still pass locally (the `Imgproc_AdaptiveThreshold` tests were not run, they need `opencv_extra` 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.
- [ ] The feature is well documented and sample code can be built with the project CMake
2026-10-12 15:23:08 +03:00
Alexander Smorkalov
9a52d087d9 Merge pull request #30253 from Kumataro:tiff_remove_unused_private_enums_5.x
imgcodecs(tiff): remove unused private enums(5.x)
2026-10-12 13:57:16 +03:00
Alexander Smorkalov
a232314184 Merge pull request #30185 from asmorkalov:as/arithmetics_fix
Fix Scalars and small matrix broadcasting logic. - #30185

Replaces https://github.com/opencv/opencv/pull/30166

**non-continuous** array of the same shape and type (e.g. a column `P.col(0)` of a 4xN matrix of homogeneous 3D
points) silently treats the continuous operand as a `cv::Scalar` and broadcasts its first element:

`cc` continuous 4x1 `CV_64FC1`, `P.col(0)` same shape but non-continuous
cc = [10, 20, 30, 40] — a continuous 4x1 CV_64FC1.
It comes from P, a 4x10 CV_64F matrix filled with `P.at<double>(i,j) = 10*(i+1) + j:`
```
P = [ 10 11 12 ... 19
      20 21 22 ... 29
      30 31 32 ... 39
      40 41 42 ... 49 ]
```

### Same-shape pair

| op | src1 | src2 | Expected | 4.x (4.6) | 5.x HEAD | 5.x + PR 30185 |
|---|---|---|---|---|---|---|
| `subtract` | `cc` | `P.col(0)` | `0 0 0 0` | `0 0 0 0` | **`0 -10 -20 -30`** | `0 0 0 0` |
| `subtract` | `P.col(0)` | `cc` | `0 0 0 0` | `0 0 0 0` | **`0 10 20 30`** | `0 0 0 0` |
| `add` | `cc` | `P.col(0)` | `20 40 60 80` | `20 40 60 80` | **`20 30 40 50`** | `20 40 60 80` |
| `multiply` | `cc` | `P.col(0)` | `100 400 900 1600` | `100 400 900 1600` | **`100 200 300 400`** | `100 400 900 1600` |
| `divide` | `cc` | `P.col(0)` | `1 1 1 1` | `1 1 1 1` | **`1 0.5 0.33333 0.25`** | `1 1 1 1` |
| `absdiff` | `cc` | `P.col(0)` | `0 0 0 0` | `0 0 0 0` | **`0 10 20 30`** | `0 0 0 0` |
| `min` | `cc` | `P.col(0)` | `10 20 30 40` | `10 20 30 40` | **`10 10 10 10`** | `10 20 30 40` |
| `max` | `cc` | `P.col(0)` | `10 20 30 40` | `10 20 30 40` | `10 20 30 40` | `10 20 30 40` |
| `compare EQ` | `cc` | `P.col(0)` | `255 255 255 255` | `255 255 255 255` | **`255 0 0 0`** | `255 255 255 255` |
| `addWeighted` | `cc` | `P.col(0)` | `0 0 0 0` | `0 0 0 0` | **`THROW`** | `0 0 0 0` |
| `bitwise_xor` | `cc` | `P.col(0)` | `0 0 0 0` | `0 0 0 0` | **`0 2.2e-308 3.6e-308 7.1e-307`** | `0 0 0 0` |
| `subtract` +mask | `cc` | `P.col(0)` | `0 0 0 0` | `0 0 0 0` | **`0 -10 -20 -30`** | `0 0 0 0` |
| `operator-` | `cc` | `P.col(0)` | `0 0 0 0` | `0 0 0 0` | **`0 -10 -20 -30`** | `0 0 0 0` |

### Genuine `Scalar` partner

| op | src1 | src2 | Expected | 4.x (4.6) | 5.x HEAD | 5.x + PR 30185 |
|---|---|---|---|---|---|---|
| `subtract` | `cc` | `Scalar(5)` | `5 15 25 35` | `5 15 25 35` | **`5 20 30 40`** | `5 15 25 35` |
| `subtract` | `Scalar(5)` | `cc` | `-5 -15 -25 -35` | `-5 -15 -25 -35` | **`-5 -20 -30 -40`** | `-5 -15 -25 -35` |
| `subtract` | `cc` | `Scalar(5,6,7,8)` | `5 15 25 35` | `5 15 25 35` | **`5 14 23 32`** | `5 15 25 35` |
| `subtract` | `cc` | `Vec4d(5,6,7,8)` | `5 15 25 35` | `5 15 25 35` | **`5 14 23 32`** | `5 15 25 35` |
| `add` | `cc` | `Scalar(5)` | `15 25 35 45` | `15 25 35 45` | **`15 20 30 40`** | `15 25 35 45` |
| `multiply` | `cc` | `Scalar(2)` | `20 40 60 80` | `20 40 60 80` | **`20 0 0 0`** | `20 40 60 80` |
| `divide` | `cc` | `Scalar(2)` | `5 10 15 20` | `5 10 15 20` | **`5 inf inf inf`** | `5 10 15 20` |
| `max` | `cc` | `Scalar(25)` | `25 25 30 40` | `25 25 30 40` | **`25 20 30 40`** | `25 25 30 40` |
| `compare GT` | `cc` | `Scalar(25)` | `0 0 255 255` | `0 0 255 255` | **`0 255 255 255`** | `0 0 255 255` |
| `operator-` | `cc` | `Scalar(5)` | `5 15 25 35` | `5 15 25 35` | **`5 20 30 40`** | `5 15 25 35` |
| `subtract` | `cc` | `Scalar::all(5)` | `5 15 25 35` | `5 15 25 35` | `5 15 25 35` | `5 15 25 35` |
| `subtract` | `cc` | `Vec<double,1>(5)` | `5 15 25 35` | `5 15 25 35` | `5 15 25 35` | `5 15 25 35` |
| `subtract` | `UMat cc` | `Scalar(5)` | `5 15 25 35` | `5 15 25 35` | `5 15 25 35` | `5 15 25 35` |

### 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-12 13:38:25 +03:00
Kumataro
14a8c3165e imgcodecs(tiff): remove unused private enums 2026-10-12 18:34:33 +09:00
Abhishek Gola
25beda402a Merge pull request #30157 from abhishek-gola:core-reduce-nd
core: reduceND, used by the DNN Reduce2 layer - #30157

Split out of #30082, which now carries only the resize half.

Adds `cv::reduceND`, which reduces an n-dimensional array over a set of axes with any of the `ReduceTypes`, extended with `REDUCE_PROD`, `REDUCE_L1`, `REDUCE_L2`, `REDUCE_LOG_SUM` and `REDUCE_LOG_SUM_EXP`. `cv::reduce` accepts n-dimensional input through it.

`sum`, `mean` and `minMaxIdx` now share one parallel driver (`stat_parallel.hpp`), so they parallelize over large arrays the same way `reduceND` does.

The new graph engine's `Reduce2` layer calls `cv::reduceND` instead of its own kernels, so `reduce2_kernels.simd.hpp` and the hand-written reduction loops in `reduce2_layer.cpp` go away.

### 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-12 12:08:20 +03:00
Alexander Smorkalov
1aab5099d2 Merge pull request #30188 from pratham-mcw:imgproc-pyrup-vec
imgproc: vectorize pyrUp horizontal pass via PyrUpVecH (cn 1/4)
2026-10-12 12:05:14 +03:00
Abhishek Gola
3388290736 Merge pull request #30202 from sergiud/fix/fisheye-point-layout
calib: fix fisheye calibration for column-shaped points
2026-10-12 13:56:09 +05:30
Abhishek Gola
04b8d499e4 Merge pull request #30201 from uwezkhan/onnx-resize-input-bound
dnn: bound the scales input index in onnx parseResize2 🤖🤖🤖
2026-10-12 13:49:53 +05:30
Abhishek Gola
0054f3aa7e Merge pull request #30159 from pranayr710/fix/norm-l1-32s
core: fix cv::norm(CV_32S, NORM_L1) returning negative at INT_MIN and losing precision above 2^24
2026-10-12 13:27:56 +05:30
Varun Jaiswal
fb00e3875f Merge pull request #30208 from varun-jaiswal17:calib-document-fix
calib document fix - #30208

Documentation changes - three doxygen blocks in `modules/objdetect`.

- **`findChessboardCorners`** (PR#22083): whether the returned order pins down a unique
  physical corner depends on the **parity** of the two `patternSize` dimensions, not on
  whether they differ. Quads are built from the dark squares only (`calibinit.cpp:755`
  `THRESH_BINARY`, `:796` white frame, `:1919` holes-only), so a rotation is admissible
  only if it maps dark squares onto dark squares. For `patternSize` of w x h interior
  corners the squares form a (w+1) x (h+1) grid, so 180° preserves the colouring exactly
  when w and h share parity:

  | `patternSize`                  | distinct origins | ambiguity     |
  |--------------------------------|------------------|---------------|
  | different parity (9x6, 8x5)    | 1                | none          |
  | same parity, w != h (8x6, 7x5) | 2                | 180°          |
  | w == h (7x7, 8x8)              | 4                | 90°           |

  The square case is not colour: the transpose at `calibinit.cpp:1745` is a no-op when
  `width == pattern_size.width`, so the detector cannot tell rows from columns. Verified
  over 24 in-plane rotations and 60 perspective views per board, zero detection failures;
  inverting the square colouring moves the origin but not the count.

  Practical consequence is the reverse of what was documented: the common 9x6 board is
  unambiguous, while this docstring's own sample `Size patternsize(8,6)` is not. The note
  now recommends a board whose dimensions differ in parity first, then
  #findChessboardCornersSB + `CALIB_CB_MARKER`, then ChArUco. Still harmless for
  intrinsics (each view absorbs the rotation into its own pose); still breaks hand-eye.

- **`findCirclesGrid`** (PR#7312): the returned points are the keypoint locations reported
  by `blobDetector` as-is, without refinement - the parameter is a `FeatureDetector` and
  `SimpleBlobDetector` is only the default, so the points are not necessarily moment
  centroids. Under perspective the apparent centre of a projected circle can be displaced
  from the projection of the physical centre; the displacement vanishes when the board is
  parallel to the image plane and is not removed by fitting an ellipse. Points at the
  `blobDetector = NULL` path for supplying corrected centres. Describes the bias
  qualitatively rather than quoting a fixed estimate.

- **`setLegacyPattern` / `detectBoard`** (PR#23152, PR#29636): the flag is a no-op on
  odd-row boards, and a wrong setting fails silently - markers detected, zero corners,
  only a `CV_LOG_DEBUG` line; notes that calib.io boards use the legacy layout and aligns
  the 4.6.0 version wording across both headers.


### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
2026-10-12 10:25:33 +03:00
Alexander Smorkalov
31d0b67649 Merge pull request #30232 from vrabaud:pop_back
core: decrement size directly in AutoBuffer::pop_back()
2026-10-12 09:27:13 +03:00
Vincent Rabaud
282e14732f allow empty array with scalar operand in arithm_op
Previously, arithm_op returned an empty output when one operand was an
empty Mat and the other was a Scalar.
The new element-wise engine asserted `src1.empty() == src2.empty()` before
checking `isScalarArg`, causing calls such as `cv::max(empty_mat, 1.0, dst)`
or `cv::add(empty_mat, Scalar(1), dst)` to fail with an assertion error.
2026-10-11 22:13:22 +02:00
Vincent Rabaud
30a7014ecc core: decrement size directly in AutoBuffer::pop_back()
Calling resize(size() - 1) in pop_back() pulls in the buffer growth path
for the unreachable sz == 0 case in release builds (where size() - 1
underflows to SIZE_MAX), which both bloats codegen and triggers an LLVM
ScalarEvolution assertion on 32-bit Hexagon Clang. Guard and decrement
sz directly instead.
2026-10-11 10:36:48 +02:00
pranayr710
7843afa92e core: fix the masked CV_32S L1 norm for INT_MIN
Rebasing onto 5.x picked up facc3fdc7d, which vectorized the masked norm for the remaining depths,
and Core_NormL1_Signed then failed on CI for masked CV_32S at INT_MIN - 13 jobs, every platform.

The new kernel takes the magnitude before widening:

    v_int32 s = v_reinterpret_as_s32(v_and(v_abs(vx_load(src + i)), v_normmask_u32(mask + i)));
    acc0 = v_add(acc0, v_cvt_f64(s));

v_abs() does give |INT_MIN| correctly, as an unsigned 2147483648, but reinterpreting that back as
int32 turns it negative again and the widening carries the sign into the accumulator, so the norm
came out as -16 * 2^31 for 16 elements. Mask the value instead, widen to double - exact for every
int32 - and take the magnitude there, which is what the unmasked path already does.

The 8- and 16-bit masked kernels are not affected: v_abs() returns the unsigned type there too, and
they accumulate in unsigned without reinterpreting back to signed.
2026-10-10 23:40:36 +05:30
pranayr710
03160275da core: report out-of-range cases as skipped, and test cv_abs() directly
- The CV_32S instantiation covers values outside the int32 range, which only apply to CV_64S.
  Those now throw SkipTestException so they are reported as skipped rather than silently passing.

- Core_CvAbs checks cv_abs() at the lowest value of each signed type, where the magnitude is not
  representable in that type. The norm test only reaches cv_abs() indirectly, so a direct one makes
  the contract explicit and fails for an obvious reason if it regresses.
2026-10-10 19:55:25 +05:30
pranayr710
70dc2027b9 core: address review - fix cv_abs(int64) too, and tighten the test
- cv_abs(int64) had the same std::abs UB at INT64_MIN that cv_abs(int) had, so
  cv::norm(CV_64S, NORM_L1) still returned a negative value - at every length, masked and unmasked.
  Verified that before changing it. Same fix: negate in the unsigned type.

- Core_NormL1_32S becomes Core_NormL1_Signed and covers CV_64S alongside CV_32S, so both signed
  integer depths are held to the same rule.

- EXPECT_DOUBLE_EQ -> EXPECT_EQ, since the test does claim exact equality: every value used is
  below 2^53 in magnitude and so is its total.

- Shortened the comments in the test and in norm.simd.hpp to describe what the code must do rather
  than retell the defects.
2026-10-10 19:55:25 +05:30
pranayr710
3a0c43a19d core: fix cv::norm(CV_32S, NORM_L1) returning negative and losing precision
Two independent defects, both visible from the same observation: an L1 norm is a sum of
magnitudes, so it can never be negative and can never depend on how many elements sit beside a
given one. cv::norm() on CV_32S broke both rules.

1. Negative result at INT_MIN. cv_abs(int) is (unsigned)std::abs(x), and std::abs(INT_MIN) is
   undefined - its result is not representable in int. In optimized builds the contribution came
   out negative, so

       cv::norm(Mat(1, 1, CV_32S, Scalar(INT_MIN)), NORM_L1)  ==  -2147483648

   With a mask this is wrong at every length, since the masked path is scalar throughout.
   Fixed at the source by negating in unsigned, where INT_MIN's magnitude is an ordinary value.
   Behaviour is unchanged for every other input, and the UB is gone for all other callers too.

2. Precision loss above 2^24 in the vector body. NormL1_SIMD<int, double> widened int32 to float
   before accumulating into double, and float cannot represent every int32, so values above 2^24
   were rounded first:

       127 elements of INT_MAX  ->  272730423281, exact answer 272730423169

   Only the vector body was affected, so the error appeared once the array was long enough to
   enter it - the same answer was correct at length 8 and wrong at length 16. Widen straight to
   double instead and take the magnitude there; this is exact over the whole int32 range,
   INT_MIN included, and is the same conversion the NEON backend already documents as the
   correct replacement for an f32 round-trip.

NORM_INF and NORM_L2 on CV_32S were already correct and are untouched: NORM_INF accumulates in
unsigned, and NORM_L2 uses v_dotprod_expand_fast, which stays in integers.

Core_NormL1_32S covers both defects over masked and unmasked input, asserting non-negativity as
well as the exact value, at lengths straddling the vector width.
2026-10-10 19:55:25 +05:30