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.
DISK, ALIKED and the two LightGlueMatcher variants read the ONNX network outputs through raw pointers and Mat::at<> with the layout of the reference exports, but never check the shape or element type that the loaded model actually returned. Any model passed to DISK::create, ALIKED::create or LightGlueMatcher::create (file or buffer) reaches this code:
DISK::detectAndCompute reads kptsData[i * 2 + 1] for every row of keypoints without checking it has 2 columns.
ALIKEDImpl::runNetwork reads at<float>(i, 1) on keypoints and at<float>(i, 0) on scores without checking 2 columns or the float type.
ALIKEDLightGlueMatcherImpl::lightglueMatch reads at<int64_t>(i, 1) on matches0 and at<float>(i) on mscores0 for every match row without checking 2 columns, the int64 type or one score per match.
DISKLightGlueMatcherImpl::lightglueMatch already checks the element counts but reads at<int64_t>(i) on matches0 without checking the int64 type.
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.
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.
- Check points3d_ori.rows == rows and points3d_ori.cols == cols (plus
non-empty valid row step) in RgbdNormalsImpl::apply() before cache()
and output creation so mismatched inputs throw without touching
preallocated output buffers.
- Validate positive dimensions in setRows() and setCols() (and >= 2 for
SRI in create(), setRows(), setCols(), and cache() to prevent the
cols/2 - 1 underflow and zero-denominator division on 1xN / Nx1 grids).
- Stage non-packed (ROI / padded-step) outputs and overlapping
CrossProduct buffers through a continuous temporary in apply() and
copy back into the caller's OutputArray, normalizing 1-D or transposed
OutputArray wrappers via reshape(0, rows) while preserving buffer
aliasing.
- Clone non-packed or overlapping 1-channel depth inputs for LINEMOD
(whose computeImpl() steps rows by cols), skip the inner loop early
when cols <= 2 * r + 1, and widen pixel-count multiplications to
size_t in FALS and SRI.
- Add parameterized NormalsInputSize tests covering mismatched sizes,
setter validation, 1-D wrappers, overlapping/in-place buffers, cross-
depth 4-channel ROIs, non-continuous Mat/UMat/padded-step outputs, and
LINEMOD 1-channel depth ROIs across CV_16U, CV_32F, and CV_64F.
dnn: use the opset 20 default axis -2 for ONNX DFT - #31142Fixes#31141
### Problem
Opset 20 made the `DFT` axis an optional input with default `-2`, but the importer leaves the layer on its opset 17 default `axis = 1`. So opset 20 `DFT` without an axis input transforms the wrong dim for 4-D and larger inputs.
### Fix
In `parseDFT`, set `axis = -2` when the model's opset is 20 or newer and no `axis` attribute is present (same pattern as `parseRoiAlign`).
### Tests
Added `Test_ONNX_layers.DFT_opset20_default_axis` to `test_onnx_importer.cpp`, using a `[1, 3, 4, 2]` model from opencv_extra. It fails without the fix and passes with it. The full `opencv_test_dnn` passes (9540 tests) on macOS arm64.
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
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.
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.
- Check points3d_ori.rows == rows and points3d_ori.cols == cols (plus
non-empty valid row step) in RgbdNormalsImpl::apply() before cache()
and output creation so mismatched inputs throw without touching
preallocated output buffers.
- Validate positive dimensions in setRows() and setCols() (and >= 2 for
SRI in create(), setRows(), setCols(), and cache() to prevent the
cols/2 - 1 underflow and zero-denominator division on 1xN / Nx1 grids).
- Stage non-packed (ROI / padded-step) outputs and overlapping
CrossProduct buffers through a continuous temporary in apply() and
copy back into the caller's OutputArray, normalizing 1-D or transposed
OutputArray wrappers via reshape(0, rows) while preserving buffer
aliasing.
- Clone non-packed or overlapping 1-channel depth inputs for LINEMOD
(whose computeImpl() steps rows by cols), skip the inner loop early
when cols <= 2 * r + 1, and widen pixel-count multiplications to
size_t in FALS and SRI.
- Add parameterized NormalsInputSize tests covering mismatched sizes,
setter validation, 1-D wrappers, overlapping/in-place buffers, cross-
depth 4-channel ROIs, non-continuous Mat/UMat/padded-step outputs, and
LINEMOD 1-channel depth ROIs across CV_16U, CV_32F, and CV_64F.
dnn: fix Trilu for inputs with more rows than columns
Problem
Trilu only loops over the first min(h, w) rows, so when the input has more rows than columns, the remaining rows keep their input values instead of being masked.
Fix
Loop over all h rows in forward() and remove the unused m. The existing cmin < w && num_zeros > 0 check already keeps the memset inside each row, so no other change is needed.
* dnn: support allowzero attribute in ONNX Reshape
* dnn: skip reshape allowzero test for OpenVINO, specify opset range
* dnn: add Reshape2 allowzero tests for 2D legacy and block-layout paths
* dnn: fix masked Attention ONNX import and commutative mask-Add fusion
ONNXImporter2::parseAttention required every input after X to be constant before populating params.blobs, leaving blobs empty for dynamic masks, pushing constant masks into blobs[2], and failing on omitted or trailing empty optional inputs. AttentionLayerImpl also read bias from blobs.back() instead of blobs[1], and ModelFusionAttention::isMaskAdd hardcoded inputs[1] so Add(mask, scores) bound Attention's mask to the removed score node. Fold constant weight and bias into blobs[0..1], keep any 4th mask input on layer->inputs[1], and match score_arg in isMaskAdd.
* dnn(onnx): lower the Attention int32 mask_index with addKeyPaddingMaskBias
mask_index is an int32 0/1 padding mask, not an additive bias. Turn it
into the additive mask the layer applies, the same way
parseMultiHeadAttention does, saving and restoring node_inputs and
node_outputs around the helper.
The test loads its models from opencv_extra (same branch name) with
testONNXModels() instead of building them and the reference in code;
the first three cases now use the spec's int32 [B, S] mask.
* dnn: keep AttentionLayerImpl's blob access as on 5.x
parseAttention now always gives the layer exactly two blobs, the weight
and the bias, and the fusion passes do the same, so blobs.front() and
blobs.back() already pick them. The blobs[0]/blobs[1] change is not
needed.
* dnn: return an empty shape in Shape when start > end
* dnn: apply the Shape start > end rule to the CUDA backend
* dnn: skip test_shape_start_greater_than_end in the OpenVINO filter
Problem
ShapeLayerImpl::getShapeRange asserts start_ <= end_, so Shape with start > end throws. The ONNX spec says the result should be an empty shape.
Fix
After clamping, set end_ = std::max(end_, start_) so the range has length 0. This
* 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>
* dnn: fix CumProd crash when the scan axis has length 0
* dnn: use Mat::empty() for the CumProd empty-input check
Return early from forwardImpl() when the input has no elements. The output already has the right empty shape. The check comes after normalize_axis(), so an out-of-range axis is still reported.
imgproc: Port 4.x enable boxFilter OpenCL fast paths on all aligned GPUs (5.x)
This PR only removes the Intel vendor gate as a port of upstream OpenCV PR #29805.
No changes are made to the underlying OpenCL kernels or dispatch logic.
Regression is observed on Apple M5 when filterSmall is used, including cases up to about 3.5× slower at odd, large sizes.
Earlier benchmark data in imgproc: Enable boxFilter OpenCL fast paths on Non-Intel GPUs. #29805 showed gains on AMD and NVIDIA GPUs for the small-kernel cases.
The filterSmall gate is therefore extended from Intel to AMD and NVIDIA. Apple and other vendors stay on the general kernel.
Any potential kernel correctness, ROI, aliasing, boundary handling, or in-place processing issues are pre-existing implementation concerns and should be evaluated separately in follow-up PRs. Such issues are outside the scope of this change.
core: support CV_Bool input in mean and meanStdDev - #30999Fixes#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
core, imgproc: support 0D Mat in LUT and threshold
Give a 0D input a 1x1 header before the row-based code runs, the same way #30704 normalizes 1D inputs in gemm:
threshold / thresholdWithMask: src (and mask) are viewed as 1x1, so the output is 1x1, the same as the other imgproc functions return for 0D input.
LUT: src and dst get 1x1 headers for the HAL and parallel paths. dst is created with createSameSize, so the result itself stays 0D.
dnn: support UINT32 and UINT64 targets in Cast
Map ONNX UINT32 (12) and UINT64 (13) to CV_32U and CV_64U in mapToCvDepth.
Add CV_32U and CV_64U cases to truncateFloatToInt, so float inputs truncate toward zero as ONNX requires, instead of being rounded by convertTo.
Allow CV_32U and CV_64U in the outputType parameter.