Commit Graph

6328 Commits

Author SHA1 Message Date
Abhishek Gola
ffd7b6d9d4 Merge pull request #31312 from saanvimundra/fix/commandlineparser-key-validation-5x
core: report malformed CommandLineParser key descriptions
2026-12-02 20:44:04 +05:30
Karnajeet Gosavi
659b7829c6 core: Prevent overflow in wide sums of 8-bit inputs (#31255)
On the CPU, reducing a row of 8,421,505 unsigned bytes set to 255 into CV_64F returns -2,147,483,521. The integer accumulator overflows before the result is stored. The correct sum is 2,147,483,775.

This patch uses a double accumulator for signed and unsigned 8-bit input with CV_64F output. For CV_32F, it keeps the existing fast path for lengths that are safe to sum in an int and uses double for longer reductions.

The regression test covers positive overflow and negative underflow on both axes and with both floating-point outputs. All 48 selected CPU reduction tests passed on Windows with MSVC. A separate strided, three-channel check failed before the fix and passed afterward.

The unsigned SUM case overlaps with #31079. This draft also exercises the signed 8-bit paths on 5.x. The 4.x PR covers additional SUM2 and default-output AVG cases. This draft can be reassessed when that change is ported.
2026-12-02 16:35:43 +05:30
Abhishek Gola
6519977a19 Merge pull request #31103 from wzy712/fix-file_storage_overload
Problem
cv2.FileStorage.write() stores any Python integer outside the int32 range as a
boolean instead of a 64-bit integer: YAML gets true, XML/JSON get 1, and
reading the node back yields 1.0. The write(const String&, int64_t)
overload is exposed to Python but is unreachable.

The C++ API is not affected — FileStorage::write(name, (int64_t)value) stores
the exact value, as already covered by FileStorage_exact_type.long_int in
modules/core/test/test_io.cpp.

Root cause
The Python binding resolves FileStorage::write() overloads in declaration
order (modules/core/include/opencv2/core/persistence.hpp):

CV_WRAP void write(const String& name, int val);
CV_WRAP void write(const String& name, bool val);
CV_WRAP void write(const String& name, int64_t val);
For a Python integer outside int32, pyopencv_to(int&) fails the range check
and pyopencv_to(bool&) (modules/python/src2/cv2_convert.cpp, accepts any
integer scalar) consumes the value before the int64_t overload is tried.

Fix
Declare the int64_t overload before bool.
2026-12-02 16:32:53 +05:30
Andrei Fedorov
aaaaf213a5 [IPP] Reworked IPP-based pyramids and moved it to HAL (#30417)
* enabling pyrup and prparing pyrdown

* move pyramids to hal

* updated build pyramid

* aligning with 5.x

* removed ipp_buildpyramid
2026-12-02 16:03:34 +05:30
Vladimir Iglovikov
5608a3b4ae core: accelerate interleaved mixChannels permutations 🤖🤖🤖 (#30883)
cv::mixChannels copies each channel pair separately. This patch processes full permutations of a single interleaved matrix into a disjoint output in one pass over pixel blocks.

Use universal SIMD for 2–4 channels with 1-, 2-, or 4-byte elements.
Use dispatched byte shuffles for 5–16 channels on x86 and for 5–8 and 13–16 on AArch64. Start at 1,024 pixels and require at least 16 pixels per iterator plane. The NEON byte-shuffle code requires a 64-bit Arm target. ARMv7 uses the pairwise fallback for these wide byte maps. Preparing a shuffle costs more than it saves on smaller inputs. The AArch64 route for 9–12 channels regressed in the 512 × 512 tests.
Traverse pixels directly for CV_32F, CV_32S, and CV_32U with at least 32 channels and 65,536 pixels. This keeps reads local to each pixel and copies the 32-bit values without conversion. The size threshold avoids the slowdown seen on smaller wide matrices.
Overlap checks use the actual byte ranges of contiguous views and parent bounds for strided views. Partial maps and views that may overlap use the existing pairwise copy order. Identity mappings copy each iterator plane with a size_t byte count.
2026-12-02 15:28:29 +05:30
saanvimundra
4f9fa9d199 core: report malformed CommandLineParser key descriptions
A key without all three parts (names | default | help) read past the end of the split result. Throw StsParseError instead.
2026-12-02 07:16:09 +00:00
Abhishek Gola
24d37ecc01 Merge pull request #31291 from poojithparchuri-iiitk/mat-negative-size
Why
In 4.x, setSize has CV_Assert( s >= 0 ) for every dimension. On 5.x, setSize copies the sizes into a MatShape and the check is gone. Mat::create then leaves a matrix without memory and the caller writes into it. I did not find an issue or PR about this.

What I changed
The same check in setSize, with a guard for a null pointer, as 4.x did (5 lines). A size of 0 is still allowed. I added two tests: Core_Mat.create_negative_size (Mat::create and the Mat constructor) and Imgproc_Hist_Calc.regression_negative_hist_size (calcHist with negative bins in 1D, 2D and with a mask, and a normal call afterwards).
2026-12-02 11:33:39 +05:30
Madan mohan Manokar
585746dd60 core: Port 4.x Optimized JacobiSVD to 5.x (#30874)
Changes
Move the Jacobi SVD body into lapack.dispatch.cpp and lapack.simd.hpp, and dispatch it for AVX512_SKX and AVX512_ICL.
Accumulate float dot products in double, and vectorize dotD and givensD for both float and double.
2026-12-02 09:59:38 +05:30
Shiven Solanki
3e729646e6 core: fill the second index for 1D Mat in minMaxIdx (#31276)
Problem
For a 1D Mat, minMaxIdx writes only the first element of minIdx and maxIdx and leaves the second one unset, even though the docs require 2 elements. minMaxLoc hid this by forcing y = 0, which returns (-1, 0) instead of (-1, -1) when nothing is found.

Fix
ofs2idx now also sets idx[1] for a 1D Mat: 0 when a value is found, -1 when not. The y = 0 override in minMaxLoc is removed, so a 1D "not found" result matches 2D.
2026-12-02 09:58:48 +05:30
Parchuri Poojith Kumar
24f85c241f core: reject negative sizes in setSize, as 4.x does
On 4.x, setSize asserts that every size is not negative. The check is missing on 5.x, where the sizes are copied into a MatShape. Mat::create then accepts a negative size and leaves the matrix without memory, and the next function that writes into it crashes, for example calcHist with a negative number of bins. Restore the check. Add a core test for Mat::create and the Mat constructor, and a calcHist test with negative bin counts in 1D, 2D and with a mask.
2026-12-01 21:32:23 +05:30
Abhishek Gola
af81fbfbb7 Merge pull request #31014 from vrabaud/remove_using_std
Remove std using-declarations and directives from public headers.
2026-12-01 19:52:01 +05:30
Abhishek Gola
627ac36238 Merge pull request #31190 from intel-staging/dev/andreyfe1/5.x/ipp_instrumentation
Implemented a check to enable instrumentation for IPP HAL. From 4.x to 5.x
2026-11-30 13:49:23 +05:30
Vincent Rabaud
95844c51cb Remove std using-declarations and directives from public headers.
Re-exporting standard math and algorithm symbols from
modules/core/include/opencv2/core/cvstd.hpp into `namespace cv`
caused overload ambiguity between `cv::` array operations and
`std::` scalar templates, and `using namespace std` in `datasets`
and `hdf` public headers leaked `std` into downstream translation
units. Those conflicts previously required extra `const Mat&` and
`const UMat&` overloads of `cv::min` and `cv::max` in
modules/core/include/opencv2/core.hpp.

Drop `using std::min`, `std::max`, `std::swap`, `std::sqrt`,
`std::exp`, `std::pow`, and `std::log` from `cvstd.hpp` (keeping
`using std::abs`), `using std::nullptr_t` from
`cvstd_wrapper.hpp`, and `using namespace std` from
`track_vot.hpp`, `track_alov.hpp`, and `hdf5.hpp`. Remove the
obsolete `Mat` and `UMat` `min`/`max` overloads, qualify affected
calls across OpenCV modules with `std::`, and drop unused
`using std::*` declarations from module sources. Simplify
`std::pow(x, 0.5)` calls to `std::sqrt(x)`, collapse nested
`std::min`/`std::max` chains to initializer-list calls, and
replace constant-bound `min`/`max` pairs with `std::clamp`.
Existing runtime behavior is unchanged.
2026-11-29 00:00:25 +01:00
ChandraguptSharma07
c2296fcb84 Sped up uniform 8-bit fills in Mat::setTo 2026-11-29 00:42:00 +05:30
Fedorov, Andrey
dd9fbdd563 porting changes from 4.x 2026-11-27 01:57:15 -08:00
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
wzy712
6fed49ef20 core: prefer int64_t over bool in FileStorage::write
The Python binding tries FileStorage::write() overloads in declaration
order. pyopencv_to(bool&) accepts any integer scalar, so values outside
the int32 range were consumed by the bool overload and stored as `true`
in YAML, and as 1 in XML/JSON, even though write(int64_t) is exposed and
all three formats support 64-bit integers.

Declare the int64_t overload before bool.

Add a Python test that writes int32/int64 boundary values and checks the
serialized text for YAML, XML and JSON.
2026-11-25 01:33:14 +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