The power-of-two part is now factored as r0 * 8^a * 4^b (r0 = 8 whenever the
rest can still be covered, radix-8 stages first, radix-4 last): 256 runs 2
middle stages instead of 3, 1024 3 instead of 4, 4096 3 instead of 5, 65536 5
instead of 7. The radix-8 butterfly follows FFTW's t1fv_8: the odd legs are
combined first (4-point DFT + the W8 rotations, kept as sums and folded into
the outputs with FMAs by +-1/sqrt(2)), then the even legs, whose pure
additions go straight into the outputs. GCC's AVX2 code for the kernel has 5
register spills per butterfly, so the 16-register budget is not the issue
that made an earlier radix-8 attempt slower. The last stage of C2C / even C2R
can be radix 8 too (radix8Last writes the interleaved scaled output).
Static tables gained the radix-8 stage twiddles for spans 4..128.
What did make the earlier attempt (and the radix-4 engine) slow at large n is
4K aliasing: with a span of a 4 KB multiple the r data legs, the r-1 twiddle
leg tables and the re/im arrays of one butterfly all map to one L1 set (12
ways on Intel, 8 on Zen), and 16-30 streams thrash it. One cache line of
padding between the twiddle legs (tw_stride) and between re and im (im_ofs)
fixes it: on its own it gives 1.3-1.4x at n >= 16384 for radix 4 already.
Apply time of one cv::dft() (Core Ultra 7 255H, AVX2, no IPP), speedup of
radix-8 + padding over the previous engine:
32FC2 64FC2 32FC1 64FC1
1024 1.17 1.07 1.09 1.09
4096 1.37 1.32 1.04 1.04
16384 1.63 1.51 1.22 1.32
65536 1.76 1.38 1.39 1.33
262144 1.70 1.46 1.35 1.30
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Fixes the 64F 1D regressions measured on x86 after #30061 and reduces the
memory of the generic odd radix. Measured without IPP (AVX2 kernels).
Root cause of the 1D regressions: cv::dft() builds a fresh plan per call, and
at n = 65536 the engine allocated three MB-sized blocks per call (twiddles,
permutation, workspace). glibc then trims the heap after every free (dynamic
M_TRIM_THRESHOLD = 2 x the largest block), so every call page-faulted the
buffers again: 65536 64FC2 ran at 620 us, of which ~215 us were outside the
transform itself. The old code made one ~1.5 MB allocation and escaped.
Changes:
- The plan's tables, the permutation and the owner's workspace are one
allocation (DftPlan::build(..., with_workspace)): one malloc per cv::dft()
call instead of three, and glibc's trimming is not triggered by a single
freed block (its threshold is twice the largest block seen). No memory is
retained between calls, no plan cache.
- Static, lazily built tables for power-of-two lengths nc <= 1024: radix-4
stage twiddles (shared by all plans: they depend on (radix, span) only),
digit-reversal tables and the real-FFT twiddles. Plan building for 256..2048
points is now table lookups only.
- Generic odd radix: cs/sn tables of r entries with a cyclic index p*k mod r
instead of h*h entries each (h = (r-1)/2). n = 4093 in double: peak RSS
72 MB -> 7.6 MB, max error 5e-13 -> 7e-15.
- DFT_STAGE_SIMD128: stages whose span is shorter than the full vector but at
least 128 bits run on v_float32x4 / v_float64x2 instead of scalar code
(span 4 on AVX2 floats, i.e. every 4^k length; span 2 on AVX-512 doubles).
- Fused twiddle-free first stage of radix 3 and 5 for odd nc (vectorized
gather + DFT3/DFT5), replacing the scalar table gather and two scalar
stages for lengths like 4725.
- Fused last radix-4 stage writing the interleaved, scaled output (C2C and
even C2R): one pass over the data less.
- Leading stages run chunk by chunk (depth-first, 32 KB per array) for long
transforms so that their data stays in L2.
- perf: 1D dft1d/dct1d cases and 256x256 / 512x512 2D sizes; test: prime and
2*prime lengths (257, 1009, 2018, ...) in the sweep.
Single thread, Core Ultra 7 255H (AVX2 kernels, no IPP), min of two perf runs,
geomean over flags and row/column; speedup of the optimized build vs 5.x head
and vs the pre-#30061 code:
32FC1 64FC1 32FC2 64FC2
dft1d 256 2.0 / 2.8 1.8 / 2.2 2.1 / 3.5 1.7 / 2.4
dft1d 1000 1.1 / 2.7 1.0 / 1.9 1.0 / 4.2 1.0 / 2.3
dft1d 1024 2.4 / 5.8 1.9 / 3.4 2.3 / 6.0 1.6 / 3.3
dft1d 4096 1.0 / 2.8 1.0 / 1.8 1.2 / 3.2 1.1 / 1.7
dft1d 4725 1.7 / 3.2 1.7 / 1.8 1.7 / 3.0 1.7 / 1.7
dft1d 65536 1.0 / 2.7 1.15/ 1.75 1.2 / 2.8 1.0 / 1.65
dct1d 256..65536: 1.03-1.22 / 1.8-2.6
2D dft 256x256..2048x2048: 1.05-1.15 / 2.2-3.8; 2D dct 1.04 / 2.6;
matchTemplate 1.01-1.06 / 2.1-3.4; filter2D unchanged.
In a plain cv::dft() loop (outside the perf harness) 65536 64FC2 goes from
620 us (5.x head) to 287 us, as the page-fault storm is gone.
No case is slower than 5.x head beyond run-to-run noise (checked by
alternating runs of the suspicious cases).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
vectorized and parallel DFT/DCT + matchTemplate - #30061
(Made with a help from Claude Code Fable 5.1)
## Summary
This PR replaces the scalar 1D DFT/DCT kernels in `modules/core/src/dxt.cpp` with a new engine
built on universal intrinsics and compiled per ISA through `ocv_add_dispatched_file`, and makes
the 2D transforms, the `DFT_ROWS`/`DCT_ROWS` batches and `matchTemplate` (`crossCorr`) multi-threaded.
The public API, the output formats (CCS packing of real spectra, `DFT_COMPLEX_OUTPUT` layout,
DCT ordering and normalization) and the IPP/OpenCL paths are unchanged. Only floating-point
rounding may differ (the new twiddle tables are more accurate than the old recurrence-generated
ones, so the error goes down, not up).
Measured on Apple M4 Max (16 cores, NEON), macOS 26.5.x, Xcode 26.6, Release build
(`-O3`, no IPP). All numbers are the minimum over repeated runs, `5.x` vs this PR.
## Changes
### New 1D engine (`dxt.hpp`, `dxt.simd.hpp`, `dxt.cpp`)
- **Split re/im layout.** The input pass gathers the data into separate `re[]`/`im[]` workspace
arrays; all middle stages operate on the split arrays, so a complex multiplication is four
independent vector FMAs with no lane shuffling. The output pass interleaves back (or packs the
CCS / DCT layout) with the scaling fused in.
- **Mixed-radix decimation-in-time with a fused first stage.** The plan chooses the first stage
(radix 1/2/4/8, twiddle-free, fused with the gather and the digit-reversal permutation) from
the power of two in the length, then radix-4 stages, then radix-3, radix-5 and a generic odd
radix. There are no radix-2 middle stages.
- **Vectorized butterflies with universal intrinsics** (`v_float32`/`v_float64`, VLA-safe): one
flat loop per stage with a single clamped counter for both the data and the twiddle offsets
(the back-off clamp handles spans that are not multiples of the vector width; such stages run
out of place, ping-ponging between two workspace pairs, the others run in place).
- **Vectorized first stage.** The radix-2/4/8 first stage reads the input columns contiguously
(`v_load_deinterleave`), runs the small DFT in registers and scatters the outputs of every
lane with one 4-channel interleaved store. Only odd lengths use a scalar table-driven gather.
- **Vectorized edge passes**: interleave/deinterleave, the real-FFT untangling in both directions
(with `v_reverse` for the mirrored half), DCT-II post-twiddle and DCT-III pre-twiddle, the
Makhoul permutations.
- **Inverse = conjugation trick**: the middle stages are direction-free and use forward twiddles
only; the inverse conjugates on the gather and negates the imaginary scale on the output.
- **Immutable plan + per-executor workspace, zero allocations per transform.** The plan
(radix sequence, permutation table, per-stage split twiddle tables) is built once in `init()`
and shared by all rows of a batch; every executor owns a workspace. Twiddles are generated in
double precision from a two-level exact table (a few ulps, much cheaper to build than the old
N-point recurrence, which matters because `cv::dft()` builds a plan on every call).
- **Per-ISA dispatch**: `ocv_add_dispatched_file(dxt SSE2 AVX2 AVX512_ICL RVV)`; the kernels are
reached through a function-pointer table resolved once per depth, following the pattern of
`arithm.simd.hpp` / `warp_kernels.simd.hpp`. The plan is built with the vector width of the
dispatched kernels (never with the baseline `VTraits`).
- The legacy scalar engine, `DFTInit`, the SSE3 `DFT_VecR*` butterflies and the `noPermute`/
`factors[0] >>= 1` machinery are removed (−1400 lines). The legacy `cv_hal_dft` hook (which
took the old tables) is no longer called from the 1D path; the in-tree RISC-V HAL
implementation of it will be updated in a separate PR.
### Parallelism
- `crossCorr` (`matchTemplate`): the correlation tiles are independent and are now distributed
with `parallel_for_`; every worker creates its DFT buffers and `DFT2D` contexts once per range.
(The tile loop had been sequential since the C++ rewrite in 2010, which dropped the OpenMP
pragma of `icvCrossCorr`.)
- 2D DFT/DCT and `DFT_ROWS`/`DCT_ROWS` batches: the row pass, the column pass and the DCT line
loop distribute their lines over threads; the 1D plan is shared, each worker allocates its
workspace once per range. The number of stripes is derived from the N log N cost, so a 256x256
transform stays on the calling thread and 1024x1024 gets ~20 stripes. Nested calls (the 2D DFTs
inside the parallel `crossCorr` tiles) are serialized by `parallel_for_` itself.
- The column pass copies columns in batches (`CopyFromColumns`/`CopyToColumns`, 4..16 adjacent
columns copied row by row into contiguous buffers sized to stay within 128 KB) instead of two
at a time: with power-of-two row steps the old strided copies aliased in the cache and took
60-70% of the 2D time.
### Tests
- `Core_DFT.sweep_1d`, `Core_DCT.sweep_1d`: every 5-smooth length up to 2048 plus odd, prime and
"awkward" lengths, both depths, C2C forward/inverse, R2C (CCS and complex output), C2R (CCS and
complex input), DCT/IDCT, in-place, column vectors, round trips; compared against the naive
O(N^2) references of `test_dxt.cpp` with a tolerance of `32*eps*(log2(N) + 2 + maxfactor/16)`.
- `Core_DFT.sweep_rows`: `DFT_ROWS` batches sharing one plan.
- `Core_DFT.nonzero_rows`: 2D transforms with `nonzero_rows` (previously uncovered).
- `Core_DFT.parallel_large`: large 2D / rows / DCT transforms, multi-threaded result vs the
single-threaded one.
- The naive DCT reference reduces the angle exactly before `cos()` (its accuracy was limiting
the comparison for n > 100 in double precision).
- Perf: `perf_dft.cpp` gains 1D row/column cases for `dft` and `dct`.
- Existing `opencv_test_core` (incl. `Core_DFT*`, `Core_DCT*`, `Core_MulSpectrums`,
`Core_DivSpectrums`) and `opencv_test_imgproc` (phaseCorrelate, matchTemplate, filter2D) pass;
the x86-64 build (SSE3 baseline + SSE4.1/AVX2/AVX512_ICL dispatch) passes the DFT/DCT tests
under Rosetta 2 (AVX2/AVX-512 paths compile-checked only on this machine).
## Performance
### 1D transforms (single row, one thread), microseconds
`C2C` = complex-to-complex, `R2C` = real-to-CCS, `C2R` = CCS-to-real (inverse, scaled),
`32`/`64` = float/double.
| n | C2C32 | C2C64 | R2C32 | C2R32 | R2C64 | DCT32 | IDCT32 | DCT64 |
|---|---|---|---|---|---|---|---|---|
| 256 | 0.82 → 0.55 | 0.86 → 0.74 | 0.67 → 0.53 | 0.63 → 0.52 | 0.64 → 0.56 | 0.88 → 0.56 | 0.88 → 0.56 | 0.90 → 0.66 |
| 1000 | 3.84 → 1.70 | 4.08 → 2.58 | 2.86 → 1.36 | 2.88 → 1.38 | 2.77 → 1.74 | 3.95 → 1.69 | 4.02 → 1.72 | 3.97 → 2.15 |
| 1024 | 3.25 → 1.65 | 3.44 → 2.40 | 2.46 → 1.23 | 2.35 → 1.27 | 2.42 → 1.59 | 3.57 → 1.57 | 3.51 → 1.59 | 3.45 → 2.02 |
| 4096 | 14.9 → 6.4 | 16.4 → 11.5 | 10.7 → 4.3 | 10.2 → 4.5 | 11.0 → 6.9 | 15.4 → 6.0 | 15.3 → 6.0 | 17.0 → 9.5 |
| 4725 (3³·5²·7) | 27.5 → 17.2 | 29.4 → 24.1 | 28.2 → 16.4 | 29.8 → 18.3 | 30.3 → 24.7 | – | – | – |
| 65536 | 350 → 273 | 411 → 494 | 223 → 136 | 274 → 139 | 251 → 249 | 318 → 167 | 299 → 159 | 372 → 320 |
Each `cv::dft()` call builds its plan anew; at n = 4096 the plan takes ~1.9 µs of the 6.4 µs
(the old code spent ~4 µs of 14.9 on its tables). For n = 65536 both versions are bound by the
memory traffic of the out-of-cache data, and C2C64 gets slightly slower (the split layout needs
one more pass over 1 MB of data; a plan cache or larger radices could recover this later).
### 2D transforms, single thread, microseconds
| size | C2C32 | R2C32 | C2R32 | R2C64 | DCT32 | IDCT32 | R2C32 rows |
|---|---|---|---|---|---|---|---|
| 256×256 | 297 → 140 | 162 → 75 | 165 → 77 | 178 → 126 | 259 → 166 | 290 → 174 | 72 → 29 |
| 512×512 | 1660 → 569 | 765 → 306 | 723 → 317 | 896 → 551 | 1381 → 946 | 1377 → 957 | 303 → 125 |
| 480×640 | 1555 → 715 | 895 → 377 | 918 → 392 | 978 → 677 | 1248 → 707 | 1262 → 695 | 389 → 147 |
| 1024×1024 | 7508 → 2625 | 3781 → 1387 | 3883 → 1398 | 4964 → 3201 | 6438 → 4556 | 6805 → 4583 | 1341 → 516 |
| 1080×1920 | 13141 → 5543 | 7143 → 2880 | 7269 → 2970 | 7770 → 5348 | 9735 → 5190 | 9477 → 5381 | 3116 → 1192 |
| 2048×2048 | 38151 → 16822 | 18381 → 6973 | 18784 → 7294 | 25146 → 17476 | 30291 → 21631 | 30540 → 22003 | 5809 → 2242 |
### 2D transforms, default thread count (16), microseconds
| size | C2C32 | R2C32 | C2R32 | R2C64 | DCT32 | IDCT32 | R2C32 rows |
|---|---|---|---|---|---|---|---|
| 256×256 | 309 → 138 | 157 → 75 | 161 → 77 | 174 → 126 | 265 → 167 | 293 → 170 | 71 → 29 |
| 512×512 | 1660 → 162 | 785 → 155 | 788 → 160 | 866 → 256 | 1410 → 235 | 1366 → 228 | 303 → 41 |
| 480×640 | 1531 → 178 | 895 → 142 | 916 → 141 | 957 → 222 | 1241 → 172 | 1248 → 173 | 393 → 46 |
| 1024×1024 | 7495 → 381 | 3755 → 274 | 3767 → 269 | 4875 → 478 | 6323 → 650 | 6583 → 630 | 1343 → 94 |
| 1080×1920 | 12905 → 681 | 7131 → 403 | 7240 → 382 | 7760 → 657 | 9673 → 605 | 9513 → 607 | 3124 → 143 |
| 2048×2048 | 38155 → 1481 | 18324 → 826 | 18559 → 857 | 24861 → 1776 | 30120 → 2592 | 30741 → 2734 | 5890 → 274 |
(5.x is single-threaded for all of these; 256×256 stays single-threaded in the new code by design.)
### matchTemplate (`opencv_perf_imgproc`, `*matchTemplate*`), milliseconds
Whole suite (156 cases): 921 → 284 ms. Selected cases (8-bit image, 16×16 template unless noted):
| image, template | SQDIFF | SQDIFF_NORMED | CCORR | CCORR_NORMED | CCOEFF | CCOEFF_NORMED |
|---|---|---|---|---|---|---|
| 128×128 | 0.15 → 0.12 | 0.14 → 0.12 | 0.09 → 0.05 | 0.13 → 0.09 | 0.11 → 0.08 | 0.13 → 0.10 |
| 320×240 | 0.99 → 0.52 | 1.09 → 0.58 | 0.79 → 0.23 | 0.96 → 0.42 | 0.93 → 0.38 | 1.02 → 0.53 |
| 640×480 | 3.19 → 1.17 | 3.35 → 1.22 | 2.27 → 0.29 | 3.12 → 1.04 | 2.94 → 0.90 | 3.43 → 1.38 |
| 800×600 | 5.86 → 1.64 | 5.61 → 1.77 | 4.11 → 0.34 | 5.48 → 1.53 | 5.19 → 1.28 | 5.82 → 2.04 |
| 1024×768 | 9.73 → 2.72 | 9.59 → 2.90 | 6.88 → 0.48 | 9.11 → 2.45 | 8.44 → 2.05 | 9.84 → 3.44 |
| 1280×1024 | 14.92 → 4.33 | 15.01 → 4.58 | 10.70 → 0.64 | 14.31 → 3.97 | 13.40 → 3.33 | 15.37 → 5.58 |
| 1280×1024, 1260×1000 | 13.06 → 7.90 | 13.08 → 7.74 | 10.75 → 3.58 | 12.23 → 5.03 | 11.11 → 3.94 | 12.03 → 5.05 |
`TM_CCORR` is now dominated by the (still single-threaded) `integral()` and normalization passes
in the other methods; those are candidates for a follow-up.
## Notes for reviewers
- `modules/core/src/dxt.hpp` documents the engine layout; the plan builder (`DftPlan::build`)
and the driver (`runDft`) are in `dxt.cpp`, the kernels in `dxt.simd.hpp`.
- Stages whose span is smaller than the vector width run scalar (on NEON this only affects
lengths of the form 2·odd; on AVX2/AVX-512 also the first radix-4 stage of 4^k lengths);
handling them with narrower fixed-width vectors is a possible follow-up.
- A radix-8 middle stage was implemented and measured slower on NEON than two radix-4 stages
(register pressure), so it is not included.
### 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
Fix code according to fuzzer findings - #30286
### 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
core: explicit UMat transfers for non OpenCL builds - #30259
## Summary
Core groundwork for moving the DNN CUDA backend from mapped `getMat()` to explicit host/device copies (related: #29807):
-`fitSameSize` keeps tensor layout, the missing `_OutputArray::fit*` overloads are defined, `UMat::create` reports a failing bound allocator, and cross-allocator `copyTo` no longer maps a device destination.
- OpenCL paths (`Kernel::set`, `isCLBuffer`, clFFT, `arithm_op`) now decline CUDA UMats instead of passing a CUDA pointer as `cl_mem`, which segfaulted with NVIDIA OpenCL.
- Adds a private `HostDeviceBuffer` (CUDA → OpenCL → CPU fallback) for the follow-up DNN PR, with tests for all of the above.
### 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
Fix function pointer signature mismatches - #30040
Contrib PR: https://github.com/opencv/opencv_contrib/pull/4224
Calling a function through a function pointer with a mismatched signature is undefined behavior in C/C++ and causes Clang Control Flow Integrity to trap with `SIGILL` (`ud1`) at indirect call sites.
This is a follow-up on https://github.com/opencv/opencv/pull/28939
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
Use MatShape instead of MatSize inside cv::Mat/cv::UMat #27757
**Merge together with https://github.com/opencv/opencv_contrib/pull/3996**
---
This PR continues cv::Mat/cv::UMat refactoring. See #26056, where `MatShape` was introduced. Now it's put inside cv::Mat/cv::UMat instead of a weird `MatSize`. MatSize is now an alias for MatShape:
**before:**
```
struct MatShape { ... };
struct MatSize { ... };
struct Mat {
...
int dims;
int rows;
int cols;
...
MatShape shape() const { ... /* constructs MatShape out of MatSize and returns it;
layout is always 'unknown', because we don't store it */ }
MatSize size; // size is not valid without the parent cv::Mat,
// because size.p may point to Mat::rows or to Mat::cols,
// depending on the dimensionality, and dims() returns Mat::dims.
MatStep step; // may allocate memory, depending on the dimensionality.
...
};
```
**after:**
```
struct MatShape { ... };
typedef MatShape MatSize; // they are now synonyms
struct Mat {
...
int dims;
int rows;
int cols;
...
MatShape shape() const { return size; } // just return the embedded shape (including the proper layout information)
MatSize size; // size is self-contained data structure that can be used without the parent cv::Mat.
// size.dims is now a copy of dims; size.p[*] contains copies of Mat::rows and Mat::cols when dims <= 2.
MatStep step; // does not allocate extra memory buffers.
...
};
```
There are several reasons to do that:
1. the main reason is to be able to store data layout (MatShape::layout) inside each cv::Mat/cv::UMat. This is necessary for the proper shape inference in DNN module. In particular, it's necessary for the next step of DNN inference optimization where we introduce block-layout-optimized convolution and other operations. Later on, we can use layout information to support non-interleaved images (e.g. RRR...GGG...BBB...) or even batches of such images in core/imgproc modules.
2. the other reason is to represent 3D/4D/5D etc. tensors as cv::Mat/cv::UMat instances more conveniently, without extra dynamic memory allocation. Before this patch we allocated some memory buffers dynamically to store shape & steps for more than 2D arrays. Now the whole cv::Mat/cv::UMat header can be stored completely on stack/in a container. Creating another copy of Mat/UMat header is now done more efficiently.
3. the third reason is to introduce the new coding pattern: `dst.create(src.size, <dst_type>);`. The pattern is suitable for most of element-wise (including cloning) and filtering operations. This pattern does not only look crisp and self-documenting, it will also automatically copy shape (including layout) from the source tensor into the destination matrix/tensor.
4. in the future we might add `colorspace` member to MatShape that will allow to distinguish RGB from BGR or NV12. `dst.create(src.size, <dst_type>);` will then copy the colorspace information as well.
### 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
Add RISC-V HAL implementation for cv::dft and cv::dct #26865
This patch implements `static cv::DFT` function in RVV_HAL using native intrinsic, optimizing the performance for `cv::dft` and `cv::dct` with data types `32FC1/64FC1/32FC2/64FC2`.
The reason I chose to create a new `cv_hal_dftOcv` interface is that if I were to use the existing interfaces (`cv_hal_dftInit1D` and `cv_hal_dft1D`), it would require handling and parsing the dft flags within HAL, as well as performing preprocessing operations such as handling unit roots. Since these operations are not performance hotspots and do not require optimization, reusing the existing interfaces would result in copying approximately 300 lines of code from `core/src/dxt.cpp` into HAL, which I believe is unnecessary.
Moreover, if I insert the new interface into `static cv::DFT`, both `static cv::RealDFT` and `static cv::DCT` can be optimized as well. The processing performed before and after calling `static cv::DFT` in these functions is also not a performance hotspot.
Tested on MUSE-PI (Spacemit X60) for both gcc 14.2 and clang 20.0.
```
$ opencv_test_core --gtest_filter="*DFT*"
$ opencv_perf_core --gtest_filter="*dft*:*dct*" --perf_min_samples=30 --perf_force_samples=30
```
The head of the perf table is shown below since the table is too long.
View the full perf table here: [hal_rvv_dxt.pdf](https://github.com/user-attachments/files/18622645/hal_rvv_dxt.pdf)
<img width="1017" alt="Untitled" src="https://github.com/user-attachments/assets/609856e7-9c7d-4a95-9923-45c1b77eb3a2" />
### 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
C-API cleanup: apps, imgproc_c and some constants #25075
Merge with https://github.com/opencv/opencv_contrib/pull/3642
* Removed obsolete apps - traincascade and createsamples (please use older OpenCV versions if you need them). These apps relied heavily on C-API
* removed all mentions of imgproc C-API headers (imgproc_c.h, types_c.h) - they were empty, included core C-API headers
* replaced usage of several C constants with C++ ones (error codes, norm modes, RNG modes, PCA modes, ...) - most part of this PR (split into two parts - all modules and calib+3d - for easier backporting)
* removed imgproc C-API headers (as separate commit, so that other changes could be backported to 4.x)
Most of these changes can be backported to 4.x.
* attempt to add 0d/1d mat support to OpenCV
* revised the patch; now 1D mat is treated as 1xN 2D mat rather than Nx1.
* a step towards 'green' tests
* another little step towards 'green' tests
* calib test failures seem to be fixed now
* more fixes _core & _dnn
* another step towards green ci; even 0D mat's (a.k.a. scalars) are now partly supported!
* * fixed strange bug in aruco/charuco detector, not sure why it did not work
* also fixed a few remaining failures (hopefully) in dnn & core
* disabled failing GAPI tests - too complex to dig into this compiler pipeline
* hopefully fixed java tests
* trying to fix some more tests
* quick followup fix
* continue to fix test failures and warnings
* quick followup fix
* trying to fix some more tests
* partly fixed support for 0D/scalar UMat's
* use updated parseReduce() from upstream
* trying to fix the remaining test failures
* fixed [ch]aruco tests in Python
* still trying to fix tests
* revert "fix" in dnn's CUDA tensor
* trying to fix dnn+CUDA test failures
* fixed 1D umat creation
* hopefully fixed remaining cuda test failures
* removed training whitespaces
Fix dynamic loading of clBLAS and clFFT (formerly, clAmdBlas and clAmdFft)
* Fix dynamic loading of clBLAS and clFFT
* Update filenames and function names for clBLAS (formerly, clAmdBlas)
* Update filenames and function names for clFFT (formerly, clAmdFft)
* Uncomment teardown of clFFT; tear down clFFT in same way as clBLAS
* Fix generators for clBLAS and clFFT headers
* Update generators to parse recent clBLAS and clFFT library headers
* Update generators to be compatible with Python 3
* Re-generate OpenCV's clBLAS and clFFT headers
* Update function calls to match names in newly generated headers
* Disable (and comment on) teardown code for clBLAS and clFFT
* Renaming *clamd* files
* Renaming *clamdblas* files to *clblas*
* Renaming *clamdfft* files to *clfft*
* Update generator for CL headers
* Update generator to be compatible with Python 3
- to reduce binaries size of FFmpeg Windows wrapper
- MinGW linker doesn't support -ffunction-sections (used for FFmpeg Windows wrapper)
- move code to improve locality with its used dependencies
- move UMat::dot() to matmul.dispatch.cpp (Mat::dot() is already there)
- move UMat::inv() to lapack.cpp
- move UMat::mul() to arithm.cpp
- move UMat:eye() to matrix_operations.cpp (near setIdentity() implementation)
- move normalize(): convert_scale.cpp => norm.cpp
- move convertAndUnrollScalar(): arithm.cpp => copy.cpp
- move scalarToRawData(): array.cpp => copy.cpp
- move transpose(): matrix_operations.cpp => matrix_transform.cpp
- move flip(), rotate(): copy.cpp => matrix_transform.cpp (rotate90 uses flip and transpose)
- add 'OPENCV_CORE_EXCLUDE_C_API' CMake variable to exclude compilation of C-API functions from the core module
- matrix_wrap.cpp: add compile-time checks for CUDA/OpenGL calls
- the steps above allow to reduce FFmpeg wrapper size for ~1.5Mb (initial size of OpenCV part is about 3Mb)
backport is done to improve merge experience (less conflicts)
backport of commit: 65eb946756
- to reduce binaries size of FFmpeg Windows wrapper
- MinGW linker doesn't support -ffunction-sections (used for FFmpeg Windows wrapper)
- move code to improve locality with its used dependencies
- move UMat::dot() to matmul.dispatch.cpp (Mat::dot() is already there)
- move UMat::inv() to lapack.cpp
- move UMat::mul() to arithm.cpp
- move UMat:eye() to matrix_operations.cpp (near setIdentity() implementation)
- move normalize(): convert_scale.cpp => norm.cpp
- move convertAndUnrollScalar(): arithm.cpp => copy.cpp
- move scalarToRawData(): array.cpp => copy.cpp
- move transpose(): matrix_operations.cpp => matrix_transform.cpp
- move flip(), rotate(): copy.cpp => matrix_transform.cpp (rotate90 uses flip and transpose)
- add 'OPENCV_CORE_EXCLUDE_C_API' CMake variable to exclude compilation of C-API functions from the core module
- matrix_wrap.cpp: add compile-time checks for CUDA/OpenGL calls
- the steps above allow to reduce FFmpeg wrapper size for ~1.5Mb (initial size of OpenCV part is about 3Mb)
Maximum depth limit var was added to the instrumentation structure;
Trace names output console output fix: improper tree formatting could happen;
Output in case of error was added;
Custom regions improvements;
Improved timing and weight calculation for parallel regions; New TC (threads counter) value to indicate how many different threads accessed particular node;
parallel_for, warnings fixes and ReturnAddress code from Alexander Alekhin;
HAVE_IPP_ICV_ONLY will be undefined if OpenCV was linked against ICV packet from IPP9 or greater. ICV9+ packets will be aligned with IPP in OpenCV APIs
This will ease code management between IPP and ICV
IPP_VERSION_MAJOR * 100 + IPP_VERSION_MINOR*10 + IPP_VERSION_UPDATE
to manage changes between updates more easily.
IPP_DISABLE_BLOCK was added to ease tracking of disabled IPP functions;