Skip to content

recoverPose

geometryfunctionOpenCV 5.0.0
import { recoverPose } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

Recovers the relative camera rotation and the translation from corresponding points in two images from two different cameras, using chirality check. Returns the number of inliers that pass the check.

    // Example. Estimation of fundamental matrix using the RANSAC algorithm
    int point_count = 100;
    vector<Point2f> points1(point_count);
    vector<Point2f> points2(point_count);

    // initialize the points here ...
    for( int i = 0; i < point_count; i++ )
    {
        points1[i] = ...;
        points2[i] = ...;
    }

    // Input: camera calibration of both cameras, for example using intrinsic chessboard calibration.
    Mat cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2;

    // Output: Essential matrix, relative rotation and relative translation.
    Mat E, R, t, mask;

    recoverPose(points1, points2, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, E, R, t, mask);
recoverPose(points1: Mat, points2: Mat, cameraMatrix1: Mat, distCoeffs1: Mat, cameraMatrix2: Mat, distCoeffs2: Mat, E: Mat, R: Mat, t: Mat, method: number, prob: number, threshold: number, mask: Mat): number;
5 available overloads
recoverPose(points1: Mat, points2: Mat, cameraMatrix1: Mat, distCoeffs1: Mat, cameraMatrix2: Mat, distCoeffs2: Mat, E: Mat, R: Mat, t: Mat): number;
recoverPose(points1: Mat, points2: Mat, cameraMatrix1: Mat, distCoeffs1: Mat, cameraMatrix2: Mat, distCoeffs2: Mat, E: Mat, R: Mat, t: Mat, method: number): number;
recoverPose(points1: Mat, points2: Mat, cameraMatrix1: Mat, distCoeffs1: Mat, cameraMatrix2: Mat, distCoeffs2: Mat, E: Mat, R: Mat, t: Mat, method: number, prob: number): number;
recoverPose(points1: Mat, points2: Mat, cameraMatrix1: Mat, distCoeffs1: Mat, cameraMatrix2: Mat, distCoeffs2: Mat, E: Mat, R: Mat, t: Mat, method: number, prob: number, threshold: number): number;
recoverPose(points1: Mat, points2: Mat, cameraMatrix1: Mat, distCoeffs1: Mat, cameraMatrix2: Mat, distCoeffs2: Mat, E: Mat, R: Mat, t: Mat, method: number, prob: number, threshold: number, mask: Mat): number;
points1

Array of N 2D points from the first image. The point coordinates should be floating-point (single or double precision).

points2

Array of the second image points of the same size and format as points1 .

cameraMatrix1

Input/output camera matrix for the first camera, the same as in calibrateCamera. Furthermore, for the stereo case, additional flags may be used, see below.

distCoeffs1

Input/output vector of distortion coefficients, the same as in calibrateCamera.

cameraMatrix2

Input/output camera matrix for the first camera, the same as in calibrateCamera. Furthermore, for the stereo case, additional flags may be used, see below.

distCoeffs2

Input/output vector of distortion coefficients, the same as in calibrateCamera.

E

Output destination, filled by the native operation. The output essential matrix.

R

Output destination, filled by the native operation. Output rotation matrix. Together with the translation vector, this matrix makes up a tuple that performs a change of basis from the first camera's coordinate system to the second camera's coordinate system. Note that, in general, t can not be used for this tuple, see the parameter described below.

t

Output destination, filled by the native operation. Output translation vector. This vector is obtained by decomposeEssentialMat and therefore is only known up to scale, i.e. t is the direction of the translation vector and has unit length.

method

Method for computing an essential matrix.

  • RANSAC for the RANSAC algorithm.
  • LMEDS for the LMedS algorithm.
prob

Parameter used for the RANSAC or LMedS methods only. It specifies a desirable level of confidence (probability) that the estimated matrix is correct.

threshold

Parameter used for RANSAC. It is the maximum distance from a point to an epipolar line in pixels, beyond which the point is considered an outlier and is not used for computing the final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the point localization, image resolution, and the image noise.

mask

Input/output value, modified by the native operation. Input/output mask for inliers in points1 and points2. If it is not empty, then it marks inliers in points1 and points2 for the given essential matrix E. Only these inliers will be used to recover pose. In the output mask only inliers which pass the chirality check.

This function decomposes an essential matrix using decomposeEssentialMat and then verifies possible pose hypotheses by doing chirality check. The chirality check means that the triangulated 3D points should have positive depth. Some details can be found in [Nister03].

This function can be used to process the output E and mask from findEssentialMat. In this scenario, points1 and points2 are the same input for findEssentialMat.:

Returns

The number result.

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.