estimateAffine2D
import { estimateAffine2D } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Computes an optimal affine transformation between two 2D point sets.
It computes
\begin{bmatrix}
x\\
y\\
\end{bmatrix}
=
\begin{bmatrix}
a_{11} & a_{12}\\
a_{21} & a_{22}\\
\end{bmatrix}
\begin{bmatrix}
X\\
Y\\
\end{bmatrix}
+
\begin{bmatrix}
b_1\\
b_2\\
\end{bmatrix}
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 it works correctly only when there are more than 50% of inliers.
See: estimateAffinePartial2D, getAffineTransform
estimateAffine2D(from_: Mat, to: Mat, inliers: Mat, method: number, ransacReprojThreshold: number, maxIters: number, confidence: number, refineIters: number): Mat;7 available overloads
estimateAffine2D(from_: Mat, to: Mat): Mat;estimateAffine2D(from_: Mat, to: Mat, inliers: Mat): Mat;estimateAffine2D(from_: Mat, to: Mat, inliers: Mat, method: number): Mat;estimateAffine2D(from_: Mat, to: Mat, inliers: Mat, method: number, ransacReprojThreshold: number): Mat;estimateAffine2D(from_: Mat, to: Mat, inliers: Mat, method: number, ransacReprojThreshold: number, maxIters: number): Mat;estimateAffine2D(from_: Mat, to: Mat, inliers: Mat, method: number, ransacReprojThreshold: number, maxIters: number, confidence: number): Mat;estimateAffine2D(from_: Mat, to: Mat, inliers: Mat, method: number, ransacReprojThreshold: number, maxIters: number, confidence: number, refineIters: number): Mat;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 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 refining algorithm (Levenberg-Marquardt). Passing 0 will disable refining, so the output matrix will be output of robust method.
Output 2D affine transformation matrix 2 \times 3 or empty matrix if transformation
could not be estimated. The returned matrix has the following form:
\begin{bmatrix}
a_{11} & a_{12} & b_1\\
a_{21} & a_{22} & b_2\\
\end{bmatrix}
The function estimates an optimal 2D affine transformation between two 2D point sets using the selected robust algorithm.
The computed transformation is then refined further (using only inliers) with the Levenberg-Marquardt method to reduce the re-projection error even more. Release returned native handles with using or delete(), including handles nested in results.
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.