OpenCvSharp.Cv2.SolvePnP C# (CSharp) Method

SolvePnP() public static method

Finds an object pose from 3D-2D point correspondences.
public static SolvePnP ( IEnumerable objectPoints, IEnumerable imagePoints, double cameraMatrix, IEnumerable distCoeffs, double &rvec, double &tvec, bool useExtrinsicGuess = false, SolvePnPFlags flags = SolvePnPFlags.Iterative ) : void
objectPoints IEnumerable Array of object points in the object coordinate space, 3xN/Nx3 1-channel or 1xN/Nx1 3-channel, /// where N is the number of points. vector<Point3f> can be also passed here.
imagePoints IEnumerable Array of corresponding image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, /// where N is the number of points. vector<Point2f> can be also passed here.
cameraMatrix double Input camera matrix
distCoeffs IEnumerable Input vector of distortion coefficients (k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6]]) of 4, 5, or 8 elements. /// If the vector is null, the zero distortion coefficients are assumed.
rvec double Output rotation vector that, together with tvec , brings points from the model coordinate system to the /// camera coordinate system.
tvec double Output translation vector.
useExtrinsicGuess bool If true, the function uses the provided rvec and tvec values as initial approximations of /// the rotation and translation vectors, respectively, and further optimizes them.
flags SolvePnPFlags Method for solving a PnP problem:
return void
        public static void SolvePnP(
            IEnumerable<Point3f> objectPoints,
            IEnumerable<Point2f> imagePoints,
            double[,] cameraMatrix,
            IEnumerable<double> distCoeffs,
            out double[] rvec, out double[] tvec,
            bool useExtrinsicGuess = false,
            SolvePnPFlags flags = SolvePnPFlags.Iterative)
        {
            if (objectPoints == null)
                throw new ArgumentNullException(nameof(objectPoints));
            if (imagePoints == null)
                throw new ArgumentNullException(nameof(imagePoints));
            if (cameraMatrix == null)
                throw new ArgumentNullException(nameof(cameraMatrix));
            if (cameraMatrix.GetLength(0) != 3 || cameraMatrix.GetLength(1) != 3)
                throw new ArgumentException("");

            Point3f[] objectPointsArray = EnumerableEx.ToArray(objectPoints);
            Point2f[] imagePointsArray = EnumerableEx.ToArray(imagePoints);
            double[] distCoeffsArray = EnumerableEx.ToArray(distCoeffs);
            int distCoeffsLength = (distCoeffs == null) ? 0 : distCoeffsArray.Length;
            rvec = new double[3];
            tvec = new double[3];

            NativeMethods.calib3d_solvePnP_vector(
                    objectPointsArray, objectPointsArray.Length,
                    imagePointsArray, imagePointsArray.Length,
                    cameraMatrix, distCoeffsArray, distCoeffsLength,
                    rvec, tvec, useExtrinsicGuess ? 1 : 0, (int)flags);
        }
        #endregion

Same methods

Cv2::SolvePnP ( InputArray objectPoints, InputArray imagePoints, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess = false, SolvePnPFlags flags = SolvePnPFlags.Iterative ) : void
Cv2