Commit Graph

27756 Commits

Author SHA1 Message Date
Abhishek Gola
e45cf0217a tests: reduce iterations, input sizes and perf grids of slow tests (#30844)
This cuts the runtime of slow accuracy and perf tests by giving them less work on the same code paths: fewer iterations, smaller inputs, and fewer perf parameter combinations that measure the same thing. The table lists every change and why the code path the test was written for is still exercised; most changes also carry a short comment in the code.
2026-11-25 17:05:19 +05:30
Abhishek Gola
72d9ae750b Merge pull request #30807 from lazerg/fix/issue-30790-solvecubic-double-root-5.x
core: fix solveCubic missing double roots after coefficient normalization (5.x)
2026-11-25 16:18:41 +05:30
Abhishek Gola
6767539300 features: check DNN output shapes in DISK, ALIKED and LightGlue (#31114)
DISK, ALIKED and the two LightGlueMatcher variants read the ONNX network outputs through raw pointers and Mat::at<> with the layout of the reference exports, but never check the shape or element type that the loaded model actually returned. Any model passed to DISK::create, ALIKED::create or LightGlueMatcher::create (file or buffer) reaches this code:

DISK::detectAndCompute reads kptsData[i * 2 + 1] for every row of keypoints without checking it has 2 columns.
ALIKEDImpl::runNetwork reads at<float>(i, 1) on keypoints and at<float>(i, 0) on scores without checking 2 columns or the float type.
ALIKEDLightGlueMatcherImpl::lightglueMatch reads at<int64_t>(i, 1) on matches0 and at<float>(i) on mscores0 for every match row without checking 2 columns, the int64 type or one score per match.
DISKLightGlueMatcherImpl::lightglueMatch already checks the element counts but reads at<int64_t>(i) on matches0 without checking the int64 type.
2026-11-25 16:10:43 +05:30
RITU BASKEY
9f79aeba07 calib: handle three-channel column object points in calibrateMultiview (#30937)
* calib: handle three-channel column object points

* calib: simplify layout test and document object points

* calib: fix fisheye reprojection errors for object point layouts
2026-11-25 16:09:28 +05:30
Abhishek Gola
5051f0ecb6 core: fix NORM_L2 overflow for CV_16S and CV_32S at the type minimum (#31144)
The SIMD kernels of cv::norm(src, NORM_L2/NORM_L2SQR) for CV_16S and CV_32S
sum adjacent squares in a type that is too narrow for the most negative value:

- CV_16S: the int16 dot product accumulates pairs in int32, and
  (-32768)^2 + (-32768)^2 = 2^31 wraps to INT_MIN.
- CV_32S: the int32 dot product accumulates pairs in int64, and
  INT_MIN^2 + INT_MIN^2 = 2^63 wraps to INT64_MIN.

As a result NORM_L2SQR could return a negative value and NORM_L2 NaN, but
only for inputs long enough to reach the vector loop. Masked norm and
norm(src1, src2) were not affected.

Widen the int16 pairwise sums as unsigned (they always fit into uint32) and
square int32 values in double. Performance is unchanged.
2026-11-25 15:58:47 +05:30
Shiven Solanki
34e51a4bf4 Merge pull request #30558 from sshivensolanki/fix-dot-new-depths
Fix
New kernels in matmul.simd.hpp, called through CV_CPU_DISPATCH like dotProd_64f:

CV_32U, CV_64U, CV_64S: thin wrappers around dotProd_ (each element converted to double, accumulated in double).
CV_16F, CV_16BF: vx_load_expand widens each value to float32, and v_muladd adds the products in float32 with two independent accumulators, in blocks of 8192 like dotProd_32f. Each block's sum is added to a double.
CV_8F_E4M3FN, CV_8F_E4M3FNUZ: decoded through decodeLUT() with v_lut, as in cvtFp8ToF32, then multiplied and added in float32 in the same 8192-element blocks.
CV_Bool gets its own kernel: any non-zero byte is true, so it counts the positions where both bytes are non-zero, using v_ne / v_and on v_uint8 with two byte counters in blocks of 255 * vlanes.
ocl_dot() returns false for the 5.x depths, so UMat::dot uses the CPU kernels instead of trying to compile an OpenCL kernel with an unsupported accumulator type.
The Mat::dot documentation now describes the CV_Bool result and the float32 accumulation of CV_16F, CV_16BF and fp8.
The 16F, 16BF and fp8 kernels only need CV_SIMD, not CV_SIMD_64F, so they also use the vector path on platforms without double-precision SIMD.

On a 1024×1024 matrix (Apple M1 Pro, NEON), Mat::dot takes 0.159 ms for CV_16F / CV_16BF and 0.363 ms for the fp8 depths, compared with 0.25 ms and 1.43 ms for the scalar dotProd_ loop.
2026-11-25 15:56:47 +05:30
Abhishek Gola
0654e71376 ptcloud: validate input size, setters, and ROI continuity in RgbdNormals (#30934)
- Check points3d_ori.rows == rows and points3d_ori.cols == cols (plus
  non-empty valid row step) in RgbdNormalsImpl::apply() before cache()
  and output creation so mismatched inputs throw without touching
  preallocated output buffers.
- Validate positive dimensions in setRows() and setCols() (and >= 2 for
  SRI in create(), setRows(), setCols(), and cache() to prevent the
  cols/2 - 1 underflow and zero-denominator division on 1xN / Nx1 grids).
- Stage non-packed (ROI / padded-step) outputs and overlapping
  CrossProduct buffers through a continuous temporary in apply() and
  copy back into the caller's OutputArray, normalizing 1-D or transposed
  OutputArray wrappers via reshape(0, rows) while preserving buffer
  aliasing.
- Clone non-packed or overlapping 1-channel depth inputs for LINEMOD
  (whose computeImpl() steps rows by cols), skip the inner loop early
  when cols <= 2 * r + 1, and widen pixel-count multiplications to
  size_t in FALS and SRI.
- Add parameterized NormalsInputSize tests covering mismatched sizes,
  setter validation, 1-D wrappers, overlapping/in-place buffers, cross-
  depth 4-channel ROIs, non-continuous Mat/UMat/padded-step outputs, and
  LINEMOD 1-channel depth ROIs across CV_16U, CV_32F, and CV_64F.
2026-11-25 15:54:32 +05:30
Shiven Solanki
4fe077ab3e Merge pull request #31142 from sshivensolanki:dnn-dft-opset20-axis
dnn: use the opset 20 default axis -2 for ONNX DFT - #31142

Fixes #31141

### Problem
Opset 20 made the `DFT` axis an optional input with default `-2`, but the importer leaves the layer on its opset 17 default `axis = 1`. So opset 20 `DFT` without an axis input transforms the wrong dim for 4-D and larger inputs.

### Fix
In `parseDFT`, set `axis = -2` when the model's opset is 20 or newer and no `axis` attribute is present (same pattern as `parseRoiAlign`).

### Tests
Added `Test_ONNX_layers.DFT_opset20_default_axis` to `test_onnx_importer.cpp`, using a `[1, 3, 4, 2]` model from opencv_extra. It fails without the fix and passes with it. The full `opencv_test_dnn` passes (9540 tests) on macOS arm64.

### 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-11-25 12:34:14 +03:00
Savya Sanchi Sharma
c97ebe2b55 core: add ROCm 10 support and HIP backend plugin for the non-CPU HAL (#30925)
Adds the AMD/ROCm half:

ROCm detection, separate from HIP. ROCm 10.0 ships HIP 7.15, and HIP's major
version is 7 on both ROCm 7 and ROCm 10, so hip_VERSION cannot identify the
platform. Detection probes rocm-core, then the legacy version file, then
ROCm 10's core-<major>.<minor> directory.
GPU architecture selection via amdgpu-arch / rocm_agent_enumerator,
falling back to family-wide generic targets.
A standalone HIP backend plugin (hal/accel/hip/), loaded on first use.
No OpenCV module compiles HIP, and the main build does not depend on ROCm.
Implemented kernels: flip, transpose, setTo, and convertTo.
2026-11-25 14:23:05 +05:30
Alexander Smorkalov
e8d7aa4a2f Merge pull request #31131 from sshivensolanki:dnn-einsum-uppercase-letters
dnn: fix Einsum index for uppercase subscript letters
2026-11-25 11:12:59 +03:00
Abhishek Gola
5a7c72eba5 geometry: restore HuMoments accuracy coverage (#30465) 2026-11-25 13:00:47 +05:30
shivensolanki
683d4a5bb1 core: fix NORM_L2 overflow for CV_16S and CV_32S at the type minimum
The SIMD kernels of cv::norm(src, NORM_L2/NORM_L2SQR) for CV_16S and CV_32S
sum adjacent squares in a type that is too narrow for the most negative value:

- CV_16S: the int16 dot product accumulates pairs in int32, and
  (-32768)^2 + (-32768)^2 = 2^31 wraps to INT_MIN.
- CV_32S: the int32 dot product accumulates pairs in int64, and
  INT_MIN^2 + INT_MIN^2 = 2^63 wraps to INT64_MIN.

As a result NORM_L2SQR could return a negative value and NORM_L2 NaN, but
only for inputs long enough to reach the vector loop. Masked norm and
norm(src1, src2) were not affected.

Widen the int16 pairwise sums as unsigned (they always fit into uint32) and
square int32 values in double. Performance is unchanged.
2026-11-25 14:58:32 +08:00
Alexander Smorkalov
b8d77c769a Merge pull request #31120 from sshivensolanki/dnn-det-empty-matrix
dnn: fix Det output for 0x0 matrices
2026-11-25 09:17:41 +03:00
Abhishek Gola
6fd640eca1 Merge pull request #31132 from Prasadayus/fix/reduce-false-sharing-5x
core: give cv::reduce rows a per-call accumulator to stop false sharing
2026-11-25 09:16:38 +05:30
Uwez Khan
354b4b38c9 features: check DNN output shapes in DISK, ALIKED and LightGlue 2026-11-24 23:51:30 +05:30
pctablet505
bf830d892d ptcloud: validate input size, setters, and ROI continuity in RgbdNormals
- Check points3d_ori.rows == rows and points3d_ori.cols == cols (plus
  non-empty valid row step) in RgbdNormalsImpl::apply() before cache()
  and output creation so mismatched inputs throw without touching
  preallocated output buffers.
- Validate positive dimensions in setRows() and setCols() (and >= 2 for
  SRI in create(), setRows(), setCols(), and cache() to prevent the
  cols/2 - 1 underflow and zero-denominator division on 1xN / Nx1 grids).
- Stage non-packed (ROI / padded-step) outputs and overlapping
  CrossProduct buffers through a continuous temporary in apply() and
  copy back into the caller's OutputArray, normalizing 1-D or transposed
  OutputArray wrappers via reshape(0, rows) while preserving buffer
  aliasing.
- Clone non-packed or overlapping 1-channel depth inputs for LINEMOD
  (whose computeImpl() steps rows by cols), skip the inner loop early
  when cols <= 2 * r + 1, and widen pixel-count multiplications to
  size_t in FALS and SRI.
- Add parameterized NormalsInputSize tests covering mismatched sizes,
  setter validation, 1-D wrappers, overlapping/in-place buffers, cross-
  depth 4-channel ROIs, non-continuous Mat/UMat/padded-step outputs, and
  LINEMOD 1-channel depth ROIs across CV_16U, CV_32F, and CV_64F.
2026-11-24 21:01:25 +05:30
Alexander Smorkalov
d1abca9a89 Merge pull request #31123 from sshivensolanki:dnn-maxunpool-kernel-hw
dnn: fix MaxUnpool kernel and stride order in the ONNX importer
2026-11-24 18:08:21 +03:00
Prasadayus
663d7c1a8d core: give cv::reduce rows a per-call accumulator to stop false sharing 2026-11-24 19:49:56 +05:30
uwezkhan
7b07609d66 dnn: reject negative position ids in RotaryEmbedding gather 🤖🤖🤖 (#30511)
* dnn: reject negative position ids in RotaryEmbedding gather

* dnn: check RotaryEmbedding cache width, rotary dim and position_ids shape/type

* dnn: check RotaryEmbedding input types in getTypes, exact cache width and 4d num_heads
2026-11-24 19:22:42 +05:30
uwezkhan
06f7ecb5ce ptcloud: bound triangle vertex indices in triangleRasterize 🤖🤖🤖 (#30640)
* ptcloud: bound triangle vertex indices in triangleRasterize

* ptcloud: use checkRange for the triangle index check
2026-11-24 19:11:50 +05:30
Shiven Solanki
3e3f338dde Merge pull request #31061 from sshivensolanki/dnn-trilu-tall-matrix
dnn: fix Trilu for inputs with more rows than columns

Problem
Trilu only loops over the first min(h, w) rows, so when the input has more rows than columns, the remaining rows keep their input values instead of being masked.

Fix
Loop over all h rows in forward() and remove the unused m. The existing cmin < w && num_zeros > 0 check already keeps the memset inside each row, so no other change is needed.
2026-11-24 18:50:41 +05:30
Shiven Solanki
45fed1fec6 dnn: fix Einsum index for uppercase subscript letters 2026-11-24 20:54:28 +08:00
Abhishek Gola
60aeb36381 docs(imgproc): describe contour approximation modes (#31118)
* docs(imgproc): describe contour approximation modes

* docs(imgproc): clarify LINK_RUNS behavior
2026-11-24 18:17:05 +05:30
abhishek-gola
0cfdeb800f tests: reduce iterations, input sizes and perf grids of slow tests
Signed-off-by: abhishek-gola <abhishek@opencv.org>
2026-11-24 16:43:10 +05:30
Shiven Solanki
f9efe61f9a dnn: fix MaxUnpool kernel and stride order in the ONNX importer 2026-11-24 18:17:54 +08:00
Abhishek Gola
8a1083b85a Merge pull request #30938 from abhishek-gola/tests/faster-test-infra-5x
tests: speed up reference implementations and avoid repeated work in slow tests
2026-11-24 15:47:17 +05:30
Shiven laharjai
9cffded4c4 docs(imgproc): clarify LINK_RUNS behavior 2026-11-24 15:47:06 +05:30
abhishek-gola
28d85a1fb0 tests: speed up reference implementations and avoid repeated work in slow tests
Signed-off-by: abhishek-gola <abhishek@opencv.org>
2026-11-24 15:46:07 +05:30
Shiven Solanki
e8bc3f0c9c doc(imgproc): fix supported depths for integral and thresholdWithMask (#30978)
* doc(imgproc): fix supported depths for integral and thresholdWithMask

* doc(imgproc): note extra integral depth combinations on the OpenCL path
2026-11-24 15:33:37 +05:30
Shiven Solanki
5dcb95b793 dnn: fix Det output for 0x0 matrices 2026-11-24 17:44:57 +08:00
Shiven laharjai
9c2cba82d7 docs(imgproc): describe contour approximation modes 2026-11-24 14:50:34 +05:30
Laiba Irfan
3351889ecd dnn: support allowzero attribute in ONNX Reshape (#30854)
* dnn: support allowzero attribute in ONNX Reshape

* dnn: skip reshape allowzero test for OpenVINO, specify opset range

* dnn: add Reshape2 allowzero tests for 2D legacy and block-layout paths
2026-11-24 13:41:12 +05:30
Rahul Kumar
7a3dd65ae1 dnn: fix com.microsoft Attention with a mask_index or without a bias, and Add(mask, scores) fusion 🤖🤖🤖 (#30930)
* dnn: fix masked Attention ONNX import and commutative mask-Add fusion

ONNXImporter2::parseAttention required every input after X to be constant before populating params.blobs, leaving blobs empty for dynamic masks, pushing constant masks into blobs[2], and failing on omitted or trailing empty optional inputs. AttentionLayerImpl also read bias from blobs.back() instead of blobs[1], and ModelFusionAttention::isMaskAdd hardcoded inputs[1] so Add(mask, scores) bound Attention's mask to the removed score node. Fold constant weight and bias into blobs[0..1], keep any 4th mask input on layer->inputs[1], and match score_arg in isMaskAdd.

* dnn(onnx): lower the Attention int32 mask_index with addKeyPaddingMaskBias

mask_index is an int32 0/1 padding mask, not an additive bias. Turn it
into the additive mask the layer applies, the same way
parseMultiHeadAttention does, saving and restoring node_inputs and
node_outputs around the helper.

The test loads its models from opencv_extra (same branch name) with
testONNXModels() instead of building them and the reference in code;
the first three cases now use the spec's int32 [B, S] mask.

* dnn: keep AttentionLayerImpl's blob access as on 5.x

parseAttention now always gives the layer exactly two blobs, the weight
and the bias, and the fusion passes do the same, so blobs.front() and
blobs.back() already pick them. The blobs[0]/blobs[1] change is not
needed.
2026-11-24 13:38:53 +05:30
Shiven Solanki
9c6d1ababb dnn: return an empty shape in Shape when start > end (#31011)
* dnn: return an empty shape in Shape when start > end

* dnn: apply the Shape start > end rule to the CUDA backend

* dnn: skip test_shape_start_greater_than_end in the OpenVINO filter

Problem
ShapeLayerImpl::getShapeRange asserts start_ <= end_, so Shape with start > end throws. The ONNX spec says the result should be an empty shape.

Fix
After clamping, set end_ = std::max(end_, start_) so the range has length 0. This
2026-11-24 13:36:58 +05:30
Vladimir Iglovikov
ebf8a55d6c core: support CV_16F in the legacy reduce overload 🤖🤖🤖 (#31032)
* core: support CV_16F in the legacy reduce overload

Delegate half-precision CPU input to the existing N-D reduction kernels.
Preserve the 2-D result for a one-dimensional legacy input.

* core: use CV_CheckEQ for the 1D dim check in CV_16F reduce

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-24 13:30:49 +05:30
Shiven Solanki
5014b24db5 dnn: keep CV_64S precision in Resize2 nearest mode (#31036)
* dnn: keep CV_64S precision in Resize2 nearest mode

Fixes #31035

* dnn: use ptr<>() in Resize2 int64 test to fix Debug assert on 4D Mat
2026-11-24 13:04:50 +05:30
Alexander Smorkalov
ed4ee4d5b2 Merge pull request #31097 from sshivensolanki:dnn-cumsum-empty-axis
dnn: fix CumSum crash when the scan axis has length 0
2026-11-24 10:02:45 +03:00
Abhishek Gola
1056624e1c dnn: fix CumProd crash when the scan axis has length 0 (#31063)
* dnn: fix CumProd crash when the scan axis has length 0

* dnn: use Mat::empty() for the CumProd empty-input check

Return early from forwardImpl() when the input has no elements. The output already has the right empty shape. The check comes after normalize_axis(), so an out-of-range axis is still reported.
2026-11-24 10:45:03 +05:30
Madan mohan Manokar
19f86d566c Merge pull request #30974 from amd/port_5.x_opencl_boxfilter
imgproc: Port 4.x enable boxFilter OpenCL fast paths on all aligned GPUs (5.x)

This PR only removes the Intel vendor gate as a port of upstream OpenCV PR #29805.

No changes are made to the underlying OpenCL kernels or dispatch logic.
Regression is observed on Apple M5 when filterSmall is used, including cases up to about 3.5× slower at odd, large sizes.
Earlier benchmark data in imgproc: Enable boxFilter OpenCL fast paths on Non-Intel GPUs. #29805 showed gains on AMD and NVIDIA GPUs for the small-kernel cases.
The filterSmall gate is therefore extended from Intel to AMD and NVIDIA. Apple and other vendors stay on the general kernel.
Any potential kernel correctness, ROI, aliasing, boundary handling, or in-place processing issues are pre-existing implementation concerns and should be evaluated separately in follow-up PRs. Such issues are outside the scope of this change.
2026-11-24 10:14:09 +05:30
Abhishek Gola
eb30136494 Merge pull request #30924 from pctablet505/fix-dnn-cuda-gemm-square-transpose-5x
dnn: avoid transposing square Gemm weights in-place in initCUDA (5.x) 🤖🤖🤖
2026-11-24 09:44:47 +05:30
Abhishek Gola
5eb67caa6b Merge pull request #31093 from vinaykumar11-maker/fix-empty-case-msvc
dnn(test): remove empty CASE() entry that breaks MSVC build with OpenVINO
2026-11-24 09:37:45 +05:30
Abhishek Gola
f15f296e1b Merge pull request #31023 from v-hogood/fix-lightglue-swift-name
features(objc): fix conflicting Swift name for LightGlueMatcher.create
2026-11-24 09:24:07 +05:30
Karnajeet Gosavi
c309fe76d4 Merge pull request #31029 from kg290/codex/ffmpeg-frame-size-warning
videoio: Report expected and actual FFmpeg frame sizes
2026-11-24 09:22:10 +05:30
Shiven Solanki
150a25256c dnn: fix CumSum crash when the scan axis has length 0 2026-11-23 22:25:12 +08:00
vinay kumar
958be87d74 dnn(test): remove empty CASE() entry that breaks MSVC build with OpenVINO 2026-11-23 18:14:55 +05:30
Shiven Solanki
9637fe1290 Merge pull request #30999 from sshivensolanki:core-mean-bool
core: support CV_Bool input in mean and meanStdDev - #30999

Fixes #30998

### Problem

`cv::mean` and `cv::meanStdDev` fail with `func != 0` on a `CV_Bool` source, because there is no `CV_Bool` sum kernel. `cv::sum` and `cv::norm` already handle `CV_Bool`.

### Fix

For a `CV_Bool` source, compute the result from `countNonZero` and `total()` instead of the sum kernels: mean = nz/n, and stddev = sqrt(p*(1-p)) with p = nz/n. A mask, or more than one channel, reports `StsNotImplemented`.

### Tests

Added `Core_MeanStdDev.bool_input`: a 1-channel `CV_Bool` source (including a raw `255` byte) must give mean 0.5 and stddev 0.5, and both functions must throw when a mask is given. It fails on the current code with the assert and passes with the fix. The full `opencv_test_core` run passes.

### 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-11-23 15:01:58 +03:00
Shiven Solanki
7f57e38b02 dnn: use Mat::empty() for the CumProd empty-input check 2026-11-23 18:58:12 +08:00
Virat Pratap
79ae232914 docs(imgproc): fix math rendering in color formula
Clarify the max operator and group ChannelRange as one identifier. Addresses #31077.
2026-11-23 08:55:17 +00:00
Abhishek Gola
fb6166e54b Merge pull request #31044 from harshil-sri/fix-0d-threshold-lut
core, imgproc: support 0D Mat in LUT and threshold

Give a 0D input a 1x1 header before the row-based code runs, the same way #30704 normalizes 1D inputs in gemm:

threshold / thresholdWithMask: src (and mask) are viewed as 1x1, so the output is 1x1, the same as the other imgproc functions return for 0D input.
LUT: src and dst get 1x1 headers for the HAL and parallel paths. dst is created with createSameSize, so the result itself stays 0D.
2026-11-23 09:27:52 +05:30
Abhishek Gola
d2c6f944cf Merge pull request #31034 from sshivensolanki/dnn-cast-uint32-uint64
dnn: support UINT32 and UINT64 targets in Cast

Map ONNX UINT32 (12) and UINT64 (13) to CV_32U and CV_64U in mapToCvDepth.
Add CV_32U and CV_64U cases to truncateFloatToInt, so float inputs truncate toward zero as ONNX requires, instead of being rounded by convertTo.
Allow CV_32U and CV_64U in the outputType parameter.
2026-11-23 09:27:12 +05:30