Skip to content

solvePnPRansac

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

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

Finds an object pose {}^{c}\mathbf{T}_o from 3D-2D point correspondences using the RANSAC scheme to deal with bad matches.

Perspective projection, from object to camera frame{ width=50% }

See: calib3d_solvePnP

Note: - An example of how to use solvePnPRansac for object detection can be found at tutorial_real_time_pose

  • The default method used to estimate the camera pose for the Minimal Sample Sets step is #SOLVEPNP_EPNP. Exceptions are:
    • if you choose #SOLVEPNP_P3P or #SOLVEPNP_AP3P, these methods will be used.
    • if the number of input points is equal to 4, #SOLVEPNP_P3P is used.
  • The method used to estimate the camera pose using all the inliers is defined by the flags parameters unless it is equal to #SOLVEPNP_P3P or #SOLVEPNP_AP3P. In this case, the method #SOLVEPNP_EPNP will be used instead.
solvePnPRansac(objectPoints: Mat, imagePoints: Mat, cameraMatrix: Mat, distCoeffs: Mat, rvec: Mat, tvec: Mat, useExtrinsicGuess: boolean, iterationsCount: number, reprojectionError: number, confidence: number, inliers: Mat, flags: number): boolean;
7 available overloads
solvePnPRansac(objectPoints: Mat, imagePoints: Mat, cameraMatrix: Mat, distCoeffs: Mat, rvec: Mat, tvec: Mat): boolean;
solvePnPRansac(objectPoints: Mat, imagePoints: Mat, cameraMatrix: Mat, distCoeffs: Mat, rvec: Mat, tvec: Mat, useExtrinsicGuess: boolean): boolean;
solvePnPRansac(objectPoints: Mat, imagePoints: Mat, cameraMatrix: Mat, distCoeffs: Mat, rvec: Mat, tvec: Mat, useExtrinsicGuess: boolean, iterationsCount: number): boolean;
solvePnPRansac(objectPoints: Mat, imagePoints: Mat, cameraMatrix: Mat, distCoeffs: Mat, rvec: Mat, tvec: Mat, useExtrinsicGuess: boolean, iterationsCount: number, reprojectionError: number): boolean;
solvePnPRansac(objectPoints: Mat, imagePoints: Mat, cameraMatrix: Mat, distCoeffs: Mat, rvec: Mat, tvec: Mat, useExtrinsicGuess: boolean, iterationsCount: number, reprojectionError: number, confidence: number): boolean;
solvePnPRansac(objectPoints: Mat, imagePoints: Mat, cameraMatrix: Mat, distCoeffs: Mat, rvec: Mat, tvec: Mat, useExtrinsicGuess: boolean, iterationsCount: number, reprojectionError: number, confidence: number, inliers: Mat): boolean;
solvePnPRansac(objectPoints: Mat, imagePoints: Mat, cameraMatrix: Mat, distCoeffs: Mat, rvec: Mat, tvec: Mat, useExtrinsicGuess: boolean, iterationsCount: number, reprojectionError: number, confidence: number, inliers: Mat, flags: number): boolean;
objectPoints

Array of object points in the object coordinate space, Nx3 1-channel or 1xN/Nx1 3-channel, where N is the number of points. vector<Point3d> can be also passed here.

imagePoints

Array of corresponding image points, Nx2 1-channel or 1xN/Nx1 2-channel, where N is the number of points. vector<Point2d> can be also passed here.

cameraMatrix

Input camera intrinsic matrix \cameramatrix{A} .

distCoeffs

Input vector of distortion coefficients \distcoeffs. If the vector is NULL/empty, the zero distortion coefficients are assumed.

rvec

Output destination, filled by the native operation. Output rotation vector (see Rodrigues ) that, together with tvec, brings points from the model coordinate system to the camera coordinate system.

tvec

Output destination, filled by the native operation. Output translation vector.

useExtrinsicGuess

Parameter used for SOLVEPNP_ITERATIVE. If true (1), the function uses the provided rvec and tvec values as initial approximations of the rotation and translation vectors, respectively, and further optimizes them.

iterationsCount

Number of iterations.

reprojectionError

Inlier threshold value used by the RANSAC procedure. The parameter value is the maximum allowed distance between the observed and computed point projections to consider it an inlier.

confidence

The probability that the algorithm produces a useful result.

inliers

Output destination, filled by the native operation. Output vector that contains indices of inliers in objectPoints and imagePoints .

flags

Method for solving a PnP problem (see solvePnP ).

The function estimates an object pose given a set of object points, their corresponding image projections, as well as the camera intrinsic matrix and the distortion coefficients. This function finds such a pose that minimizes reprojection error, that is, the sum of squared distances between the observed projections imagePoints and the projected (using projectPoints ) objectPoints. The use of RANSAC makes the function resistant to outliers.

Returns

The boolean 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.