Three changes:
intrin_neon.hpp — MSVC versions of v_load_expand / v_pack_store over the raw intrinsics
system.cpp — report FP16 on Windows ARM64, matching the aarch64 branch at line 585. Baseline
features are verified at startup, so without this the library builds and then refuses to run
cpu_fp16.cpp — MSVC ARM64 branch for the check, written with _ARM64_DISTINCT_NEON_TYPES set
so the check and the library agree. The old one did not, which is why it passed while the build
failed
* video: parallelize FarnebackPolyExp and FarnebackUpdateMatrices using parallel_for_
* tune Farneback parallel_for_ stripes and extend tests
* use scoped thread count in Farneback threading test
* hoist Farneback matrices update and parallelize Gaussian flow loop
* bound Farneback PolyExp stripes and consolidate thread test
* add large odd-size case to Farneback multithread test
Replace the std::pow calls with repeated multiplication (decolorPow), which for exponents 0/1/2 is the exact same arithmetic, not an approximation.
Take row pointers (Mat::ptr) instead of Mat::at in both polynomial loops.
Transpose dest/dest1 once in gradvector and read them row-major instead of walking columns.
Thread the full-resolution pass in grayImContruct with parallel_for_ over image rows, the polynomial terms are gathered once up front and each row accumulates independently, so the result is scheduler-independent. Below the element-count cutoff it runs as a single invocation.
Added a perf test (modules/photo/perf/perf_decolor.cpp).
In cv::warpPolar(), the forward path (no WARP_INVERSE_MAP) builds both remap tables, mapx and mapy, in a serial scalar loop over the output rows before calling remap(). Every output row is independent, so this loop can be threaded and vectorized.
TopKLayerImpl::finalize previously normalized the axis attribute by
overwriting this->axis with normalize_axis(axis, input_shape.size()).
When the layer was created with a negative axis (such as the default -1),
this replaced the relative index with a positive index fixed to the rank
of the first input.
Subsequent runs on an input of different rank then either:
- evaluated TopK along the wrong axis (e.g. axis 1 instead of axis 2
when moving from a 2D tensor to a 3D tensor), or
- triggered an out-of-range assertion in getMemoryShapes (e.g. axis 2
on a 2D tensor when moving from a 3D tensor to a 2D tensor).
Fix this by keeping this->axis unmodified and storing the normalized axis
separately for execution. Add unit tests for both increasing and decreasing
rank inputs on the same TopK layer instance.
TopKLayerImpl::finalize previously normalized the axis attribute by
overwriting this->axis with normalize_axis(axis, input_shape.size()).
When the layer was created with a negative axis (such as the default -1),
this replaced the relative index with a positive index fixed to the rank
of the first input.
Subsequent runs on an input of different rank then either:
- evaluated TopK along the wrong axis (e.g. axis 1 instead of axis 2
when moving from a 2D tensor to a 3D tensor), or
- triggered an out-of-range assertion in getMemoryShapes (e.g. axis 2
on a 2D tensor when moving from a 3D tensor to a 2D tensor).
Fix this by keeping this->axis unmodified and storing the normalized axis
separately for execution. Add unit tests for both increasing and decreasing
rank inputs on the same TopK layer instance.
* imgcodecs(jpegxl): preserve alpha channel on uniform opaque alpha with libjxl >= 0.13
Starting with libjxl 0.13.0 (libjxl/libjxl#4981), the default frame setting
strips alpha channels when all pixels are opaque during lossy encoding,
turning 4-channel input images into 3 channels on decode.
Set JXL_ENC_FRAME_SETTING_STRIP_ALPHA to 0 when building against libjxl
0.13.0 or later to keep 4 channels intact, and add parameterized tests
covering 8U/16U/32F, transparent/opaque alpha, and quality 95/100.
* Update warning message to be human readable.
* imgcodecs: fix PFM dimensions under grouped numeric locales
* Keep PFM formatting local and isolate locale regression tests
* Remove locale test and test-runner change as requested
core: preserve solvePoly roots under coefficient rescaling
This PR makes it so that a shared power of two is now applied to scale the internal polynomial coefficients before degree determination and root initialisation. The shift is limited to preserve non-zero components. Leading terms with exactly zero coefficients are removed, while the iteration method, input coefficients and output format are the same as before.
- Route 32F and 64F to blockSum for kernels up to 5x5
- Restore pre-#28224 out-of-place path in blockSum
- Keep the in-place ROI fix from #28224
- Drop float paths unused by fused 3x3/5x5 kernels
Android SDK 36, NDK 30 in 4.x - #31146
CI: https://github.com/opencv/ci-gha-workflow/pull/365
### 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
* imgproc: improve blur and box filter with combined row+column separable filter
- Combined row+column separable filter for small filter sizes (3x3 and 5x5) added to avoid intermediate row buffer storage.
- FilterEngine has been modified to use combined rowColumnFilter.
- Vectorize separable row sums.
- Fix normalized 8U/16U/16S/32S scaling in ColumnSum.
- Pass an inner-region flag to row and column filters.
- Use the fused path on x86 for out-of-place, centered-anchor 3x3/5x5.
- Add AVX512_ICL dispatch for box_filter.
* imgproc: fix in-place boxFilter on ROI
- Drop unused kcn/processInnerRegion column-filter args
- Skip fused path when src and dst overlap
- Add Imgproc_Blur.inplace_roi test
* imgproc: deduplicate box filter kernels
- Share row-slide helpers between RowSum and templates
- Merge ColumnSum specializations
- Share Sum3x3/Sum5x5 setup and tails
- Round CV_16S power-of-two normalization
- Use ptrdiff_t for dst row offsets
- Initialize Cn4 row-sum carry in native lane order
- Keep scalar int -> short column sum on RISC-V (GCC 13 ICE)
* imgproc: run fused box filter on row bands on all platforms
- Split the fused 3x3/5x5 pass into bands of ~256 KB of rows (min 8)
- Fixes the large-image slowdowns vs 4.x; output unchanged
- Route out-of-place 3x3/5x5 32F/64F boxFilter/blur to the fused kernels everywhere, not only x86
- Fixes the 32F slowdowns vs 4.x on Mac M5
* imgproc: address box filter review comments
- Drop always-true processInnerRegion arg from row filters and fillRowData
- Gate 8U/16U/16S fused box kernels on !CV_NEON instead of x86-only
* imgproc: run fused box filter bands in parallel
- Split fused 3x3/5x5 bands across threads when there is >= 1 MB of work per thread
- Fix false src/dst overlap detection that sent the fused path to the row-buffered fallback
* calib3d: fix USAC getLambda out-of-bounds on single support vectors
Fixes#27487
In usac::getLambda(), the median calculation had an inverted odd/even
parity check and accessed supports[size/2 + 1] when size % 2 was
non-zero. When evaluating a single model (supports.size() == 1),
supports[1] was accessed out of bounds, which triggered a debug
assertion (vector subscript out of range) in debug builds and caused
undefined reads in release builds.
This patch:
- Inlines getLambda in usac.hpp without CV_EXPORTS to avoid altering
the 4.x shared library ABI.
- Corrects the median calculation to use supports[size/2] for odd sizes
and (supports[size/2 - 1] + supports[size/2]) * 0.5 for even sizes.
- Guards empty support vectors and clamps denominators to avoid
divisions by zero.
* calib3d: add deterministic test coverage for getLambda
Add direct regression tests in test_usac.cpp:
- Empty support vector returns 1.0 and sets min_non_random_inliers to 1.
- Single-element vector (supports.size() == 1) validates fix against out-of-bounds read and crash.
- Even-sized vector (supports.size() == 4) validates two-middle-element median.
- Odd-sized vector (supports.size() == 3) validates middle-element median.
- Validates denominator handling and min_non_random_inliers when is_independent is true.
This PR replaces it with an 85 compare-exchange network that needs 146 min/max operations. The network is from Bert Dobbelaere's list of median selection networks (https://bertdobbelaere.github.io/median_networks.html), found with his SorterHunter program, and is also in the SorterHunter repository under the MIT License (https://github.com/bertdobbelaere/SorterHunter/blob/master/Networks/Median/Median_25_85_16.json). I checked with Bert Dobbelaere before opening this, and he is fine with it being used here. The PR reorders its compare-exchanges to reduce register pressure on targets with 16 vector registers. Nothing else changes: loads, stores, border and tail handling are untouched. For integer types the output is bit-identical. For floating point it is identical except in the NaN and signed-zero cases described in the notes below.
flann: handle non-multiple of 16 vector sizes in NEON Hamming distance - #31055Fixes#30940
On ARM NEON, \cvflann::Hamming<unsigned char>\ loaded 16 bytes per iteration using \or (size_t i = 0; i < size; i += 16)\ without tail handling. Whenever \size\ was not a multiple of 16, the final iteration read up to 15 bytes past each vector (\ld1q_u8\), adding those unrelated bits to the distance calculation and causing \heap-buffer-overflow\ under AddressSanitizer. This affected AKAZE descriptors (61 bytes) and any non-multiple-of-16 binary feature vector.
### Changes
- Adjust the main loop termination condition to \i + 16 <= size\.
- Process remaining 0..15 tail bytes directly with scalar \cvflann::HammingLUT\ after the vector reduction for both binary vector comparison and the \ZeroIterator\ overload.
- Add regression tests in \ est_hamming.cpp\ verifying tail bounds across vector lengths from 1 to 65 (including AKAZE's 61 bytes) and checking consistency against \cvflann::HammingLUT\ and \cv::norm(..., NORM_HAMMING)\.
### 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
This PR extends the RVV fused rotation implementation from #30057 to three-channel images, including RGB/BGR images.
Three-channel images currently fall back to separate transpose and flip operations for 90-degree rotation. The new implementation combines these operations into a single vectorized pass and writes directly to the final output positions.
It supports 1-, 2-, 4-, and 8-byte channels, corresponding to pixel sizes of 3, 6, 12, and 24 bytes. No public API changes are required.
videoio: fix the scale of grayscale frames in the built-in MJPEG encoder
Raised the tolerance from 10 to 16. The ARM64 difference comes from the encoder, not the decoder: the NEON DCT truncates the quantized coefficients where the scalar code rounds. For this frame the maximum error at quality 75, 90 and 100 is 11, 6 and 7 on AArch64 (under qemu) and 2 on x86. Without the fix the error is 255 at quality 75, so the test still fails on both.
* imgproc: do not put a bogus vertex into the result of approxPolyN
A vertex can only be contracted if the lines of the two edges next to the removed edge meet beyond it. For parallel edges, as in a rectangle, the code marked the vertex with the area FLT_MAX and the point (-1, -1), but still contracted it when nothing else was left, so the point (-1, -1) ended in the result. Nearly parallel edges, like in a regular octagon, gave a vertex billions of units away, because the check for parallel edges used a fixed threshold. Test for parallel edges relative to the edge lengths, treat edges that diverge the same way, and stop when no vertex can be contracted, as the documentation already allows for the epsilon limit. The result for any polygon that could be contracted is unchanged. Add tests and a note to the documentation.
* imgproc: add tests with nearly parallel sides for approxPolyN
The tests with a rectangle and an octagon with integer coordinates only have exactly parallel sides, which the old check for 1e-8 rejected as well. Add a test with a square whose top side is tilted by about 2e-7 radians, which gave a vertex 4e8 units away, and a test with regular octagons computed with float cos and sin for 16 rotations, which gave vertices billions of units away for some of them.
Earlier wrong cv::multiply api usage has been fixed. Scale param has been set to 6 by mistake by passing CV_64F.
cv::abs returns tiny negative value due to float32 sign-bit problem. This issue has been fixed.
Relative errors has been adjusted in perf_dot, perf_stat, perf_moments to avoid introducing new error while changing scale from 6 to 1 in cv::multiply.
The docs list the required order of the 4 object points for SOLVEPNP_IPPE_SQUARE, but do not say anything about the image points. In ippe.cpp (PoseSolver::solveSquare) the image points are used by index, so they must be given in the same order as the object points.
This PR adds that sentence everywhere the object point order is listed (SolvePnPMethod enum, solvePnP, solvePnPGeneric, solvePnPRefine docs and solvePnP.markdown). In solvePnP.markdown I also added that, when the marker faces the camera, this order is top-left, top-right, bottom-right, bottom-left, which is the same corner order returned by ArucoDetector::detectMarkers.
I checked this with a small script: with the same order solvePnP returns the true pose, with reversed image points the rotation is wrong.
Docs only, no code changes.
videoio(ffmpeg): keep HDR transfer and primaries so HLG/PQ frames are not clipped 🤖🤖🤖 - #31069
Merge with https://github.com/opencv/opencv_extra/pull/1473Fixes#30955
Hi @peterroelants, thanks for the detailed report and the ramp repro, it made this easy to pin down.
### What changed
Since #27755, with swscale >= 8.12.100 the conversion is set up by `sws_scale_frame()` from the two frames. `rgb_picture` had no colour properties, so swscale treated the output as SDR BT.709 and converted HLG and PQ input to it, clipping everything above SDR white to 255. This is option 1 from the issue: copy the source primaries and transfer to `rgb_picture` before the call. swscale then has no colour conversion to do and returns the decoded values like the old `sws_scale()` path (and like `ffmpeg -pix_fmt bgr24` with no output tags). The matrix and range don't need copying, swscale always treats an RGB frame as RGB, full range.
Older FFmpeg (swscale < 8.12.100) still goes through `sws_init_context()`, which ignores these fields, so nothing changes there.
### Test
New `videoio_ffmpeg_hdr.keep_decoded_values_30955` (hlg, pq) reads a 64x4 10-bit gray ramp tagged HLG or PQ (samples in the opencv_extra PR) and checks every pixel against the plain limited-range mapping, with a 3 level margin for swscale's dither. Without the fix both cases fail (mid-tones off by 10 to 20 levels, the right side of the ramp at 255).
- Debian 13 x86_64, self-built FFmpeg n8.1 (swscale 9.5.100): new tests fail before the fix, pass after. Full `opencv_test_videoio` with opencv_extra data: 564/564 pass.
- Same with the distro FFmpeg 7.1 (swscale 8.3.100): 564/564 pass, the new tests pass with or without the fix as expected.
- I also tried a PQ file with mastering display metadata: values stay within 1 level of the plain ramp.
I used AI assistance for parts of this change and tested it locally against the full test suite.
### 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
objdetect: validate the QR encoder version and correction level - #31042
QRCodeEncoder::create accepts any version and correction level, and the encoder then uses them as indexes into its tables. A version above 40 crashes or hangs it, and an unknown correction level crashes it too. With the Python package this is easy to see: set params.version = 41 or params.correction_level = 100 and call encode() on the encoder, and the process segfaults. With version 100 or 255 it hangs (I stopped it after 15 seconds), and with version 40 and correction_level 4 it crashes with SIGFPE, an arithmetic error.. The tables have MAX_VERSION + 1 entries, so version 41 reads past the end.
This adds two checks to the constructor of the encoder: the version must be in [0, 40], where 0 still selects it automatically, and the correction level must be one of the four known values. Anything else raises an error. Valid values are not affected.
I added three tests: an invalid version, an invalid correction level, and one that checks that the lowest and highest valid values (version 0, 1 and 40 with all four levels) still encode. On Windows with MSVC, without the change the two tests for invalid values fail, because the encoder accepts the bad values, and with the change they pass. The self-contained existing encoder tests also pass (Kanji, structured append, auto version, long text). I did not run the existing encoder tests that need images from opencv_extra, so CI will be the first run of those. My AI assistant also reproduced the crashes on the released 4.14.0 and 5.1.0 Python packages, and qrcode_encoder.cpp is the same in 4.14.0 and current 4.x.
This is separate from my open PR #30773, which changes the decoder part of the same file, so they do not touch the same lines.
I built and tested it myself on Windows, and an AI assistant (Claude) helped me find the problem and write the change and the tests.
- [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
- [ ] 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
photo: parallelize and vectorize the Poisson solver - #31065
## Summary
- All four cloning APIs (seamlessClone, colorChange, illuminationChange, textureFlattening) solve the three colour channels one after another in Cloning::poisson(). Each solve is two DST passes, which are cv::dft calls, and without IPP the DFT has no threading of its own. The channel solves are independent, so they can run in parallel.
## Changes
- Cloning::poisson runs the three channel solves through parallel_for_.
- Cloning::dst transposes once and reads in row order, instead of striding down a column.
- Four data-parallel loops in dst and solve use universal intrinsics (v_float32, vx_load, VTraits<>::vlanes()), each with a scalar tail.
- The per-element arithmetic is unchanged, so the output is bit-identical to the original.
- Adds perf tests for the four APIs in perf_cloning.cpp.
## Performance Benchmarks
<img width="647" height="240" alt="image" src="https://github.com/user-attachments/assets/5ab39c64-e236-4f35-9868-9bba4b8444a1" />
CLAHE_Impl::apply divides by the numbers of tiles and takes the remainder of them in several places, and nothing checked that they are positive. A tile grid with a zero, for example Size(0, 0) given to createCLAHE or setTilesGridSize, ended in a division by zero and a crash of the process, and a negative size was only rejected by accident, when a matrix with a negative size was created. Check both numbers at the start of apply. The result for any valid grid is unchanged. Add a test.