Commit Graph

6312 Commits

Author SHA1 Message Date
pranjal9091
2868492769 core: forbid trace and setIdentity for non-2D matrices (#30785)
* core: support 1D Mat in trace and setIdentity for non-float types

In OpenCV 5.x, 1D Mat support was introduced and cv::trace and
cv::setIdentity were updated with CV_Assert(m.dims <= 2). However,
both functions previously relied on m.diag() as the general fallback
path for non-float types (e.g. integer and multi-channel types).
Since Mat::diag strictly asserts dims == 2, calling cv::trace or
cv::setIdentity on a 1D non-float Mat resulted in an assertion failure
in Mat::diag.

Fix this by using m.col(0) when m.dims <= 1 (mirroring the behavior of
1xN 2D matrices), and gracefully handling empty matrices. Also add unit
tests covering 1D Mat across integral, floating point, and multi-channel
types for both cv::trace and cv::setIdentity.

* core: handle 0-D Mat in trace and setIdentity for non-float types

Properly handle 0-D matrices (scalars) in cv::trace using cv::sum(m)
and in cv::setIdentity using m = s without invoking m.col(0).
Also add unit tests for 0-D Mat covering integral, floating-point,
and multi-channel types.

* core: forbid trace and setIdentity for non-2D matrices
2026-11-26 18:00:46 +05:30
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
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
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
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
Prasadayus
663d7c1a8d core: give cv::reduce rows a per-call accumulator to stop false sharing 2026-11-24 19:49:56 +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
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
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
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
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
Harshil
942aa1aabb core, imgproc: support 0D Mat in LUT and threshold 2026-11-22 02:28:24 +05:30
Abhishek Gola
fc79cd24c2 Merge pull request #30990 from pranayr710/fix/compare-cv-bool
core: add the missing CV_Bool kernel to cv::compare

The fix is not simply reusing the uchar kernel. A CV_Bool byte is not guaranteed to be 0 or 1:
Mat wrapping an external buffer performs no conversion, so other values are reachable through
the public API, and comparing the raw bytes would order 2 above 1 when both mean true.
2026-11-21 09:19:22 +05:30
Abhishek Gola
22db6f41b9 Merge pull request #30398 from abhishek-gola/non-cpu-hal
core: non-CPU HAL (cv::accel) with a CUDA backend

What this PR adds: cv::accel, a non-CPU HAL in core, kept to a minimal first version.

Explicit placement: UMat::createOn(device, shape, type), Mat::upload(device) and UMat::upload(device). Mat::upload() returns once the Mat has been read; UMat::upload() returns the same UMat when it is already on that device.
Functions with an accelerator hook (cv::flip and cv::transpose in this PR) run on the device stored in the input's UMatData. Their output is created there with createOn(), also when the backend declines the call and the CPU runs it. Other functions run on the CPU as before.
One allocator per backend; each buffer keeps its device in UMatData::allocatorContext.
One stream per device and CPU thread (Device::threadStream()). Work of one thread runs in order; work of different threads is synchronized explicitly with cv::accel::synchronize(device).
Operations are reached with device.ops<accel::CoreOps>("core") and called directly. A stream keeps the buffers of queued work alive until it finishes (Stream::retain()), as the OpenCL backend does with a running kernel's UMats.
In-place calls are handled by each operation: the CUDA backend swaps mirrored elements for an in-place flip and transposes square matrices in place.
A CUDA backend with flip and transpose kernels. Discrete GPUs get memory from a stream-ordered pool that keeps freed memory for reuse while the pool holds less than a quarter of the device's memory, and returns the rest to the driver. On a GPU the build has no kernels for, the calls fall back to the CPU.
2026-11-20 17:54:15 +05:30
Shiven Solanki
884de0655d doc(core): fix output type rules for mulTransposed and calcCovarMatrix (#30987)
* doc(core): fix output type rules for mulTransposed and calcCovarMatrix

* doc(core): describe calcCovarMatrix mean depth rule per overload

* doc(core): drop redundant gemm note from mulTransposed src
2026-11-20 17:34:11 +05:30
Abhishek Gola
319fa030a2 Merge pull request #30822 from iammanoj807/fix/mixed-depth-64bit-add-sub
core: add and subtract a 64-bit integer with a narrower integer in 64-bit integers 🤖🤖🤖
2026-11-20 17:06:51 +05:30
Abhishek Gola
e03d01a414 Merge pull request #30973 from vrabaud/avif
Fix sanitizer bugs in OpenCV image warping

Strip BORDER_ISOLATED and validate borderType (0 <= borderType <= BORDER_TRANSPARENT)
Align cv::borderInterpolate (copy.cpp) and borderInterpolate_fast
Only compute tl_ofs in scalar bicubicCoeffs when all_inliers is true
2026-11-20 16:31:34 +05:30
Abhishek Gola
ae3d5ae750 core: cap the accel CUDA pool at a quarter of device memory and document that UMat::clone() stays on its device
Signed-off-by: Abhishek Gola <abhishek.gola@bigvisionllc.com>
2026-11-20 14:47:31 +05:30
Alexander Smorkalov
ef693903f5 Merge pull request #30989 from sshivensolanki:core-keypoint-overlap-nan
core: fix NaN in KeyPoint::overlap for internally tangent keypoints
2026-11-20 11:58:48 +03:00
Abhishek Gola
f672e8b1c8 core: bound the accel CUDA pool and fix its out-of-memory trim, fall back on GPUs without kernels and keep UMat::clone() on its device
Signed-off-by: Abhishek Gola <abhishek.gola@bigvisionllc.com>
2026-11-20 14:00:53 +05:30
pranayr710
01bdef3cab core: add the missing CV_Bool kernel to cv::compare
Comparing two CV_Bool matrices threw "no kernel for this op/type combination" for all six
comparison operations, while the matrix/scalar overload of the same function worked.
compareByType had a case for every other depth, CV_32U, CV_64U and CV_64S included, so
CV_Bool was the only one left out.

The uchar kernel is not a correct substitute. A CV_Bool byte is not guaranteed to hold 0 or
1, since a matrix wrapping an external buffer is never converted, and comparing the raw
bytes would order 2 above 1 when both mean true. countNonZero, norm, sum and the scalar
compare overload all already read CV_Bool logically, and notKernel documents the same rule
for bitwise NOT.

scalarCompareKernel takes an isBool template parameter that normalises each operand to 0/1
before comparing. It is a compile time constant, so the existing instantiations are
unchanged.
2026-11-20 13:24:29 +05:30
abhishek-gola
f23446318f core: fix accel transpose between regions of one buffer, CUDA < 11.2 builds and OpenCL images of foreign UMats
Signed-off-by: abhishek-gola <abhishek@opencv.org>
2026-11-20 12:54:06 +05:30
Shiven Solanki
1ae9b2b523 core: support 1D Mat in findNonZero
Fixes #30995
2026-11-20 14:37:51 +08:00
Manoj Kumar Thapa
8075a155df core: add and subtract a 64-bit integer with a narrower integer in 64-bit integers
promote2() mapped CV_64S and CV_64U to CV_64F, so cv::add and cv::subtract
computed a 64-bit integer array mixed with a narrower integer array in double,
and values above 2^53 lost their low bits: 3074457345618258602 + 5 gave
3074457345618258432.

Two integer depths (CV_IS_INT_TYPE, which includes CV_Bool) of which one is
64-bit now meet at promoteArith()'s integer type, as in NumPy. uint64 with a
signed integer, which no integer type holds, still promotes to CV_64F.

Adds Core_EW_AddSub.mixed_depth_s64_u64_exact and makes the same change to the
promote2() mirror in test_new_arithm_extensive.cpp.
2026-11-19 21:58:34 +00:00
Shiven Solanki
57884ae16e core: fix NaN in KeyPoint::overlap for internally tangent keypoints
Float rounding can push cosAlpha or cosBeta slightly outside [-1, 1] when one keypoint is just inside the other, so acos() returned NaN. Clamp both cosines before acos and add a regression test.
2026-11-20 02:03:16 +08:00
Vincent Rabaud
09ef0105c8 Fix sanitizer bugs in OpenCV image warping
- Strip BORDER_ISOLATED and validate borderType
  (0 <= borderType <= BORDER_TRANSPARENT)
- Align cv::borderInterpolate (copy.cpp) and borderInterpolate_fast
- Only compute tl_ofs in scalar bicubicCoeffs when all_inliers is true
2026-11-19 19:10:37 +05:30
Vladimir Iglovikov
a8dfd5c99b fix(core): broadcast zero-power output over all channels 2026-11-19 18:47:57 +09:00
Abhishek Gola
529546d011 Merge pull request #30892 from pratham-mcw/svd_backSubst_opt_5x
Add ARMPL HAL backend for cv::SVD::backSubst

Adds a new cv_hal_SVBackSubst32f/64f HAL hook and an ARM Performance Library (ARMPL) backend, accelerating cv::SVD::backSubst for float and double datatype on AArch64.
Unlike the cv::SVD::compute HAL hook (cv_hal_SVD32f/64f), which already existed, SVD::backSubst had no HAL dispatch it called the baseline SVBkSb unconditionally. This PR adds the core for the new hook alongside the ARMPL implementation.
2026-11-18 17:15:03 +05:30
Abhishek Gola
80db42de85 Merge pull request #30887 from abhishek-gola/fix/sphinx-docs-warnings
Fix Sphinx documentation warning sources
2026-11-18 08:49:36 +05:30
Pratham Kumar
433cd83e62 Add ARMPL HAL backend for cv::SVD::backSubst 2026-11-17 20:22:07 +05:30
Vadim Pisarevsky
a30d2be6ea Merge pull request #30618 from vpisarev:dft_opt
Further FFT/DFT/DCT optimizations - #30618

Merge together with https://github.com/opencv/opencv_extra/pull/1456

### Summary

Follow-up to #30061 and relates to #30467. It fixes the 64F 1D regressions measured on x86 after that PR, removes the O(r²) memory of the big prime radix, adds radix-8 stages, and makes the twiddle tables ~1 ulp accurate. Everything below was measured without IPP (`WITH_IPP=OFF`), so the numbers compare the OpenCV code paths only; the IPP logic is not touched.

Four commits, each self-contained:

1. **Memory, plan overhead, vectorization** (784be814b2)
   - Root cause of the x86 1D regressions: `cv::dft()` builds a plan per call, and at n = 65536 the engine allocated three MB-sized blocks per call (twiddles, permutation, workspace). glibc trims the heap after every free (its dynamic trim threshold is 2x the largest freed block), so every call page-faulted the buffers again: 65536 64FC2 ran at 620 us, ~215 us of it outside the transform. Fix: tables, permutation and the owner's workspace are **one allocation** per plan. No memory is retained between calls, no plan cache.
   - Static, lazily built tables for power-of-two lengths nc ≤ 1024 (stage twiddles, digit-reversal, real-FFT twiddles): plan building for 256..2048 points is table lookups only (0.06 us).
   - Generic odd radix: `cs/sn` tables of r entries with a cyclic index instead of h×h (h = (r−1)/2). n = 4093 in double: peak RSS 72.6 MB → 7.7 MB.
   - `DFT_STAGE_SIMD128`: stages with span shorter than the full vector but ≥ 128 bits run on `v_float32x4`/`v_float64x2` instead of scalar code (span 4 on AVX2 floats, i.e. every 4^k length).
   - Fused twiddle-free first stage of radix 3 and 5 for odd lengths (e.g. 4725), fused last radix-4 stage writing the interleaved scaled output, depth-first chunking of the leading stages for long transforms.
2. **`AutoBuffer` alignment** (02c6f39c82): `alignas(max(alignof(_Tp), 8))` on the local storage, so `AutoBuffer<uchar>` used as raw storage for double/int64 data is 8-byte aligned on every platform (it was only 4-byte aligned on 32-bit targets).
3. **Radix-8 stages and cache-set padding** (c7bf418d06): the power-of-two part is factored as r0·8^a·4^b (256: 2 middle stages instead of 3, 4096: 3 instead of 5, 65536: 5 instead of 7). The butterfly follows FFTW's `t1fv_8` (odd legs first, W8 rotations folded into the outputs with FMAs). The real reason an earlier radix-8 attempt was slower turned out to be **4K aliasing**: with a span of a 4 KB multiple, the data legs, the twiddle leg tables and the re/im arrays of one butterfly all map to one L1 set. One cache line of padding between the twiddle legs and between re and im gives 1.3–1.4x at n ≥ 16384 on its own; radix-8 adds 1.1–1.4x on top for complex transforms.
4. **Accurate twiddle generation** (2831df79c8): the tables were built by rotation recurrences and chained leg products and were 12–27 ulps off in double. Now every entry is one product of exactly computed seeds (Cephes sin/cos polynomials on an integer-reduced octant, ~0.5 ulp), computed in double, vectorized and rounded once. The real-FFT twiddles are stored as one table (`rtw_im = rtw_re + nc/2`).

Also: `perf_dft.cpp` gains 256x256 and 512x512 2D sizes (matchTemplate / filter2D tile sizes); `test_dxt.cpp` sweep gains prime and 2·prime lengths (257, 1009, 2018).

### Performance vs 5.x head (c4f7634256)

Environment: Intel Core Ultra 7 255H, Ubuntu 26.04, GCC 15.2, Release, default `CPU_BASELINE`/`CPU_DISPATCH` (AVX2 kernels are dispatched), `WITH_IPP=OFF`. Each binary was run twice and the minimum per case taken; the tables show the speedup `t(5.x) / t(PR)` as geomean over the flags (and row/column for 1D). Everything single-threaded unless stated.

**1D DFT (`dft1d`)**

|  | 32FC1 | 64FC1 | 32FC2 | 64FC2 |
|---|---|---|---|---|
| 256 | 2.11 | 1.84 | 2.25 | 1.73 |
| 1000 | 1.39 | 1.17 | 0.99 | 1.04 |
| 1024 | 2.62 | 2.07 | 2.49 | 1.68 |
| 4096 | 1.38 | 1.36 | 1.58 | 1.44 |
| 4725 | 1.81 | 1.71 | 1.86 | 1.72 |
| 65536 | 1.79 | 1.55 | 2.05 | 1.38 |

geomean 1.66 over 192 cases, min 0.98.

**1D DCT (`dct1d`)**

|  | 32FC1 | 64FC1 |
|---|---|---|
| 256 | 1.65 | 1.51 |
| 1000 | 1.50 | 1.22 |
| 1024 | 1.96 | 1.63 |
| 4096 | 1.52 | 1.37 |
| 65536 | 1.82 | 1.29 |

**2D DFT, 1 thread** (geomean over flags; `DFT_ROWS` cases in the second group)

|  | 32FC1 | 64FC1 | 32FC2 | | ROWS 32FC1 | ROWS 64FC1 | ROWS 32FC2 |
|---|---|---|---|---|---|---|---|
| 256x256 | 1.14 | 1.02 | 1.33 | | 0.97 | 0.97 | 1.70 |
| 512x512 | 1.14 | 1.04 | 1.04 | | 1.44 | 1.01 | 1.09 |
| 320x480 | 0.98 | 1.00 | 1.16 | | 0.98 | 1.00 | 1.62 |
| 800x600 | 1.10 | 1.00 | 0.99 | | 1.34 | 0.98 | 1.00 |
| 1280x1024 | 1.12 | 1.02 | 1.26 | | 1.00 | 1.00 | 1.43 |
| 1920x1080 | 1.12 | 1.00 | 0.99 | | 1.39 | 1.03 | 1.00 |
| 2048x2048 | 1.09 | 1.04 | 1.07 | | 1.34 | 0.99 | 1.21 |

2D DCT, 1 thread: 0.99–1.23 (geomean 1.06). With the default number of threads the 2D geomeans are the same (dft 1.07, dct 1.09) but individual cases are noisy on this hybrid-core CPU (0.75–1.76 between runs of the same code).

**imgproc**: matchTemplate 1.00–1.25 per image/template size (geomean 1.07), filter2D 1.00–1.03.

The one case consistently below 0.95 in the 1-thread tables, 2D 256x256 32FC2 `DFT_INVERSE` (0.84), is bimodal (0.11 / 0.19 ms) with both the old and the new library: it depends on the addresses malloc returns for the row buffers (set aliasing between src/dst and the 2D driver's buffers), so the per-run winner is luck. It is a candidate for a follow-up.

**Plain `cv::dft()` loop** (outside the perf harness, one thread, time per call in us, `create` = plan + workspace, `apply` = transform):

| n | type | 5.x total | PR total | 5.x create / apply | PR create / apply |
|---|---|---|---|---|---|
| 256 | 32FC1 | 0.54 | 0.23 | 0.35 / 0.09 | 0.06 / 0.09 |
| 1024 | 32FC2 | 1.88 | 0.76 | 0.82 / 0.97 | 0.06 / 0.58 |
| 4096 | 64FC2 | 13.3 | 8.7 | 5.1 / 9.1 | 2.3 / 5.7 |
| 4725 | 64FC2 | 47.6 | 17.9 | 8.2 / 24.7 | 3.0 / 14.5 |
| 65536 | 32FC2 | 358 | 109 | 97 / 175 | 26 / 80 |
| 65536 | 64FC2 | 632 | 199 | 155 / 255 | 33 / 159 |

At 65536 the 5.x numbers include ~90–220 us of page faults per call (the glibc trimming described above); the perf harness hides part of this because its warm-up changes the heap state.

### Accuracy

`cv::dft` output vs a long double reference, error in units of eps (2^−52 for double):

| n | impulse response, 5.x | PR | random input (rel. to max\|X\|), 5.x | PR |
|---|---|---|---|---|
| 256 | 12.1 | 0.9 | 15.9 | 0.8 |
| 1024 | 2.4 | 1.1 | 5.2 | 1.25 |
| 4096 | 26.6 | 1.35 | 29.5 | 1.1 |
| 65536 | 11.7 | 1.2 | | |
| 1048576 | 26.4 | 1.4 | | |

Float tables are correctly rounded (0.25 eps). Round trip `idft(dft(x))` at n = 4093 (generic odd radix): max error 5.2e-13 → 7.0e-15.

### Memory

n = 4093 64FC2 (prime length → generic odd radix 4093): peak RSS 72.6 MB → 7.7 MB. No memory is kept between calls apart from the static tables of the power-of-two lengths ≤ 1024 (34 KB float + 67 KB double, built on first use).

### Tests

- `opencv_test_core` (18297 tests) with AVX2 and with `OPENCV_CPU_DISABLE=AVX2`; `Core_DFT`/`Core_DCT` sweeps now include prime lengths.
- `opencv_test_imgproc` matchTemplate / filter2D / phaseCorrelate.
- `dxt.cpp` / `dxt.simd.hpp` syntax-checked for aarch64 NEON, riscv64 RVV, x86 without SIMD, AVX2 baseline, and with `-Wall -Wextra -Wshadow`.

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

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-11-17 14:41:43 +03:00
Alexander Smorkalov
6d711375a1 Merge pull request #30886 from sshivensolanki:core-magnitude-phase-nd
core: support N-D Mats in cv::magnitude and cv::phase
2026-11-17 12:00:15 +03:00
Alexander Smorkalov
5c98cb61a8 Merge pull request #30877 from sshivensolanki/core-convert-bool-negative-zero
core: fix convertTo(CV_Bool) turning -0.0 into true for CV_16F and CV_16BF
2026-11-17 11:18:32 +03:00
Alexander Smorkalov
84c8ba4e39 Merge pull request #30872 from pratham-mcw:sortIdx_opt_5x
core: parallelize sortIdx over independent rows/columns
2026-11-17 08:58:06 +03:00
Shiven Solanki
7c475d2785 core: support N-D Mats in cv::magnitude and cv::phase 2026-11-17 12:09:11 +08:00
Shiven Solanki
9465727b84 core: fix convertTo(CV_Bool) turning -0.0 into true for CV_16F and CV_16BF 2026-11-17 00:16:46 +08:00
Alexander Smorkalov
ff92bf2147 Merge pull request #30840 from sshivensolanki:core-foreach-1d-position
core: fix forEach position for 1D Mat
2026-11-16 17:56:54 +03:00
Abhishek gola
315ddafc6c Fix Sphinx API targets, navigation and documentation warnings 2026-11-16 20:13:32 +05:30
Pratham Kumar
1c67b283ac core: parallelize sortIdx over independent rows/columns 2026-11-16 18:04:18 +05:30
Abhishek Gola
d4e911c97e core: fix the accel test's 32-bit constant truncation warning and its RVV-dependent flip reference
Signed-off-by: Abhishek Gola <abhishek.gola@bigvisionllc.com>
2026-11-16 12:21:49 +05:30
Shiven Solanki
7a8d99e6b2 doc(core): note unspecified NaN handling in minMaxLoc and minMaxIdx (#30809) 2026-11-16 09:35:26 +05:30
Shiven Solanki
ac79228d5e core: fix forEach position for 1D Mat 2026-11-16 00:32:28 +08:00
Shiven Solanki
cc26a67b62 doc(core): fix LUT index formula for CV_8S and CV_16S inputs (#30793)
* doc(core): fix LUT index formula for CV_8S and CV_16S inputs

LUT reads CV_8S and CV_16S values as the unsigned numbers with the same bits, so negative values index the upper half of the table (-1 maps to entry 255 for CV_8S). The docs said the index was src + 128 (CV_8S) or src + 32768 (CV_16S), which is wrong for every value. Also remove a stray 'ref' in the compare docs.

* doc(core): fix LUT index rule in HAL interface docs

cv_hal_lut and cv_hal_lut16 docs still said 128 or 32768 is added to the index for 8s and 16s inputs. Use the same rule as the LUT docs: the input is read as unsigned with the same bits, and no offset is added.
2026-11-15 12:49:38 +05:30
lazerg
b62c3a475f core: fix solveCubic missing double roots after coefficient normalization (5.x) 2026-11-13 18:03:08 +05:00
Shiven Solanki
efe44093c3 Merge pull request #30706 from sshivensolanki/core-locateroi-1d (#30706)
core: fix locateROI and getUMat for 1D Mat and UMat

Problem
For a 1D Mat, Mat::locateROI divides by step[0] (the element size), so it counts every element as a row and returns a wrong wholeSize and offset. Because of this, adjustROI doesn't grow 1D slices, and getUMat on a 1D slice recurses until the stack overflows. UMat::locateROI has the same bug.

Fix
Mat::locateROI and UMat::locateROI: for dims == 1, compute the offset and whole size from the element size: ofs = (delta1 / esz, 0) and wholeSize = (delta2 / esz, 1). The width is clamped to at least ofs.x + cols, like the 2D code.
Mat::getUMat: for a 1D slice, cut the result out of the whole UMat with a Range instead of a Rect, so the returned UMat stays 1D. Cutting with a Rect always made it 2D.
2D Mats and UMats are unchanged.
2026-11-13 16:16:51 +05:30
Abhishek Gola
f62ce23b91 Merge pull request #30655 from sshivensolanki/core-add-sub-64-saturate ( #30655)
core: saturate cv::add and cv::subtract on CV_64S and CV_64UProblem
cv::add and cv::subtract are documented to saturate, and they do on every depth up to 32 bits. On 64 bits there is no wider type to hold the result, so add wrapped on CV_64S and CV_64U, and subtract wrapped on CV_64S. For example, INT64_MAX + 1 gave INT64_MIN. Signed overflow is also undefined behaviour in C++.

Fix
Added int64_t and uint64_t overloads of EwAdd::scl and an int64_t overload of EwSub::scl. They check for overflow before computing the result, like the existing uint64_t overload in EwSub.
Updated the comment on EwAdd::scl, which described 32-bit and 64-bit results as wrapping.
Other depths still use the generic scl, so their behaviour does not change.
2026-11-13 16:15:41 +05:30
Shiven Solanki
76bae0c542 core: support CV_16F and CV_16BF in finiteMask (#30620)
* core: support CV_16F and CV_16BF in finiteMask

finiteMask asserted CV_32F or CV_64F input, so 16-bit float arrays,
which can hold NaN and infinity too, could not be checked.

Add finiteMask16_, which marks a pixel as finite if no channel has an
all-ones exponent (0x7c00 for CV_16F, 0x7f80 for CV_16BF), for 1 to 4
channels. getFiniteMaskFunc now takes the depth. The OpenCL kernel only
handles float and double, so other depths fall back to the CPU path.

* core: use SIMD and typed templates in 16-bit finiteMask

Use hfloat and bfloat as the template parameter of finiteMask16_ instead
of the raw exponent masks, and add a universal-intrinsics path for 1 to
4 channels.

Add Core_FiniteMask_bits, which checks exact bit patterns at the edges
of the exponent: largest finite, subnormal, signalling, quiet and
negative NaN, and both infinities.

* core: use the scalar loop for 1-channel 16-bit finiteMask

With 1 channel, the compiler vectorizes the scalar loop, and it runs
faster than the explicit SIMD path. Use the SIMD path only for 2 to 4
channels.
2026-11-13 15:36:54 +05:30
Abhishek Gola
968b65053d core: address the non-CPU HAL review and fix the unused lambda capture warning
Signed-off-by: Abhishek Gola <abhishek.gola@bigvisionllc.com>
2026-11-13 14:56:42 +05:30