Ejemplo n.º 1
0
        /// <summary>
        /// Пытается произвести калибровку камеры
        /// </summary>
        /// <returns>Результат калибровки</returns>
        public bool TryToCalibrate(out CoordinatesTransformer transformer)
        {
            CvPoint2D32f[] imageCornersArray;
            transformer = new CoordinatesTransformer();

            // Пытаемся найти углы шахматной доски
            if (FindCorners(out imageCornersArray))
            {
                // Преобразуем массивы точек в матрицы
                CvMat imageCorners = new CvMat(imageCornersArray.Length, 1, MatrixType.F32C2, imageCornersArray);
                CvMat numCorners   = new CvMat(1, 1, MatrixType.S32C1, new CvScalar(imageCornersArray.Length));

                // Определяем нужно-ли считать коэффициенты дисторсии
                CalibrationFlag flag = UseUndistort ? CalibrationFlag.RationalModel : CalibrationFlag.ZeroTangentDist | CalibrationFlag.FixK1 | CalibrationFlag.FixK2;

                // Производим калибровку
                Cv.CalibrateCamera2
                (
                    generateCorners(),
                    imageCorners,
                    numCorners,
                    chessBoard.Size,
                    transformer.Intrinsic,
                    transformer.Distortion,
                    transformer.Rotation,
                    transformer.Translation,
                    flag
                );

                // Определяем прямоугольник в котором произведена калибровка
                CalibratedZone[0] = imageCornersArray[0];
                CalibratedZone[1] = imageCornersArray[CornersPattern.Width - 1];
                CalibratedZone[2] = imageCornersArray.Last();
                CalibratedZone[3] = imageCornersArray[CornersPattern.Width * (CornersPattern.Height - 1)];

                // Расчитываем матрицу перехода
                calculateTransformationMatrix(transformer);

                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
 public static extern void cvStereoCalibrate(IntPtr object_points, IntPtr image_points1, IntPtr image_points2, IntPtr npoints,
                        IntPtr camera_matrix1, IntPtr dist_coeffs1, IntPtr camera_matrix2, IntPtr dist_coeffs2,
                        CvSize image_size, IntPtr R, IntPtr T, IntPtr E, IntPtr F,
                        CvTermCriteria term_crit, CalibrationFlag flags);
Ejemplo n.º 3
0
 public static extern void cvCalibrateCamera2(IntPtr object_points, IntPtr image_points, IntPtr point_counts, CvSize image_size,
     IntPtr intrinsic_matrix, IntPtr distortion_coeffs, IntPtr rotation_vectors, IntPtr translation_vectors, CalibrationFlag flags);
Ejemplo n.º 4
0
        /// <summary>
        /// finds intrinsic and extrinsic parameters of a stereo camera
        /// </summary>
        /// <param name="objectPoints">Vector of vectors of the calibration pattern points.</param>
        /// <param name="imagePoints1">Vector of vectors of the projections of the calibration pattern points, observed by the first camera.</param>
        /// <param name="imagePoints2">Vector of vectors of the projections of the calibration pattern points, observed by the second camera.</param>
        /// <param name="cameraMatrix1">Input/output first camera matrix</param>
        /// <param name="distCoeffs1">Input/output 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. 
        /// The output vector length depends on the flags.</param>
        /// <param name="cameraMatrix2"> Input/output second camera matrix. The parameter is similar to cameraMatrix1 .</param>
        /// <param name="distCoeffs2">Input/output lens distortion coefficients for the second camera. The parameter is similar to distCoeffs1 .</param>
        /// <param name="imageSize">Size of the image used only to initialize intrinsic camera matrix.</param>
        /// <param name="R">Output rotation matrix between the 1st and the 2nd camera coordinate systems.</param>
        /// <param name="T">Output translation vector between the coordinate systems of the cameras.</param>
        /// <param name="E">Output essential matrix.</param>
        /// <param name="F">Output fundamental matrix.</param>
        /// <param name="criteria">Termination criteria for the iterative optimization algorithm.</param>
        /// <param name="flags">Different flags that may be zero or a combination of the CalibrationFlag values</param>
        /// <returns></returns>
        public static double StereoCalibrate(IEnumerable<IEnumerable<Point3d>> objectPoints,
                                             IEnumerable<IEnumerable<Point2d>> imagePoints1,
                                             IEnumerable<IEnumerable<Point2d>> imagePoints2,
                                             double[,] cameraMatrix1, double[] distCoeffs1,
                                             double[,] cameraMatrix2, double[] distCoeffs2,
                                             Size imageSize, OutputArray R,
                                             OutputArray T, OutputArray E, OutputArray F,
                                             TermCriteria? criteria = null,
                                             CalibrationFlag flags = CalibrationFlag.FixIntrinsic)
        {
            if (objectPoints == null)
                throw new ArgumentNullException("objectPoints");
            if (imagePoints1 == null)
                throw new ArgumentNullException("imagePoints1");
            if (imagePoints2 == null)
                throw new ArgumentNullException("imagePoints2");
            if (cameraMatrix1 == null)
                throw new ArgumentNullException("cameraMatrix1");
            if (distCoeffs1 == null)
                throw new ArgumentNullException("distCoeffs1");
            if (cameraMatrix2 == null)
                throw new ArgumentNullException("cameraMatrix2");
            if (distCoeffs2 == null)
                throw new ArgumentNullException("distCoeffs2");

            TermCriteria criteria0 = criteria.GetValueOrDefault(
                new TermCriteria(CriteriaType.Iteration | CriteriaType.Epsilon, 30, 1e-6));

            using (var op = new ArrayAddress2<Point3d>(objectPoints))
            using (var ip1 = new ArrayAddress2<Point2d>(imagePoints1))
            using (var ip2 = new ArrayAddress2<Point2d>(imagePoints2))
            {
                return NativeMethods.calib3d_stereoCalibrate_array(
                        op.Pointer, op.Dim1Length, op.Dim2Lengths,
                        ip1.Pointer, ip1.Dim1Length, ip1.Dim2Lengths,
                        ip2.Pointer, ip2.Dim1Length, ip2.Dim2Lengths,
                        cameraMatrix1, distCoeffs1, distCoeffs1.Length,
                        cameraMatrix2, distCoeffs2, distCoeffs2.Length,
                        imageSize, ToPtr(R), ToPtr(T), ToPtr(E), ToPtr(F),
                        criteria0, (int)flags);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// finds intrinsic and extrinsic parameters of a stereo camera
        /// </summary>
        /// <param name="objectPoints">Vector of vectors of the calibration pattern points.</param>
        /// <param name="imagePoints1">Vector of vectors of the projections of the calibration pattern points, observed by the first camera.</param>
        /// <param name="imagePoints2">Vector of vectors of the projections of the calibration pattern points, observed by the second camera.</param>
        /// <param name="cameraMatrix1">Input/output first camera matrix</param>
        /// <param name="distCoeffs1">Input/output 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. 
        /// The output vector length depends on the flags.</param>
        /// <param name="cameraMatrix2"> Input/output second camera matrix. The parameter is similar to cameraMatrix1 .</param>
        /// <param name="distCoeffs2">Input/output lens distortion coefficients for the second camera. The parameter is similar to distCoeffs1 .</param>
        /// <param name="imageSize">Size of the image used only to initialize intrinsic camera matrix.</param>
        /// <param name="R">Output rotation matrix between the 1st and the 2nd camera coordinate systems.</param>
        /// <param name="T">Output translation vector between the coordinate systems of the cameras.</param>
        /// <param name="E">Output essential matrix.</param>
        /// <param name="F">Output fundamental matrix.</param>
        /// <param name="criteria">Termination criteria for the iterative optimization algorithm.</param>
        /// <param name="flags">Different flags that may be zero or a combination of the CalibrationFlag values</param>
        /// <returns></returns>
        public static double StereoCalibrate(IEnumerable<InputArray> objectPoints,
                                             IEnumerable<InputArray> imagePoints1,
                                             IEnumerable<InputArray> imagePoints2,
                                             InputOutputArray cameraMatrix1, InputOutputArray distCoeffs1,
                                             InputOutputArray cameraMatrix2, InputOutputArray distCoeffs2,
                                             Size imageSize, OutputArray R,
                                             OutputArray T, OutputArray E, OutputArray F,
                                             TermCriteria? criteria = null,
                                             CalibrationFlag flags = CalibrationFlag.FixIntrinsic)
        {
            if (objectPoints == null)
                throw new ArgumentNullException("objectPoints");
            if (imagePoints1 == null)
                throw new ArgumentNullException("imagePoints1");
            if (imagePoints2 == null)
                throw new ArgumentNullException("imagePoints2");
            if (cameraMatrix1 == null)
                throw new ArgumentNullException("cameraMatrix1");
            if (distCoeffs1 == null)
                throw new ArgumentNullException("distCoeffs1");
            if (cameraMatrix2 == null)
                throw new ArgumentNullException("cameraMatrix2");
            if (distCoeffs2 == null)
                throw new ArgumentNullException("distCoeffs2");
            cameraMatrix1.ThrowIfDisposed();
            distCoeffs1.ThrowIfDisposed();
            cameraMatrix2.ThrowIfDisposed();
            distCoeffs2.ThrowIfDisposed();
            cameraMatrix1.ThrowIfNotReady();
            cameraMatrix2.ThrowIfNotReady();
            distCoeffs1.ThrowIfNotReady();
            distCoeffs2.ThrowIfNotReady();

            IntPtr[] opPtrs = EnumerableEx.SelectPtrs(objectPoints);
            IntPtr[] ip1Ptrs = EnumerableEx.SelectPtrs(imagePoints1);
            IntPtr[] ip2Ptrs = EnumerableEx.SelectPtrs(imagePoints2);

            TermCriteria criteria0 = criteria.GetValueOrDefault(
                new TermCriteria(CriteriaType.Iteration | CriteriaType.Epsilon, 30, 1e-6));

            double result =
                NativeMethods.calib3d_stereoCalibrate_InputArray(
                    opPtrs, opPtrs.Length,
                    ip1Ptrs, ip1Ptrs.Length, ip2Ptrs, ip2Ptrs.Length,
                    cameraMatrix1.CvPtr, distCoeffs1.CvPtr,
                    cameraMatrix2.CvPtr, distCoeffs2.CvPtr,
                    imageSize, ToPtr(R), ToPtr(T), ToPtr(E), ToPtr(F),
                    criteria0, (int)flags
                    );

            cameraMatrix1.Fix();
            distCoeffs1.Fix();
            cameraMatrix2.Fix();
            distCoeffs2.Fix();
            if (R != null)
                R.Fix();
            if (T != null)
                T.Fix();
            if (E != null)
                E.Fix();
            if (F != null)
                F.Fix();

            return result;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// finds intrinsic and extrinsic camera parameters from several fews of a known calibration pattern.
        /// </summary>
        /// <param name="objectPoints">In the new interface it is a vector of vectors of calibration pattern points in the calibration pattern coordinate space. 
        /// The outer vector contains as many elements as the number of the pattern views. If the same calibration pattern is shown in each view and 
        /// it is fully visible, all the vectors will be the same. Although, it is possible to use partially occluded patterns, or even different patterns 
        /// in different views. Then, the vectors will be different. The points are 3D, but since they are in a pattern coordinate system, then, 
        /// if the rig is planar, it may make sense to put the model to a XY coordinate plane so that Z-coordinate of each input object point is 0.
        /// In the old interface all the vectors of object points from different views are concatenated together.</param>
        /// <param name="imagePoints">In the new interface it is a vector of vectors of the projections of calibration pattern points. 
        /// imagePoints.Count() and objectPoints.Count() and imagePoints[i].Count() must be equal to objectPoints[i].Count() for each i.</param>
        /// <param name="imageSize">Size of the image used only to initialize the intrinsic camera matrix.</param>
        /// <param name="cameraMatrix">Output 3x3 floating-point camera matrix. 
        /// If CV_CALIB_USE_INTRINSIC_GUESS and/or CV_CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be 
        /// initialized before calling the function.</param>
        /// <param name="distCoeffs">Output 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.</param>
        /// <param name="rvecs">Output vector of rotation vectors (see Rodrigues() ) estimated for each pattern view. That is, each k-th rotation vector 
        /// together with the corresponding k-th translation vector (see the next output parameter description) brings the calibration pattern 
        /// from the model coordinate space (in which object points are specified) to the world coordinate space, that is, a real position of the 
        /// calibration pattern in the k-th pattern view (k=0.. M -1)</param>
        /// <param name="tvecs">Output vector of translation vectors estimated for each pattern view.</param>
        /// <param name="flags">Different flags that may be zero or a combination of the CalibrationFlag values</param>
        /// <param name="criteria">Termination criteria for the iterative optimization algorithm.</param>
        /// <returns></returns>
        public static double CalibrateCamera(
            IEnumerable<IEnumerable<Point3d>> objectPoints,
            IEnumerable<IEnumerable<Point2d>> imagePoints,
            Size imageSize,
            double[,] cameraMatrix,
            double[] distCoeffs,
            out Vec3d[] rvecs,
            out Vec3d[] tvecs,
            CalibrationFlag flags = CalibrationFlag.Zero,
            TermCriteria? criteria = null)
        {
            if (objectPoints == null)
                throw new ArgumentNullException("objectPoints");
            if (objectPoints == null)
                throw new ArgumentNullException("objectPoints");
            if (cameraMatrix == null)
                throw new ArgumentNullException("cameraMatrix");
            if (distCoeffs == null)
                throw new ArgumentNullException("distCoeffs");

            TermCriteria criteria0 = criteria.GetValueOrDefault(
                new TermCriteria(CriteriaType.Iteration | CriteriaType.Epsilon, 30, Double.Epsilon));

            using (var op = new ArrayAddress2<Point3d>(objectPoints))
            using (var ip = new ArrayAddress2<Point2d>(imagePoints))
            using (var rvecsVec = new VectorOfMat())
            using (var tvecsVec = new VectorOfMat())
            {
                double ret = NativeMethods.calib3d_calibrateCamera_vector(
                    op.Pointer, op.Dim1Length, op.Dim2Lengths,
                    ip.Pointer, ip.Dim1Length, ip.Dim2Lengths,
                    imageSize, cameraMatrix, distCoeffs, distCoeffs.Length,
                    rvecsVec.CvPtr, tvecsVec.CvPtr, (int)flags, criteria0);
                Mat[] rvecsM = rvecsVec.ToArray();
                Mat[] tvecsM = tvecsVec.ToArray();
                rvecs = EnumerableEx.SelectToArray(rvecsM, m => m.Get<Vec3d>(0));
                tvecs = EnumerableEx.SelectToArray(tvecsM, m => m.Get<Vec3d>(0));
                return ret;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// finds intrinsic and extrinsic camera parameters from several fews of a known calibration pattern.
        /// </summary>
        /// <param name="objectPoints">In the new interface it is a vector of vectors of calibration pattern points in the calibration pattern coordinate space. 
        /// The outer vector contains as many elements as the number of the pattern views. If the same calibration pattern is shown in each view and 
        /// it is fully visible, all the vectors will be the same. Although, it is possible to use partially occluded patterns, or even different patterns 
        /// in different views. Then, the vectors will be different. The points are 3D, but since they are in a pattern coordinate system, then, 
        /// if the rig is planar, it may make sense to put the model to a XY coordinate plane so that Z-coordinate of each input object point is 0.
        /// In the old interface all the vectors of object points from different views are concatenated together.</param>
        /// <param name="imagePoints">In the new interface it is a vector of vectors of the projections of calibration pattern points. 
        /// imagePoints.Count() and objectPoints.Count() and imagePoints[i].Count() must be equal to objectPoints[i].Count() for each i.</param>
        /// <param name="imageSize">Size of the image used only to initialize the intrinsic camera matrix.</param>
        /// <param name="cameraMatrix">Output 3x3 floating-point camera matrix. 
        /// If CV_CALIB_USE_INTRINSIC_GUESS and/or CV_CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be 
        /// initialized before calling the function.</param>
        /// <param name="distCoeffs">Output 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.</param>
        /// <param name="rvecs">Output vector of rotation vectors (see Rodrigues() ) estimated for each pattern view. That is, each k-th rotation vector 
        /// together with the corresponding k-th translation vector (see the next output parameter description) brings the calibration pattern 
        /// from the model coordinate space (in which object points are specified) to the world coordinate space, that is, a real position of the 
        /// calibration pattern in the k-th pattern view (k=0.. M -1)</param>
        /// <param name="tvecs">Output vector of translation vectors estimated for each pattern view.</param>
        /// <param name="flags">Different flags that may be zero or a combination of the CalibrationFlag values</param>
        /// <param name="criteria">Termination criteria for the iterative optimization algorithm.</param>
        /// <returns></returns>
        public static double CalibrateCamera(
            IEnumerable<Mat> objectPoints,
            IEnumerable<Mat> imagePoints,
            Size imageSize,
            InputOutputArray cameraMatrix,
            InputOutputArray distCoeffs,
            out Mat[] rvecs, 
            out Mat[] tvecs,
            CalibrationFlag flags = CalibrationFlag.Zero, 
            TermCriteria? criteria = null)
        {
            if (objectPoints == null)
                throw new ArgumentNullException("objectPoints");
            if (objectPoints == null)
                throw new ArgumentNullException("objectPoints");
            if (cameraMatrix == null)
                throw new ArgumentNullException("cameraMatrix");
            if (distCoeffs == null)
                throw new ArgumentNullException("distCoeffs");
            cameraMatrix.ThrowIfNotReady();
            distCoeffs.ThrowIfNotReady();

            TermCriteria criteria0 = criteria.GetValueOrDefault(
                new TermCriteria(CriteriaType.Iteration | CriteriaType.Epsilon, 30, Double.Epsilon));

            IntPtr[] objectPointsPtrs = EnumerableEx.SelectPtrs(objectPoints);
            IntPtr[] imagePointsPtrs = EnumerableEx.SelectPtrs(imagePoints);

            double ret;
            using (var rvecsVec = new VectorOfMat())
            using (var tvecsVec = new VectorOfMat())
            {
                ret = NativeMethods.calib3d_calibrateCamera_InputArray(
                    objectPointsPtrs, objectPointsPtrs.Length,
                    imagePointsPtrs, objectPointsPtrs.Length,
                    imageSize, cameraMatrix.CvPtr, distCoeffs.CvPtr,
                    rvecsVec.CvPtr, tvecsVec.CvPtr, (int)flags, criteria0);
                rvecs = rvecsVec.ToArray();
                tvecs = tvecsVec.ToArray();
            }

            cameraMatrix.Fix();
            distCoeffs.Fix();
            return ret;
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Performs stereo calibration.
 /// </summary>
 /// <param name="objectPoints">Vector of vectors of the calibration pattern points.</param>
 /// <param name="imagePoints1">Vector of vectors of the projections of the calibration pattern points, observed by the first camera.</param>
 /// <param name="imagePoints2">Vector of vectors of the projections of the calibration pattern points, observed by the second camera.</param>
 /// <param name="K1">Input/output first camera matrix.If FixIntrinsic is specified, some or all of the matrix components must be initialized.</param>
 /// <param name="D1">Input/output vector of distortion coefficients (k1,k2,k3,k4) of 4 elements.</param>
 /// <param name="K2">Input/output second camera matrix. The parameter is similar to <paramref name="K1"/> </param>
 /// <param name="D2">Input/output lens distortion coefficients for the second camera. The parameter is similar to <paramref name="D1"/></param>
 /// <param name="imageSize">Size of the image used only to initialize intrinsic camera matrix.</param>
 /// <param name="R">Output rotation matrix between the 1st and the 2nd camera coordinate systems.</param>
 /// <param name="T">Output translation vector between the coordinate systems of the cameras.</param>
 /// <param name="flags">Fish eye calibration flags</param>
 /// <param name="criteria">Termination criteria for the iterative optimization algorithm.</param>
 public static void StereoCalibrate(IInputArray objectPoints, IInputArray imagePoints1,
    IInputArray imagePoints2, IInputOutputArray K1, IInputOutputArray D1, IInputOutputArray K2,
    IInputOutputArray D2, Size imageSize, IOutputArray R, IOutputArray T, CalibrationFlag flags, MCvTermCriteria criteria)
 {
    using (InputArray iaObjectPoints = objectPoints.GetInputArray())
    using (InputArray iaImagePoints1 = imagePoints1.GetInputArray())
    using (InputArray iaImagePoints2 = imagePoints2.GetInputArray())
    using (InputOutputArray ioaK1 = K1.GetInputOutputArray())
    using (InputOutputArray ioaD1 = D1.GetInputOutputArray())
    using (InputOutputArray ioaK2 = K2.GetInputOutputArray())
    using (InputOutputArray ioaD2 = D2.GetInputOutputArray())
    using (OutputArray oaR = R.GetOutputArray())
    using (OutputArray oaT = T.GetOutputArray())
    {
       CvInvoke.cveFisheyeStereoCalibrate(iaObjectPoints, iaImagePoints1, iaImagePoints2, ioaK1, ioaD1, ioaK2, ioaD2,
          ref imageSize, oaR, oaT, (int)flags, ref criteria);
    }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Performs camera calibaration.
 /// </summary>
 /// <param name="objectPoints">vector of vectors of calibration pattern points in the calibration pattern coordinate space.</param>
 /// <param name="imagePoints">vector of vectors of the projections of calibration pattern points. imagePoints.size() and objectPoints.size() and imagePoints[i].size() must be equal to objectPoints[i].size() for each i.</param>
 /// <param name="imageSize">Size of the image used only to initialize the intrinsic camera matrix.</param>
 /// <param name="K">Output 3x3 floating-point camera matrix. If UseIntrisicGuess is specified, some or all of fx, fy, cx, cy must be initialized before calling the function. </param>
 /// <param name="D">Output vector of distortion coefficients (k1,k2,k3,k4).</param>
 /// <param name="rvecs">Output vector of rotation vectors (see Rodrigues ) estimated for each pattern view. That is, each k-th rotation vector together with the corresponding k-th translation vector (see the next output parameter description) brings the calibration pattern from the model coordinate space (in which object points are specified) to the world coordinate space, that is, a real position of the calibration pattern in the k-th pattern view (k=0.. M -1).</param>
 /// <param name="tvecs">Output vector of translation vectors estimated for each pattern view.</param>
 /// <param name="flags">Different flags</param>
 /// <param name="criteria">Termination criteria for the iterative optimization algorithm.</param>
 public static void Calibrate(IInputArray objectPoints, IInputArray imagePoints, Size imageSize,
    IInputOutputArray K, IInputOutputArray D, IOutputArray rvecs, IOutputArray tvecs, CalibrationFlag flags,
    MCvTermCriteria criteria)
 {
    using (InputArray iaObjectPoints = objectPoints.GetInputArray())
    using (InputArray iaImagePoints = imagePoints.GetInputArray())
    using (InputOutputArray ioaK = K.GetInputOutputArray())
    using (InputOutputArray ioaD = D.GetInputOutputArray())
    using (OutputArray oaRvecs = rvecs.GetOutputArray())
    using (OutputArray oaTvecs = tvecs.GetOutputArray())
    {
       CvInvoke.cveFisheyeCalibrate(iaObjectPoints, iaImagePoints, ref imageSize, ioaK, ioaD, oaRvecs, oaTvecs,
         (int)flags, ref criteria);
    }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Performs stereo calibration.
 /// </summary>
 /// <param name="objectPoints">Vector of vectors of the calibration pattern points.</param>
 /// <param name="imagePoints1">Vector of vectors of the projections of the calibration pattern points, observed by the first camera.</param>
 /// <param name="imagePoints2">Vector of vectors of the projections of the calibration pattern points, observed by the second camera.</param>
 /// <param name="K1">Input/output first camera matrix.If FixIntrinsic is specified, some or all of the matrix components must be initialized.</param>
 /// <param name="D1">Input/output vector of distortion coefficients (k1,k2,k3,k4) of 4 elements.</param>
 /// <param name="K2">Input/output second camera matrix. The parameter is similar to <paramref name="K1"/> </param>
 /// <param name="D2">Input/output lens distortion coefficients for the second camera. The parameter is similar to <paramref name="D1"/></param>
 /// <param name="imageSize">Size of the image used only to initialize intrinsic camera matrix.</param>
 /// <param name="R">Output rotation matrix between the 1st and the 2nd camera coordinate systems.</param>
 /// <param name="T">Output translation vector between the coordinate systems of the cameras.</param>
 /// <param name="flags">Fish eye calibration flags</param>
 /// <param name="criteria">Termination criteria for the iterative optimization algorithm.</param>
 public static double StereoCalibrate(IInputArray objectPoints, IInputArray imagePoints1,
                                      IInputArray imagePoints2, IInputOutputArray K1, IInputOutputArray D1, IInputOutputArray K2,
                                      IInputOutputArray D2, Size imageSize, IOutputArray R, IOutputArray T, CalibrationFlag flags, MCvTermCriteria criteria)
 {
     using (InputArray iaObjectPoints = objectPoints.GetInputArray())
         using (InputArray iaImagePoints1 = imagePoints1.GetInputArray())
             using (InputArray iaImagePoints2 = imagePoints2.GetInputArray())
                 using (InputOutputArray ioaK1 = K1.GetInputOutputArray())
                     using (InputOutputArray ioaD1 = D1.GetInputOutputArray())
                         using (InputOutputArray ioaK2 = K2.GetInputOutputArray())
                             using (InputOutputArray ioaD2 = D2.GetInputOutputArray())
                                 using (OutputArray oaR = R.GetOutputArray())
                                     using (OutputArray oaT = T.GetOutputArray())
                                     {
                                         return(CvInvoke.cveFisheyeStereoCalibrate(
                                                    iaObjectPoints,
                                                    iaImagePoints1,
                                                    iaImagePoints2,
                                                    ioaK1,
                                                    ioaD1,
                                                    ioaK2,
                                                    ioaD2,
                                                    ref imageSize,
                                                    oaR,
                                                    oaT,
                                                    (int)flags,
                                                    ref criteria));
                                     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Performs camera calibration.
 /// </summary>
 /// <param name="objectPoints">vector of vectors of calibration pattern points in the calibration pattern coordinate space.</param>
 /// <param name="imagePoints">vector of vectors of the projections of calibration pattern points. imagePoints.size() and objectPoints.size() and imagePoints[i].size() must be equal to objectPoints[i].size() for each i.</param>
 /// <param name="imageSize">Size of the image used only to initialize the intrinsic camera matrix.</param>
 /// <param name="K">Output 3x3 floating-point camera matrix. If UseIntrisicGuess is specified, some or all of fx, fy, cx, cy must be initialized before calling the function. </param>
 /// <param name="D">Output vector of distortion coefficients (k1,k2,k3,k4).</param>
 /// <param name="rvecs">Output vector of rotation vectors (see Rodrigues ) estimated for each pattern view. That is, each k-th rotation vector together with the corresponding k-th translation vector (see the next output parameter description) brings the calibration pattern from the model coordinate space (in which object points are specified) to the world coordinate space, that is, a real position of the calibration pattern in the k-th pattern view (k=0.. M -1).</param>
 /// <param name="tvecs">Output vector of translation vectors estimated for each pattern view.</param>
 /// <param name="flags">Different flags</param>
 /// <param name="criteria">Termination criteria for the iterative optimization algorithm.</param>
 public static double Calibrate(IInputArray objectPoints, IInputArray imagePoints, Size imageSize,
                                IInputOutputArray K, IInputOutputArray D, IOutputArray rvecs, IOutputArray tvecs, CalibrationFlag flags,
                                MCvTermCriteria criteria)
 {
     using (InputArray iaObjectPoints = objectPoints.GetInputArray())
         using (InputArray iaImagePoints = imagePoints.GetInputArray())
             using (InputOutputArray ioaK = K.GetInputOutputArray())
                 using (InputOutputArray ioaD = D.GetInputOutputArray())
                     using (OutputArray oaRvecs = rvecs.GetOutputArray())
                         using (OutputArray oaTvecs = tvecs.GetOutputArray())
                         {
                             return(CvInvoke.cveFisheyeCalibrate(
                                        iaObjectPoints,
                                        iaImagePoints,
                                        ref imageSize,
                                        ioaK,
                                        ioaD,
                                        oaRvecs,
                                        oaTvecs,
                                        (int)flags,
                                        ref criteria));
                         }
 }