imgproc: fix INTER_NEAREST_EXACT to match Pillow (5.x retarget of #28661) #28873
## Summary
Fixes `INTER_NEAREST_EXACT` producing different results from Pillow for images with dimensions that are multiples of 64 (e.g., 128, 192).
Retargets #28661 to 5.x per core team request.
## Root cause
The old 16-bit fixed-point arithmetic (`ifx`, `ifx0`, `>> 16`) rounds differently from Pillow's pixel-center coordinate mapping. At exact pixel boundaries (e.g., y=7 with 128 to 160: `0.4 + 7*0.8 = 5.999999999999999`), Pillow's truncation drops to 5 while the old opencv formula rounds to 6.
## Changes
- `resize.cpp`: Replace `ifx/ifx0/ify/ify0` 16-bit fixed-point with an int64 arithmetic formula equivalent to `floor((i + 0.5) * src / dst)`, computed as `((int64_t)(i * 2 + 1) * src) / (dst * 2)`. This matches Pillow's pixel-center mapping exactly, is deterministic across platforms, and avoids FP rounding divergence entirely.
- `test_resize_bitexact.cpp`: Add `NearestExact_PillowCompat` covering 4 dimension pairs including the reproducer from #28429.
## Testing
- All 3 `Resize_Bitexact` tests pass (Linear8U, Nearest8U, NearestExact_PillowCompat) on this branch built against 5.x
- Verified bit-exact match to PIL output (Python 3.14, Pillow) on 49 dimension combinations including random pairs
- Built on macOS ARM64 with HAL (carotene/KleidiCV) active
Fixes#28429
[GSOC] feat: Add ALIKED feature extractor and LightGlue matcher with DNN integration #28986
## PR Description
### Summary
Integrate ALIKED and LightGlue into OpenCV's `features` module as native`Feature2D` and `DescriptorMatcher` implementations, enabling end-to-end neural feature matching within OpenCV's ecosystem.
---
### What's included
#### New classes
- **`cv::ALIKED`** extends `Feature2D`
- CNN-based keypoint detection
- 128-D descriptor extraction via ONNX Runtime
- **`cv::LightGlueMatcher`** extends `DescriptorMatcher`
- Deep feature matching with spatial context
- Uses keypoints and image sizes during matching
---
#### API design
- Standard OpenCV patterns:
- `detectAndCompute()`
- `match()`
- `knnMatch()`
- Multiple factory methods:
- ONNX model path
- In-memory model buffer
- Pre-loaded `dnn::Net`
- `Params` structs use `CV_EXPORTS_W_SIMPLE`
for Python/Java bindings support
- Optional DNN dependency:
- `HAVE_OPENCV_DNN` guards
- Stub implementations throw `StsNotImplemented`
---
### Files added
| File | Description |
|------|-------------|
| `src/feature2d_aliked.cpp` | ALIKED implementation |
| `src/matchers_lightglue.cpp` | LightGlueMatcher implementation |
| `src/aliked_context.hpp` | Shared internal context struct |
| `test/test_aliked_lightglue.cpp` | Unit tests (9 test cases) |
| `samples/cpp/example_features_aliked_lightglue.cpp` | Demo application |
---
### Files modified
- `CMakeLists.txt`
- Add `opencv_dnn` as optional dependency
- `features.hpp`
- Add ALIKED and LightGlueMatcher declarations
- `precomp.hpp`
- Add DNN include guard
---
### Usage
```cpp
// Feature extraction
Ptr<ALIKED> aliked =
ALIKED::create("aliked-n16rot-top1k-640.onnx");
vector<KeyPoint> kpts;
Mat descs;
aliked->detectAndCompute(image, Mat(), kpts, descs);
// Feature matching
Ptr<LightGlueMatcher> lg =
LightGlueMatcher::create("aliked_lightglue.onnx");
lg->setPairInfo(
kpts1Mat,
kpts2Mat,
img1.size(),
img2.size()
);
vector<DMatch> matches;
lg->match(descs1, descs2, matches);
````
please refer to samples/cpp/example_features_aliked_lightglue.cpp
---
### Test plan
* Build with `BUILD_LIST=features,dnn`
* Build without DNN:
* Verify stubs compile
* Verify `StsNotImplemented` is thrown
* Run:
* `ctest -R Features2d_ALIKED`
* `ctest -R Features2d_LightGlueMatcher`
* Run sample application with:
* Real images
* Real ONNX models
* Verify Python/Java bindings compile and work
---
### Related
Phase 1 of the
"End-to-End AI Feature Extraction and LightGlue Matching Pipeline"
GSoC project.
Designed to be extensible to:
* XFeat
* SuperPoint
* Other neural feature extractors
### test dependency
Depends on the opencv_extra PR adding ALIKED and LightGlue test models:
- [opencv_extra PR](https://github.com/opencv/opencv_extra/pull/1366)
This PR adds the following ONNX models to `download_models.py`:
- `aliked-n16rot-top1k-640.onnx`
- `aliked_lightglue.onnx`
These models are required for the `features2d` tests in the main OpenCV repository to validate the ALIKED and LightGlue feature extraction and matching pipeline.
### 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
[FOLLOW UP] : Documentation optimizations for the new Sphinx structure #29220
### Pull Request Readiness Checklist
This PR serves as a follow-up to the new documentation system introduced in [#29206](https://github.com/opencv/opencv/pull/29206)
Co-authored by: @abhishek-gola @kirtijindal14 @Akansha-977 @Prasadayus @varun-jaiswal17
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
Inverted imgproc-geometry dependency and moved more functions to geometry #29230
Fixes: https://github.com/opencv/opencv/issues/20267
Continues: https://github.com/opencv/opencv/pull/29175
OpenCV Contrib: https://github.com/opencv/opencv_contrib/pull/4137
OpenCV Extra: https://github.com/opencv/opencv_extra/pull/1377
Summary:
- LSD returned back to imgproc
- drawing functions moved to imgproc
- undistort image and related perf-pixel functions moved to imgproc
- moments moved to geometry
- estimateXXXtransform moved to geometry
After the patch the geometry module depends on code and Flann and may be used everywhere without potential circular dependencies
### 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
Update BarcodeDetector super-resolution API to use single-file ONNX #29227
### Pull Request Readiness Checklist
This PR updates the `BarcodeDetector` super-resolution API to support and utilize a single-file ONNX model format.
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
little but important fix in bicubic warping 1-channel case #29229
merge together with https://github.com/opencv/opencv_contrib/pull/4136
### 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.
- [ ] The feature is well documented and sample code can be built with the project CMake
Fix MLAS 32-bit x86 build by integrating missing upstream assembly files #29226
### Pull Request Readiness Checklist
This resolves the 32-bit x86 build failure for MLAS. Related to: https://github.com/opencv/opencv/pull/29218
* Added the required `x86` assembly files and headers from upstream.
* Added `__x86_64__` guards around the AMX `syscall` and the FMA3/AVX512F kernel assignments to prevent 32-bit compilation crashes.
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
[OpenCV 5] Fix apriltag corners order and update the doc #28823
I have updated documentation for the AprilTag dictionaries.
Corresponding issues:
- https://github.com/opencv/opencv-python/issues/1195
- https://stackoverflow.com/questions/79044142/why-is-the-order-of-the-incoming-corners-different-between-apriltag-and-aruco-ma
This is a breaking change and is targeted only for OpenCV 5.
---
I have updated the ArUco doc with more information about fiducial markers detection.
I have tried to add some recommendations, best practices:
- `DICT_ARUCO_MIP_36h12` should be the recommended family, [see](https://stackoverflow.com/a/51511558)
- link to download pregenerated markers for `MIP_36h12` is [here](https://sourceforge.net/projects/aruco/files/. I have not found some other official links for the other ArUco family, but since `MIP_36h12` should be used, I guess it is fined.
- recommendation to have a white border when printing the marker
### 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.
- [x] The feature is well documented and sample code can be built with the project CMake
Dedicated pointcloud module #29224
OpenCV contrib: https://github.com/opencv/opencv_contrib/pull/4134
### 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
Fixed Out-of-Memory issue and added VLM sample #29221
### 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
Added DISK feature extractor support #29073
closes: https://github.com/opencv/opencv/issues/27083
Merge with: https://github.com/opencv/opencv_extra/pull/1368/
### 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
Caffe importer cleanup #28678
Merge with: https://github.com/opencv/opencv_extra/pull/1324
### 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
- [x] The feature is well documented and sample code can be built with the project CMake
Fixed the new chessboard detector by not using OpenCL #29211
This should hopefully fix test failures on macOS x64 builder in the latest 5.x branch.
The code of Chessboard detector (namely, the FastX part) runs tons of different-size box filters on the same image. Optimally, those filters need to be computed all together using once-computed integral image, but instead those multiple box filters, especially given how the current opencl path in box filter is organized, seem to 'overload' our OpenCL cache system and it breaks, at least on macOS. Given that boxfilter is relatively cheap operation, it will unlikely loose much by running on CPU vs GPU. So this is the current solution - switch to CPU path there. Local tests show that even on Apple M4 Max with very fast GPU we get better execution speed on CPU than on GPU.
### 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
Revised bicubic interpolation kernels and updated the corresponding functions #29165
They should work more accurately and faster than the existing implementation. The PR follows the previous work (#26271 etc.) that brought faster bilinear kernels.
### 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
Make cv::VideoCapture::get return cv::CAP_PROP_UNKNOWN (-1) for unsupported properties #21337
The return value indicating an unsupported property is not consistent across backends.
I stumbled on this issue because my code was determining if a property value is valid if it's non-zero (like the documentation says), which worked fine on macOS, but not on Android.
For example, auto-exposure is not supported on macOS, so get() returns 0. But it is supported on Android and 0 means auto-exposure is off.
I think -1 is the better return value to indicate unsupported properties.
I made changes to all the backends. I think I got every case. This breaks API compatibility for some backends, so I based this on branch 3.4.
- [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 other license that is incompatible with OpenCV
- [x] The PR is proposed to proper branch
- [ ] There is reference to 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
Homogeneize some calib/3d behavior #29077
- use CV_Check to validate input sizes (thus throwing for invalid inputs)
- return bool to validate a function result
This fixes#22746
### 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
OpenCV New Documentation #29206
This PR introduces end to end working new Documentation in OpenCV.
Co-authored by: @abhishek-gola @omrope79 @Akansha-977 @Prasadayus @varun-jaiswal17
### 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