mirror of
https://github.com/opencv/opencv.git
synced 2026-01-18 17:21:42 +01:00
[calib3d] Add estimateTranslation2D() #27950 Merge with opencv_extra PR: opencv/opencv_extra#1286 ### **Description** This PR adds a new API, `cv::estimateTranslation2D()`, to the **calib3d** module. It computes a **pure 2D translation** between two sets of corresponding points using robust methods (`RANSAC` and `LMedS`). The function mirrors the interface and behavior of `estimateAffine2D()` and `estimateAffinePartial2D()`, but constrains the transformation to translation only. This model is particularly useful for cases where the motion between images is purely translational, such as: - Aerial stitching and planar mosaics. - Image alignment in fixed-camera systems. - Lightweight pipelines where affine or homography models are unnecessarily complex. The implementation introduces a new internal class `Translation2DEstimatorCallback` and integrates seamlessly into OpenCV’s existing robust estimation framework (`PointSetRegistrator`). --- ### **Key Features** - Implements `cv::estimateTranslation2D()` in the `calib3d` module. - Supports robust methods **RANSAC** and **LMedS**. - Adds accuracy and performance tests. - Provides full **C++ and Python bindings**. - Includes **Doxygen documentation** consistent with OpenCV’s standards. - Verified correctness across noise, outlier, and datatype variations. --- ### **Testing & Verification** **Unit Tests** (`modules/calib3d/`) - **Minimal sample:** `test1Point` validates that a single correspondence recovers the correct translation under both **RANSAC** and **LMedS** across 500 randomized trials. - **Robustness to noise and outliers:** `testNPoints` generates 100 correspondences, injects noise and outliers (≤40% for RANSAC, ≤50% for LMedS), and verifies that: - Estimated **T** closely matches ground truth (`cvtest::norm(..., NORM_L2)`). - Inlier mask consistency and correctness are maintained. - **Datatype conversion:** `testConversion` checks mixed input datatypes (integer → float) to ensure correct conversion and consistent results. - **Input immutability:** `dont_change_inputs` confirms that input arrays remain unchanged after function execution, mirroring affine behavior. **Performance Tests** (`modules/calib3d/`) - `EstimateTranslation2DPerf` benchmarks **RANSAC** and **LMedS** using: - Point counts: 1000 - Confidence levels: 0.95 - Refinement iterations: 10, 0 These tests confirm **numerical stability**, **performance scaling**, and **consistency** across datatypes and noise levels. --- ### 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 (`4.x`) - [x] There is a clear description, motivation, and validation summary in this PR - [x] There are accuracy and performance tests in the calib3d module - [x] The feature is well documented and sample code can be built with CMake - [x] The feature has Python bindings and verified documentation output - [x] There is test data or sample code in the opencv_extra repository (if applicable) - [ ] There is a reference to the original bug report or related issue (if applicable)