* 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.
dnn: support CV_32U and CV_64U in Reduce layers
Fix
In modules/dnn/src/layers/reduce2_layer.cpp: Add CV_32U and CV_64U to getTypes validation.
In modules/dnn/src/layers/reduce_layer.cpp: Add CV_32U and CV_64U to getTypes and typeDispatch (opDispatch<uint32_t> and opDispatch<uint64_t>).
In modules/dnn/test/test_int.cpp: Extend Test_Reduce_Int to include CV_32U and CV_64U.
In modules/dnn/test/test_layers.cpp: Add Layer_Test_Reduce_Unsigned parameterized test checking MAX, MIN, and SUM on CV_32U and CV_64U with values greater than 2^31 to verify unsigned comparison logic.
dnn: reject zero delta in Range layer
Check that delta is not zero in getRangeParams() before rangeSize() is called: CV_CheckNE for the float branch and CV_CheckTrue(idelta != 0, ...) for the integer branch, since CV_CheckNE has no int64_t overload. Both forward() and getMemoryShapes() go through getRangeParams(), so both are covered.
* imgproc: support 5.x depths in remap/warp with INTER_NEAREST
nn_tab in cv::remap only had entries for CV_8U..CV_64F, so remap,
warpAffine and warpPerspective with INTER_NEAREST failed with
"nnfunc != 0" for CV_16F, CV_16BF, CV_Bool, CV_64U, CV_64S, CV_32U and
both fp8 depths. Nearest neighbor only copies pixels, so add the
remapNearest instances for these types, in both the absolute and the
WARP_RELATIVE_MAP rows. Using the real element types keeps the border
value conversion right (e.g. CV_Bool border 2 becomes 1).
Add an Imgproc_Warp_NearestNewDepths test.
* imgproc: use MatDepth in Imgproc_Warp_NearestNewDepths
A plain int parameter prints a failing case as GetParam() = 13. MatDepth prints the depth name instead.
* imgproc: convert remap nearest border once, dispatch copy by element size
dnn: support CV_32U, CV_64U and CV_Bool values in OneHot
Add the missing case labels, calling the existing runKernel<uint32_t>, runKernel<uint64_t> and runKernel<bool>.
tensorToScalar could not read CV_64U tensors. It now reads them as uint64_t and writes the result without going through int64_t, so values above INT64_MAX are not cut down. The output conversion moved into a small storeScalar template, called with double, int64_t or uint64_t; the results for the other input types are unchanged.
- Implement Col2ImLayer supporting static/dynamic output shape inference and spatial summation
- Enforce CV_32F data input and int32/int64 shape inputs in getTypes() and forward()
- Require 1-D rank and CV_64S value range-checking (rejecting > INT_MAX) for image_shape and block_shape
- Support multi-dimensional spatial blocks, dilations, pads, and strides
- Parse image and block shapes using OpenCV tensorToIntVec()
- Parallelize across batch and channels using a single parallel_for_ with batch*channel <= INT_MAX guard
- Guard wide-coordinate offsets and domain arithmetic against signed overflow
- Add unit and parameterized tests in test_layers for shape inference, type validation, empty inputs, oversized shapes, malformed ranks, coordinate bounds, malformed attributes, and 4-D spatial values
- Add Col2Im performance benchmark baseline in modules/dnn/perf/perf_col2im.cpp
- Skip Col2Im conformance tests in OpenVINO filter
- Un-denylist all 5 official ONNX conformance tests
# Conflicts:
# modules/dnn/test/test_layers.cpp
# Conflicts:
# modules/dnn/test/test_layers.cpp
geometry: respect row stride in triangulatePoints
The fix uses step1(0) to advance between points in a two-channel column matrix, while keeping the existing two-scalar step for row matrices. I applied this separately to both camera inputs and used size_t for the scalar offsets.
The triangulation algorithm itself is unchanged, and packed-column behavior from #28829 is preserved.
I also added a regression test covering float and double inputs, including contiguous columns, cloned ROIs, row layouts, and non-contiguous column ROIs on the left camera, right camera, or both.
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.
documentation fix 5.0 to 5.x - #30977
Replace stale "OpenCV 5.0" current-version wording with "5.x" in the 5.x docs (landing page, sidebar, prebuilt-binaries and transition-guide tutorials)
### 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
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.
* 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
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