estimateTranslation2D
import { estimateTranslation2D } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Computes a pure 2D translation between two 2D point sets.
It computes
\begin{bmatrix}
x\\
y
\end{bmatrix}
=
\begin{bmatrix}
1 & 0\\
0 & 1
\end{bmatrix}
\begin{bmatrix}
X\\
Y
\end{bmatrix}
+
\begin{bmatrix}
t_x\\
t_y
\end{bmatrix}.
cv::Vec2d t = cv::estimateTranslation2D(from, to, inliers);
cv::Mat T = (cv::Mat_<double>(2,3) << 1,0,t[0], 0,1,t[1]);
The function estimates a pure 2D translation between two 2D point sets using the selected robust algorithm. Inliers are determined by the reprojection error threshold.
Note: The RANSAC method can handle practically any ratio of outliers but needs a threshold to distinguish inliers from outliers. The method LMeDS does not need any threshold but works correctly only when there are more than 50% inliers.
See: estimateAffine2D, estimateAffinePartial2D, getAffineTransform
estimateTranslation2D(from_: Mat, to: Mat, inliers: Mat, method: number, ransacReprojThreshold: number, maxIters: number, confidence: number, refineIters: number): Vec2d;7 available overloads
estimateTranslation2D(from_: Mat, to: Mat): Vec2d;estimateTranslation2D(from_: Mat, to: Mat, inliers: Mat): Vec2d;estimateTranslation2D(from_: Mat, to: Mat, inliers: Mat, method: number): Vec2d;estimateTranslation2D(from_: Mat, to: Mat, inliers: Mat, method: number, ransacReprojThreshold: number): Vec2d;estimateTranslation2D(from_: Mat, to: Mat, inliers: Mat, method: number, ransacReprojThreshold: number, maxIters: number): Vec2d;estimateTranslation2D(from_: Mat, to: Mat, inliers: Mat, method: number, ransacReprojThreshold: number, maxIters: number, confidence: number): Vec2d;estimateTranslation2D(from_: Mat, to: Mat, inliers: Mat, method: number, ransacReprojThreshold: number, maxIters: number, confidence: number, refineIters: number): Vec2d;from_First input 2D point set containing
(X,Y).toSecond input 2D point set containing
(x,y).inliersOutput destination, filled by the native operation. Output vector indicating which points are inliers (1-inlier, 0-outlier).
methodRobust method used to compute the transformation. The following methods are possible:
RANSAC- RANSAC-based robust methodLMEDS- Least-Median robust method RANSAC is the default method.
ransacReprojThresholdMaximum reprojection error in the RANSAC algorithm to consider a point as an inlier. Applies only to RANSAC.
maxItersThe maximum number of robust method iterations.
confidenceConfidence level, between 0 and 1, for the estimated transformation. Anything between 0.95 and 0.99 is usually good enough. Values too close to 1 can slow down the estimation significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation.
refineItersMaximum number of iterations of the refining algorithm. For pure translation the least-squares solution on inliers is closed-form, so passing 0 is recommended (no additional refine).
A 2D translation vector [t_x, t_y]^T as cv::Vec2d. If the translation could not be
estimated, both components are set to NaN and, if inliers is provided, the mask is filled with zeros.
\par Converting to a 2x3 transformation matrix:
\begin{bmatrix}
1 & 0 & t_x\\
0 & 1 & t_y
\end{bmatrix}
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.