Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RZ_A2M_Mbed_samples
calib3d.hpp
00001 /*M/////////////////////////////////////////////////////////////////////////////////////// 00002 // 00003 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 00004 // 00005 // By downloading, copying, installing or using the software you agree to this license. 00006 // If you do not agree to this license, do not download, install, 00007 // copy or use the software. 00008 // 00009 // 00010 // License Agreement 00011 // For Open Source Computer Vision Library 00012 // 00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved. 00015 // Copyright (C) 2013, OpenCV Foundation, all rights reserved. 00016 // Third party copyrights are property of their respective owners. 00017 // 00018 // Redistribution and use in source and binary forms, with or without modification, 00019 // are permitted provided that the following conditions are met: 00020 // 00021 // * Redistribution's of source code must retain the above copyright notice, 00022 // this list of conditions and the following disclaimer. 00023 // 00024 // * Redistribution's in binary form must reproduce the above copyright notice, 00025 // this list of conditions and the following disclaimer in the documentation 00026 // and/or other materials provided with the distribution. 00027 // 00028 // * The name of the copyright holders may not be used to endorse or promote products 00029 // derived from this software without specific prior written permission. 00030 // 00031 // This software is provided by the copyright holders and contributors "as is" and 00032 // any express or implied warranties, including, but not limited to, the implied 00033 // warranties of merchantability and fitness for a particular purpose are disclaimed. 00034 // In no event shall the Intel Corporation or contributors be liable for any direct, 00035 // indirect, incidental, special, exemplary, or consequential damages 00036 // (including, but not limited to, procurement of substitute goods or services; 00037 // loss of use, data, or profits; or business interruption) however caused 00038 // and on any theory of liability, whether in contract, strict liability, 00039 // or tort (including negligence or otherwise) arising in any way out of 00040 // the use of this software, even if advised of the possibility of such damage. 00041 // 00042 //M*/ 00043 00044 #ifndef OPENCV_CALIB3D_HPP 00045 #define OPENCV_CALIB3D_HPP 00046 00047 #include "opencv2/core.hpp" 00048 #include "opencv2/features2d.hpp" 00049 #include "opencv2/core/affine.hpp" 00050 00051 /** 00052 @defgroup calib3d Camera Calibration and 3D Reconstruction 00053 00054 The functions in this section use a so-called pinhole camera model. In this model, a scene view is 00055 formed by projecting 3D points into the image plane using a perspective transformation. 00056 00057 \f[s \; m' = A [R|t] M'\f] 00058 00059 or 00060 00061 \f[s \vecthree{u}{v}{1} = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1} 00062 \begin{bmatrix} 00063 r_{11} & r_{12} & r_{13} & t_1 \\ 00064 r_{21} & r_{22} & r_{23} & t_2 \\ 00065 r_{31} & r_{32} & r_{33} & t_3 00066 \end{bmatrix} 00067 \begin{bmatrix} 00068 X \\ 00069 Y \\ 00070 Z \\ 00071 1 00072 \end{bmatrix}\f] 00073 00074 where: 00075 00076 - \f$(X, Y, Z)\f$ are the coordinates of a 3D point in the world coordinate space 00077 - \f$(u, v)\f$ are the coordinates of the projection point in pixels 00078 - \f$A\f$ is a camera matrix, or a matrix of intrinsic parameters 00079 - \f$(cx, cy)\f$ is a principal point that is usually at the image center 00080 - \f$fx, fy\f$ are the focal lengths expressed in pixel units. 00081 00082 Thus, if an image from the camera is scaled by a factor, all of these parameters should be scaled 00083 (multiplied/divided, respectively) by the same factor. The matrix of intrinsic parameters does not 00084 depend on the scene viewed. So, once estimated, it can be re-used as long as the focal length is 00085 fixed (in case of zoom lens). The joint rotation-translation matrix \f$[R|t]\f$ is called a matrix of 00086 extrinsic parameters. It is used to describe the camera motion around a static scene, or vice versa, 00087 rigid motion of an object in front of a still camera. That is, \f$[R|t]\f$ translates coordinates of a 00088 point \f$(X, Y, Z)\f$ to a coordinate system, fixed with respect to the camera. The transformation above 00089 is equivalent to the following (when \f$z \ne 0\f$ ): 00090 00091 \f[\begin{array}{l} 00092 \vecthree{x}{y}{z} = R \vecthree{X}{Y}{Z} + t \\ 00093 x' = x/z \\ 00094 y' = y/z \\ 00095 u = f_x*x' + c_x \\ 00096 v = f_y*y' + c_y 00097 \end{array}\f] 00098 00099 The following figure illustrates the pinhole camera model. 00100 00101  00102 00103 Real lenses usually have some distortion, mostly radial distortion and slight tangential distortion. 00104 So, the above model is extended as: 00105 00106 \f[\begin{array}{l} 00107 \vecthree{x}{y}{z} = R \vecthree{X}{Y}{Z} + t \\ 00108 x' = x/z \\ 00109 y' = y/z \\ 00110 x'' = x' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} + 2 p_1 x' y' + p_2(r^2 + 2 x'^2) + s_1 r^2 + s_2 r^4 \\ 00111 y'' = y' \frac{1 + k_1 r^2 + k_2 r^4 + k_3 r^6}{1 + k_4 r^2 + k_5 r^4 + k_6 r^6} + p_1 (r^2 + 2 y'^2) + 2 p_2 x' y' + s_3 r^2 + s_4 r^4 \\ 00112 \text{where} \quad r^2 = x'^2 + y'^2 \\ 00113 u = f_x*x'' + c_x \\ 00114 v = f_y*y'' + c_y 00115 \end{array}\f] 00116 00117 \f$k_1\f$, \f$k_2\f$, \f$k_3\f$, \f$k_4\f$, \f$k_5\f$, and \f$k_6\f$ are radial distortion coefficients. \f$p_1\f$ and \f$p_2\f$ are 00118 tangential distortion coefficients. \f$s_1\f$, \f$s_2\f$, \f$s_3\f$, and \f$s_4\f$, are the thin prism distortion 00119 coefficients. Higher-order coefficients are not considered in OpenCV. 00120 00121 The next figure shows two common types of radial distortion: barrel distortion (typically \f$ k_1 > 0 \f$ and pincushion distortion (typically \f$ k_1 < 0 \f$). 00122 00123  00124 00125 In some cases the image sensor may be tilted in order to focus an oblique plane in front of the 00126 camera (Scheimpfug condition). This can be useful for particle image velocimetry (PIV) or 00127 triangulation with a laser fan. The tilt causes a perspective distortion of \f$x''\f$ and 00128 \f$y''\f$. This distortion can be modelled in the following way, see e.g. @cite Louhichi07. 00129 00130 \f[\begin{array}{l} 00131 s\vecthree{x'''}{y'''}{1} = 00132 \vecthreethree{R_{33}(\tau_x, \tau_y)}{0}{-R_{13}(\tau_x, \tau_y)} 00133 {0}{R_{33}(\tau_x, \tau_y)}{-R_{23}(\tau_x, \tau_y)} 00134 {0}{0}{1} R(\tau_x, \tau_y) \vecthree{x''}{y''}{1}\\ 00135 u = f_x*x''' + c_x \\ 00136 v = f_y*y''' + c_y 00137 \end{array}\f] 00138 00139 where the matrix \f$R(\tau_x, \tau_y)\f$ is defined by two rotations with angular parameter \f$\tau_x\f$ 00140 and \f$\tau_y\f$, respectively, 00141 00142 \f[ 00143 R(\tau_x, \tau_y) = 00144 \vecthreethree{\cos(\tau_y)}{0}{-\sin(\tau_y)}{0}{1}{0}{\sin(\tau_y)}{0}{\cos(\tau_y)} 00145 \vecthreethree{1}{0}{0}{0}{\cos(\tau_x)}{\sin(\tau_x)}{0}{-\sin(\tau_x)}{\cos(\tau_x)} = 00146 \vecthreethree{\cos(\tau_y)}{\sin(\tau_y)\sin(\tau_x)}{-\sin(\tau_y)\cos(\tau_x)} 00147 {0}{\cos(\tau_x)}{\sin(\tau_x)} 00148 {\sin(\tau_y)}{-\cos(\tau_y)\sin(\tau_x)}{\cos(\tau_y)\cos(\tau_x)}. 00149 \f] 00150 00151 In the functions below the coefficients are passed or returned as 00152 00153 \f[(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f] 00154 00155 vector. That is, if the vector contains four elements, it means that \f$k_3=0\f$ . The distortion 00156 coefficients do not depend on the scene viewed. Thus, they also belong to the intrinsic camera 00157 parameters. And they remain the same regardless of the captured image resolution. If, for example, a 00158 camera has been calibrated on images of 320 x 240 resolution, absolutely the same distortion 00159 coefficients can be used for 640 x 480 images from the same camera while \f$f_x\f$, \f$f_y\f$, \f$c_x\f$, and 00160 \f$c_y\f$ need to be scaled appropriately. 00161 00162 The functions below use the above model to do the following: 00163 00164 - Project 3D points to the image plane given intrinsic and extrinsic parameters. 00165 - Compute extrinsic parameters given intrinsic parameters, a few 3D points, and their 00166 projections. 00167 - Estimate intrinsic and extrinsic camera parameters from several views of a known calibration 00168 pattern (every view is described by several 3D-2D point correspondences). 00169 - Estimate the relative position and orientation of the stereo camera "heads" and compute the 00170 *rectification* transformation that makes the camera optical axes parallel. 00171 00172 @note 00173 - A calibration sample for 3 cameras in horizontal position can be found at 00174 opencv_source_code/samples/cpp/3calibration.cpp 00175 - A calibration sample based on a sequence of images can be found at 00176 opencv_source_code/samples/cpp/calibration.cpp 00177 - A calibration sample in order to do 3D reconstruction can be found at 00178 opencv_source_code/samples/cpp/build3dmodel.cpp 00179 - A calibration sample of an artificially generated camera and chessboard patterns can be 00180 found at opencv_source_code/samples/cpp/calibration_artificial.cpp 00181 - A calibration example on stereo calibration can be found at 00182 opencv_source_code/samples/cpp/stereo_calib.cpp 00183 - A calibration example on stereo matching can be found at 00184 opencv_source_code/samples/cpp/stereo_match.cpp 00185 - (Python) A camera calibration sample can be found at 00186 opencv_source_code/samples/python/calibrate.py 00187 00188 @{ 00189 @defgroup calib3d_fisheye Fisheye camera model 00190 00191 Definitions: Let P be a point in 3D of coordinates X in the world reference frame (stored in the 00192 matrix X) The coordinate vector of P in the camera reference frame is: 00193 00194 \f[Xc = R X + T\f] 00195 00196 where R is the rotation matrix corresponding to the rotation vector om: R = rodrigues(om); call x, y 00197 and z the 3 coordinates of Xc: 00198 00199 \f[x = Xc_1 \\ y = Xc_2 \\ z = Xc_3\f] 00200 00201 The pinhole projection coordinates of P is [a; b] where 00202 00203 \f[a = x / z \ and \ b = y / z \\ r^2 = a^2 + b^2 \\ \theta = atan(r)\f] 00204 00205 Fisheye distortion: 00206 00207 \f[\theta_d = \theta (1 + k_1 \theta^2 + k_2 \theta^4 + k_3 \theta^6 + k_4 \theta^8)\f] 00208 00209 The distorted point coordinates are [x'; y'] where 00210 00211 \f[x' = (\theta_d / r) a \\ y' = (\theta_d / r) b \f] 00212 00213 Finally, conversion into pixel coordinates: The final pixel coordinates vector [u; v] where: 00214 00215 \f[u = f_x (x' + \alpha y') + c_x \\ 00216 v = f_y y' + c_y\f] 00217 00218 @defgroup calib3d_c C API 00219 00220 @} 00221 */ 00222 00223 namespace cv 00224 { 00225 00226 //! @addtogroup calib3d 00227 //! @{ 00228 00229 //! type of the robust estimation algorithm 00230 enum { LMEDS = 4, //!< least-median algorithm 00231 RANSAC = 8, //!< RANSAC algorithm 00232 RHO = 16 //!< RHO algorithm 00233 }; 00234 00235 enum { SOLVEPNP_ITERATIVE = 0, 00236 SOLVEPNP_EPNP = 1, //!< EPnP: Efficient Perspective-n-Point Camera Pose Estimation @cite lepetit2009epnp 00237 SOLVEPNP_P3P = 2, //!< Complete Solution Classification for the Perspective-Three-Point Problem @cite gao2003complete 00238 SOLVEPNP_DLS = 3, //!< A Direct Least-Squares (DLS) Method for PnP @cite hesch2011direct 00239 SOLVEPNP_UPNP = 4 //!< Exhaustive Linearization for Robust Camera Pose and Focal Length Estimation @cite penate2013exhaustive 00240 00241 }; 00242 00243 enum { CALIB_CB_ADAPTIVE_THRESH = 1, 00244 CALIB_CB_NORMALIZE_IMAGE = 2, 00245 CALIB_CB_FILTER_QUADS = 4, 00246 CALIB_CB_FAST_CHECK = 8 00247 }; 00248 00249 enum { CALIB_CB_SYMMETRIC_GRID = 1, 00250 CALIB_CB_ASYMMETRIC_GRID = 2, 00251 CALIB_CB_CLUSTERING = 4 00252 }; 00253 00254 enum { CALIB_USE_INTRINSIC_GUESS = 0x00001, 00255 CALIB_FIX_ASPECT_RATIO = 0x00002, 00256 CALIB_FIX_PRINCIPAL_POINT = 0x00004, 00257 CALIB_ZERO_TANGENT_DIST = 0x00008, 00258 CALIB_FIX_FOCAL_LENGTH = 0x00010, 00259 CALIB_FIX_K1 = 0x00020, 00260 CALIB_FIX_K2 = 0x00040, 00261 CALIB_FIX_K3 = 0x00080, 00262 CALIB_FIX_K4 = 0x00800, 00263 CALIB_FIX_K5 = 0x01000, 00264 CALIB_FIX_K6 = 0x02000, 00265 CALIB_RATIONAL_MODEL = 0x04000, 00266 CALIB_THIN_PRISM_MODEL = 0x08000, 00267 CALIB_FIX_S1_S2_S3_S4 = 0x10000, 00268 CALIB_TILTED_MODEL = 0x40000, 00269 CALIB_FIX_TAUX_TAUY = 0x80000, 00270 CALIB_USE_QR = 0x100000, //!< use QR instead of SVD decomposition for solving. Faster but potentially less precise 00271 // only for stereo 00272 CALIB_FIX_INTRINSIC = 0x00100, 00273 CALIB_SAME_FOCAL_LENGTH = 0x00200, 00274 // for stereo rectification 00275 CALIB_ZERO_DISPARITY = 0x00400, 00276 CALIB_USE_LU = (1 << 17), //!< use LU instead of SVD decomposition for solving. much faster but potentially less precise 00277 }; 00278 00279 //! the algorithm for finding fundamental matrix 00280 enum { FM_7POINT = 1, //!< 7-point algorithm 00281 FM_8POINT = 2, //!< 8-point algorithm 00282 FM_LMEDS = 4, //!< least-median algorithm 00283 FM_RANSAC = 8 //!< RANSAC algorithm 00284 }; 00285 00286 00287 00288 /** @brief Converts a rotation matrix to a rotation vector or vice versa. 00289 00290 @param src Input rotation vector (3x1 or 1x3) or rotation matrix (3x3). 00291 @param dst Output rotation matrix (3x3) or rotation vector (3x1 or 1x3), respectively. 00292 @param jacobian Optional output Jacobian matrix, 3x9 or 9x3, which is a matrix of partial 00293 derivatives of the output array components with respect to the input array components. 00294 00295 \f[\begin{array}{l} \theta \leftarrow norm(r) \\ r \leftarrow r/ \theta \\ R = \cos{\theta} I + (1- \cos{\theta} ) r r^T + \sin{\theta} \vecthreethree{0}{-r_z}{r_y}{r_z}{0}{-r_x}{-r_y}{r_x}{0} \end{array}\f] 00296 00297 Inverse transformation can be also done easily, since 00298 00299 \f[\sin ( \theta ) \vecthreethree{0}{-r_z}{r_y}{r_z}{0}{-r_x}{-r_y}{r_x}{0} = \frac{R - R^T}{2}\f] 00300 00301 A rotation vector is a convenient and most compact representation of a rotation matrix (since any 00302 rotation matrix has just 3 degrees of freedom). The representation is used in the global 3D geometry 00303 optimization procedures like calibrateCamera, stereoCalibrate, or solvePnP . 00304 */ 00305 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() ); 00306 00307 /** @brief Finds a perspective transformation between two planes. 00308 00309 @param srcPoints Coordinates of the points in the original plane, a matrix of the type CV_32FC2 00310 or vector<Point2f> . 00311 @param dstPoints Coordinates of the points in the target plane, a matrix of the type CV_32FC2 or 00312 a vector<Point2f> . 00313 @param method Method used to computed a homography matrix. The following methods are possible: 00314 - **0** - a regular method using all the points 00315 - **RANSAC** - RANSAC-based robust method 00316 - **LMEDS** - Least-Median robust method 00317 - **RHO** - PROSAC-based robust method 00318 @param ransacReprojThreshold Maximum allowed reprojection error to treat a point pair as an inlier 00319 (used in the RANSAC and RHO methods only). That is, if 00320 \f[\| \texttt{dstPoints} _i - \texttt{convertPointsHomogeneous} ( \texttt{H} * \texttt{srcPoints} _i) \| > \texttt{ransacReprojThreshold}\f] 00321 then the point \f$i\f$ is considered an outlier. If srcPoints and dstPoints are measured in pixels, 00322 it usually makes sense to set this parameter somewhere in the range of 1 to 10. 00323 @param mask Optional output mask set by a robust method ( RANSAC or LMEDS ). Note that the input 00324 mask values are ignored. 00325 @param maxIters The maximum number of RANSAC iterations, 2000 is the maximum it can be. 00326 @param confidence Confidence level, between 0 and 1. 00327 00328 The function finds and returns the perspective transformation \f$H\f$ between the source and the 00329 destination planes: 00330 00331 \f[s_i \vecthree{x'_i}{y'_i}{1} \sim H \vecthree{x_i}{y_i}{1}\f] 00332 00333 so that the back-projection error 00334 00335 \f[\sum _i \left ( x'_i- \frac{h_{11} x_i + h_{12} y_i + h_{13}}{h_{31} x_i + h_{32} y_i + h_{33}} \right )^2+ \left ( y'_i- \frac{h_{21} x_i + h_{22} y_i + h_{23}}{h_{31} x_i + h_{32} y_i + h_{33}} \right )^2\f] 00336 00337 is minimized. If the parameter method is set to the default value 0, the function uses all the point 00338 pairs to compute an initial homography estimate with a simple least-squares scheme. 00339 00340 However, if not all of the point pairs ( \f$srcPoints_i\f$, \f$dstPoints_i\f$ ) fit the rigid perspective 00341 transformation (that is, there are some outliers), this initial estimate will be poor. In this case, 00342 you can use one of the three robust methods. The methods RANSAC, LMeDS and RHO try many different 00343 random subsets of the corresponding point pairs (of four pairs each), estimate the homography matrix 00344 using this subset and a simple least-square algorithm, and then compute the quality/goodness of the 00345 computed homography (which is the number of inliers for RANSAC or the median re-projection error for 00346 LMeDs). The best subset is then used to produce the initial estimate of the homography matrix and 00347 the mask of inliers/outliers. 00348 00349 Regardless of the method, robust or not, the computed homography matrix is refined further (using 00350 inliers only in case of a robust method) with the Levenberg-Marquardt method to reduce the 00351 re-projection error even more. 00352 00353 The methods RANSAC and RHO can handle practically any ratio of outliers but need a threshold to 00354 distinguish inliers from outliers. The method LMeDS does not need any threshold but it works 00355 correctly only when there are more than 50% of inliers. Finally, if there are no outliers and the 00356 noise is rather small, use the default method (method=0). 00357 00358 The function is used to find initial intrinsic and extrinsic matrices. Homography matrix is 00359 determined up to a scale. Thus, it is normalized so that \f$h_{33}=1\f$. Note that whenever an H matrix 00360 cannot be estimated, an empty one will be returned. 00361 00362 @sa 00363 getAffineTransform, estimateAffine2D, estimateAffinePartial2D, getPerspectiveTransform, warpPerspective, 00364 perspectiveTransform 00365 00366 00367 @note 00368 - A example on calculating a homography for image matching can be found at 00369 opencv_source_code/samples/cpp/video_homography.cpp 00370 00371 */ 00372 CV_EXPORTS_W Mat findHomography( InputArray srcPoints, InputArray dstPoints, 00373 int method = 0, double ransacReprojThreshold = 3, 00374 OutputArray mask=noArray(), const int maxIters = 2000, 00375 const double confidence = 0.995); 00376 00377 /** @overload */ 00378 CV_EXPORTS Mat findHomography( InputArray srcPoints, InputArray dstPoints, 00379 OutputArray mask, int method = 0, double ransacReprojThreshold = 3 ); 00380 00381 /** @brief Computes an RQ decomposition of 3x3 matrices. 00382 00383 @param src 3x3 input matrix. 00384 @param mtxR Output 3x3 upper-triangular matrix. 00385 @param mtxQ Output 3x3 orthogonal matrix. 00386 @param Qx Optional output 3x3 rotation matrix around x-axis. 00387 @param Qy Optional output 3x3 rotation matrix around y-axis. 00388 @param Qz Optional output 3x3 rotation matrix around z-axis. 00389 00390 The function computes a RQ decomposition using the given rotations. This function is used in 00391 decomposeProjectionMatrix to decompose the left 3x3 submatrix of a projection matrix into a camera 00392 and a rotation matrix. 00393 00394 It optionally returns three rotation matrices, one for each axis, and the three Euler angles in 00395 degrees (as the return value) that could be used in OpenGL. Note, there is always more than one 00396 sequence of rotations about the three principal axes that results in the same orientation of an 00397 object, eg. see @cite Slabaugh . Returned tree rotation matrices and corresponding three Euler angules 00398 are only one of the possible solutions. 00399 */ 00400 CV_EXPORTS_W Vec3d RQDecomp3x3( InputArray src, OutputArray mtxR, OutputArray mtxQ, 00401 OutputArray Qx = noArray(), 00402 OutputArray Qy = noArray(), 00403 OutputArray Qz = noArray()); 00404 00405 /** @brief Decomposes a projection matrix into a rotation matrix and a camera matrix. 00406 00407 @param projMatrix 3x4 input projection matrix P. 00408 @param cameraMatrix Output 3x3 camera matrix K. 00409 @param rotMatrix Output 3x3 external rotation matrix R. 00410 @param transVect Output 4x1 translation vector T. 00411 @param rotMatrixX Optional 3x3 rotation matrix around x-axis. 00412 @param rotMatrixY Optional 3x3 rotation matrix around y-axis. 00413 @param rotMatrixZ Optional 3x3 rotation matrix around z-axis. 00414 @param eulerAngles Optional three-element vector containing three Euler angles of rotation in 00415 degrees. 00416 00417 The function computes a decomposition of a projection matrix into a calibration and a rotation 00418 matrix and the position of a camera. 00419 00420 It optionally returns three rotation matrices, one for each axis, and three Euler angles that could 00421 be used in OpenGL. Note, there is always more than one sequence of rotations about the three 00422 principal axes that results in the same orientation of an object, eg. see @cite Slabaugh . Returned 00423 tree rotation matrices and corresponding three Euler angules are only one of the possible solutions. 00424 00425 The function is based on RQDecomp3x3 . 00426 */ 00427 CV_EXPORTS_W void decomposeProjectionMatrix( InputArray projMatrix, OutputArray cameraMatrix, 00428 OutputArray rotMatrix, OutputArray transVect, 00429 OutputArray rotMatrixX = noArray(), 00430 OutputArray rotMatrixY = noArray(), 00431 OutputArray rotMatrixZ = noArray(), 00432 OutputArray eulerAngles =noArray() ); 00433 00434 /** @brief Computes partial derivatives of the matrix product for each multiplied matrix. 00435 00436 @param A First multiplied matrix. 00437 @param B Second multiplied matrix. 00438 @param dABdA First output derivative matrix d(A\*B)/dA of size 00439 \f$\texttt{A.rows*B.cols} \times {A.rows*A.cols}\f$ . 00440 @param dABdB Second output derivative matrix d(A\*B)/dB of size 00441 \f$\texttt{A.rows*B.cols} \times {B.rows*B.cols}\f$ . 00442 00443 The function computes partial derivatives of the elements of the matrix product \f$A*B\f$ with regard to 00444 the elements of each of the two input matrices. The function is used to compute the Jacobian 00445 matrices in stereoCalibrate but can also be used in any other similar optimization function. 00446 */ 00447 CV_EXPORTS_W void matMulDeriv( InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB ); 00448 00449 /** @brief Combines two rotation-and-shift transformations. 00450 00451 @param rvec1 First rotation vector. 00452 @param tvec1 First translation vector. 00453 @param rvec2 Second rotation vector. 00454 @param tvec2 Second translation vector. 00455 @param rvec3 Output rotation vector of the superposition. 00456 @param tvec3 Output translation vector of the superposition. 00457 @param dr3dr1 00458 @param dr3dt1 00459 @param dr3dr2 00460 @param dr3dt2 00461 @param dt3dr1 00462 @param dt3dt1 00463 @param dt3dr2 00464 @param dt3dt2 Optional output derivatives of rvec3 or tvec3 with regard to rvec1, rvec2, tvec1 and 00465 tvec2, respectively. 00466 00467 The functions compute: 00468 00469 \f[\begin{array}{l} \texttt{rvec3} = \mathrm{rodrigues} ^{-1} \left ( \mathrm{rodrigues} ( \texttt{rvec2} ) \cdot \mathrm{rodrigues} ( \texttt{rvec1} ) \right ) \\ \texttt{tvec3} = \mathrm{rodrigues} ( \texttt{rvec2} ) \cdot \texttt{tvec1} + \texttt{tvec2} \end{array} ,\f] 00470 00471 where \f$\mathrm{rodrigues}\f$ denotes a rotation vector to a rotation matrix transformation, and 00472 \f$\mathrm{rodrigues}^{-1}\f$ denotes the inverse transformation. See Rodrigues for details. 00473 00474 Also, the functions can compute the derivatives of the output vectors with regards to the input 00475 vectors (see matMulDeriv ). The functions are used inside stereoCalibrate but can also be used in 00476 your own code where Levenberg-Marquardt or another gradient-based solver is used to optimize a 00477 function that contains a matrix multiplication. 00478 */ 00479 CV_EXPORTS_W void composeRT( InputArray rvec1, InputArray tvec1, 00480 InputArray rvec2, InputArray tvec2, 00481 OutputArray rvec3, OutputArray tvec3, 00482 OutputArray dr3dr1 = noArray(), OutputArray dr3dt1 = noArray(), 00483 OutputArray dr3dr2 = noArray(), OutputArray dr3dt2 = noArray(), 00484 OutputArray dt3dr1 = noArray(), OutputArray dt3dt1 = noArray(), 00485 OutputArray dt3dr2 = noArray(), OutputArray dt3dt2 = noArray() ); 00486 00487 /** @brief Projects 3D points to an image plane. 00488 00489 @param objectPoints Array of object points, 3xN/Nx3 1-channel or 1xN/Nx1 3-channel (or 00490 vector<Point3f> ), where N is the number of points in the view. 00491 @param rvec Rotation vector. See Rodrigues for details. 00492 @param tvec Translation vector. 00493 @param cameraMatrix Camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$ . 00494 @param distCoeffs Input vector of distortion coefficients 00495 \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of 00496 4, 5, 8, 12 or 14 elements. If the vector is empty, the zero distortion coefficients are assumed. 00497 @param imagePoints Output array of image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, or 00498 vector<Point2f> . 00499 @param jacobian Optional output 2Nx(10+<numDistCoeffs>) jacobian matrix of derivatives of image 00500 points with respect to components of the rotation vector, translation vector, focal lengths, 00501 coordinates of the principal point and the distortion coefficients. In the old interface different 00502 components of the jacobian are returned via different output parameters. 00503 @param aspectRatio Optional "fixed aspect ratio" parameter. If the parameter is not 0, the 00504 function assumes that the aspect ratio (*fx/fy*) is fixed and correspondingly adjusts the jacobian 00505 matrix. 00506 00507 The function computes projections of 3D points to the image plane given intrinsic and extrinsic 00508 camera parameters. Optionally, the function computes Jacobians - matrices of partial derivatives of 00509 image points coordinates (as functions of all the input parameters) with respect to the particular 00510 parameters, intrinsic and/or extrinsic. The Jacobians are used during the global optimization in 00511 calibrateCamera, solvePnP, and stereoCalibrate . The function itself can also be used to compute a 00512 re-projection error given the current intrinsic and extrinsic parameters. 00513 00514 @note By setting rvec=tvec=(0,0,0) or by setting cameraMatrix to a 3x3 identity matrix, or by 00515 passing zero distortion coefficients, you can get various useful partial cases of the function. This 00516 means that you can compute the distorted coordinates for a sparse set of points or apply a 00517 perspective transformation (and also compute the derivatives) in the ideal zero-distortion setup. 00518 */ 00519 CV_EXPORTS_W void projectPoints( InputArray objectPoints, 00520 InputArray rvec, InputArray tvec, 00521 InputArray cameraMatrix, InputArray distCoeffs, 00522 OutputArray imagePoints, 00523 OutputArray jacobian = noArray(), 00524 double aspectRatio = 0 ); 00525 00526 /** @brief Finds an object pose from 3D-2D point correspondences. 00527 00528 @param objectPoints Array of object points in the object coordinate space, Nx3 1-channel or 00529 1xN/Nx1 3-channel, where N is the number of points. vector<Point3f> can be also passed here. 00530 @param imagePoints Array of corresponding image points, Nx2 1-channel or 1xN/Nx1 2-channel, 00531 where N is the number of points. vector<Point2f> can be also passed here. 00532 @param cameraMatrix Input camera matrix \f$A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1}\f$ . 00533 @param distCoeffs Input vector of distortion coefficients 00534 \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of 00535 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are 00536 assumed. 00537 @param rvec Output rotation vector (see Rodrigues ) that, together with tvec , brings points from 00538 the model coordinate system to the camera coordinate system. 00539 @param tvec Output translation vector. 00540 @param useExtrinsicGuess Parameter used for SOLVEPNP_ITERATIVE. If true (1), the function uses 00541 the provided rvec and tvec values as initial approximations of the rotation and translation 00542 vectors, respectively, and further optimizes them. 00543 @param flags Method for solving a PnP problem: 00544 - **SOLVEPNP_ITERATIVE** Iterative method is based on Levenberg-Marquardt optimization. In 00545 this case the function finds such a pose that minimizes reprojection error, that is the sum 00546 of squared distances between the observed projections imagePoints and the projected (using 00547 projectPoints ) objectPoints . 00548 - **SOLVEPNP_P3P** Method is based on the paper of X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang 00549 "Complete Solution Classification for the Perspective-Three-Point Problem". In this case the 00550 function requires exactly four object and image points. 00551 - **SOLVEPNP_EPNP** Method has been introduced by F.Moreno-Noguer, V.Lepetit and P.Fua in the 00552 paper "EPnP: Efficient Perspective-n-Point Camera Pose Estimation". 00553 - **SOLVEPNP_DLS** Method is based on the paper of Joel A. Hesch and Stergios I. Roumeliotis. 00554 "A Direct Least-Squares (DLS) Method for PnP". 00555 - **SOLVEPNP_UPNP** Method is based on the paper of A.Penate-Sanchez, J.Andrade-Cetto, 00556 F.Moreno-Noguer. "Exhaustive Linearization for Robust Camera Pose and Focal Length 00557 Estimation". In this case the function also estimates the parameters \f$f_x\f$ and \f$f_y\f$ 00558 assuming that both have the same value. Then the cameraMatrix is updated with the estimated 00559 focal length. 00560 00561 The function estimates the object pose given a set of object points, their corresponding image 00562 projections, as well as the camera matrix and the distortion coefficients. 00563 00564 @note 00565 - An example of how to use solvePnP for planar augmented reality can be found at 00566 opencv_source_code/samples/python/plane_ar.py 00567 - If you are using Python: 00568 - Numpy array slices won't work as input because solvePnP requires contiguous 00569 arrays (enforced by the assertion using cv::Mat::checkVector() around line 55 of 00570 modules/calib3d/src/solvepnp.cpp version 2.4.9) 00571 - The P3P algorithm requires image points to be in an array of shape (N,1,2) due 00572 to its calling of cv::undistortPoints (around line 75 of modules/calib3d/src/solvepnp.cpp version 2.4.9) 00573 which requires 2-channel information. 00574 - Thus, given some data D = np.array(...) where D.shape = (N,M), in order to use a subset of 00575 it as, e.g., imagePoints, one must effectively copy it into a new array: imagePoints = 00576 np.ascontiguousarray(D[:,:2]).reshape((N,1,2)) 00577 - The methods **SOLVEPNP_DLS** and **SOLVEPNP_UPNP** cannot be used as the current implementations are 00578 unstable and sometimes give completly wrong results. If you pass one of these two flags, 00579 **SOLVEPNP_EPNP** method will be used instead. 00580 */ 00581 CV_EXPORTS_W bool solvePnP( InputArray objectPoints, InputArray imagePoints, 00582 InputArray cameraMatrix, InputArray distCoeffs, 00583 OutputArray rvec, OutputArray tvec, 00584 bool useExtrinsicGuess = false, int flags = SOLVEPNP_ITERATIVE ); 00585 00586 /** @brief Finds an object pose from 3D-2D point correspondences using the RANSAC scheme. 00587 00588 @param objectPoints Array of object points in the object coordinate space, Nx3 1-channel or 00589 1xN/Nx1 3-channel, where N is the number of points. vector<Point3f> can be also passed here. 00590 @param imagePoints Array of corresponding image points, Nx2 1-channel or 1xN/Nx1 2-channel, 00591 where N is the number of points. vector<Point2f> can be also passed here. 00592 @param cameraMatrix Input camera matrix \f$A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1}\f$ . 00593 @param distCoeffs Input vector of distortion coefficients 00594 \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of 00595 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are 00596 assumed. 00597 @param rvec Output rotation vector (see Rodrigues ) that, together with tvec , brings points from 00598 the model coordinate system to the camera coordinate system. 00599 @param tvec Output translation vector. 00600 @param useExtrinsicGuess Parameter used for SOLVEPNP_ITERATIVE. If true (1), the function uses 00601 the provided rvec and tvec values as initial approximations of the rotation and translation 00602 vectors, respectively, and further optimizes them. 00603 @param iterationsCount Number of iterations. 00604 @param reprojectionError Inlier threshold value used by the RANSAC procedure. The parameter value 00605 is the maximum allowed distance between the observed and computed point projections to consider it 00606 an inlier. 00607 @param confidence The probability that the algorithm produces a useful result. 00608 @param inliers Output vector that contains indices of inliers in objectPoints and imagePoints . 00609 @param flags Method for solving a PnP problem (see solvePnP ). 00610 00611 The function estimates an object pose given a set of object points, their corresponding image 00612 projections, as well as the camera matrix and the distortion coefficients. This function finds such 00613 a pose that minimizes reprojection error, that is, the sum of squared distances between the observed 00614 projections imagePoints and the projected (using projectPoints ) objectPoints. The use of RANSAC 00615 makes the function resistant to outliers. 00616 00617 @note 00618 - An example of how to use solvePNPRansac for object detection can be found at 00619 opencv_source_code/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/ 00620 */ 00621 CV_EXPORTS_W bool solvePnPRansac( InputArray objectPoints, InputArray imagePoints, 00622 InputArray cameraMatrix, InputArray distCoeffs, 00623 OutputArray rvec, OutputArray tvec, 00624 bool useExtrinsicGuess = false, int iterationsCount = 100, 00625 float reprojectionError = 8.0, double confidence = 0.99, 00626 OutputArray inliers = noArray(), int flags = SOLVEPNP_ITERATIVE ); 00627 00628 /** @brief Finds an initial camera matrix from 3D-2D point correspondences. 00629 00630 @param objectPoints Vector of vectors of the calibration pattern points in the calibration pattern 00631 coordinate space. In the old interface all the per-view vectors are concatenated. See 00632 calibrateCamera for details. 00633 @param imagePoints Vector of vectors of the projections of the calibration pattern points. In the 00634 old interface all the per-view vectors are concatenated. 00635 @param imageSize Image size in pixels used to initialize the principal point. 00636 @param aspectRatio If it is zero or negative, both \f$f_x\f$ and \f$f_y\f$ are estimated independently. 00637 Otherwise, \f$f_x = f_y * \texttt{aspectRatio}\f$ . 00638 00639 The function estimates and returns an initial camera matrix for the camera calibration process. 00640 Currently, the function only supports planar calibration patterns, which are patterns where each 00641 object point has z-coordinate =0. 00642 */ 00643 CV_EXPORTS_W Mat initCameraMatrix2D( InputArrayOfArrays objectPoints, 00644 InputArrayOfArrays imagePoints, 00645 Size imageSize, double aspectRatio = 1.0 ); 00646 00647 /** @brief Finds the positions of internal corners of the chessboard. 00648 00649 @param image Source chessboard view. It must be an 8-bit grayscale or color image. 00650 @param patternSize Number of inner corners per a chessboard row and column 00651 ( patternSize = cvSize(points_per_row,points_per_colum) = cvSize(columns,rows) ). 00652 @param corners Output array of detected corners. 00653 @param flags Various operation flags that can be zero or a combination of the following values: 00654 - **CV_CALIB_CB_ADAPTIVE_THRESH** Use adaptive thresholding to convert the image to black 00655 and white, rather than a fixed threshold level (computed from the average image brightness). 00656 - **CV_CALIB_CB_NORMALIZE_IMAGE** Normalize the image gamma with equalizeHist before 00657 applying fixed or adaptive thresholding. 00658 - **CV_CALIB_CB_FILTER_QUADS** Use additional criteria (like contour area, perimeter, 00659 square-like shape) to filter out false quads extracted at the contour retrieval stage. 00660 - **CALIB_CB_FAST_CHECK** Run a fast check on the image that looks for chessboard corners, 00661 and shortcut the call if none is found. This can drastically speed up the call in the 00662 degenerate condition when no chessboard is observed. 00663 00664 The function attempts to determine whether the input image is a view of the chessboard pattern and 00665 locate the internal chessboard corners. The function returns a non-zero value if all of the corners 00666 are found and they are placed in a certain order (row by row, left to right in every row). 00667 Otherwise, if the function fails to find all the corners or reorder them, it returns 0. For example, 00668 a regular chessboard has 8 x 8 squares and 7 x 7 internal corners, that is, points where the black 00669 squares touch each other. The detected coordinates are approximate, and to determine their positions 00670 more accurately, the function calls cornerSubPix. You also may use the function cornerSubPix with 00671 different parameters if returned coordinates are not accurate enough. 00672 00673 Sample usage of detecting and drawing chessboard corners: : 00674 @code 00675 Size patternsize(8,6); //interior number of corners 00676 Mat gray = ....; //source image 00677 vector<Point2f> corners; //this will be filled by the detected corners 00678 00679 //CALIB_CB_FAST_CHECK saves a lot of time on images 00680 //that do not contain any chessboard corners 00681 bool patternfound = findChessboardCorners(gray, patternsize, corners, 00682 CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE 00683 + CALIB_CB_FAST_CHECK); 00684 00685 if(patternfound) 00686 cornerSubPix(gray, corners, Size(11, 11), Size(-1, -1), 00687 TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1)); 00688 00689 drawChessboardCorners(img, patternsize, Mat(corners), patternfound); 00690 @endcode 00691 @note The function requires white space (like a square-thick border, the wider the better) around 00692 the board to make the detection more robust in various environments. Otherwise, if there is no 00693 border and the background is dark, the outer black squares cannot be segmented properly and so the 00694 square grouping and ordering algorithm fails. 00695 */ 00696 CV_EXPORTS_W bool findChessboardCorners( InputArray image, Size patternSize, OutputArray corners, 00697 int flags = CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE ); 00698 00699 //! finds subpixel-accurate positions of the chessboard corners 00700 CV_EXPORTS bool find4QuadCornerSubpix( InputArray img, InputOutputArray corners, Size region_size ); 00701 00702 /** @brief Renders the detected chessboard corners. 00703 00704 @param image Destination image. It must be an 8-bit color image. 00705 @param patternSize Number of inner corners per a chessboard row and column 00706 (patternSize = cv::Size(points_per_row,points_per_column)). 00707 @param corners Array of detected corners, the output of findChessboardCorners. 00708 @param patternWasFound Parameter indicating whether the complete board was found or not. The 00709 return value of findChessboardCorners should be passed here. 00710 00711 The function draws individual chessboard corners detected either as red circles if the board was not 00712 found, or as colored corners connected with lines if the board was found. 00713 */ 00714 CV_EXPORTS_W void drawChessboardCorners( InputOutputArray image, Size patternSize, 00715 InputArray corners, bool patternWasFound ); 00716 00717 /** @brief Finds centers in the grid of circles. 00718 00719 @param image grid view of input circles; it must be an 8-bit grayscale or color image. 00720 @param patternSize number of circles per row and column 00721 ( patternSize = Size(points_per_row, points_per_colum) ). 00722 @param centers output array of detected centers. 00723 @param flags various operation flags that can be one of the following values: 00724 - **CALIB_CB_SYMMETRIC_GRID** uses symmetric pattern of circles. 00725 - **CALIB_CB_ASYMMETRIC_GRID** uses asymmetric pattern of circles. 00726 - **CALIB_CB_CLUSTERING** uses a special algorithm for grid detection. It is more robust to 00727 perspective distortions but much more sensitive to background clutter. 00728 @param blobDetector feature detector that finds blobs like dark circles on light background. 00729 00730 The function attempts to determine whether the input image contains a grid of circles. If it is, the 00731 function locates centers of the circles. The function returns a non-zero value if all of the centers 00732 have been found and they have been placed in a certain order (row by row, left to right in every 00733 row). Otherwise, if the function fails to find all the corners or reorder them, it returns 0. 00734 00735 Sample usage of detecting and drawing the centers of circles: : 00736 @code 00737 Size patternsize(7,7); //number of centers 00738 Mat gray = ....; //source image 00739 vector<Point2f> centers; //this will be filled by the detected centers 00740 00741 bool patternfound = findCirclesGrid(gray, patternsize, centers); 00742 00743 drawChessboardCorners(img, patternsize, Mat(centers), patternfound); 00744 @endcode 00745 @note The function requires white space (like a square-thick border, the wider the better) around 00746 the board to make the detection more robust in various environments. 00747 */ 00748 CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize, 00749 OutputArray centers, int flags = CALIB_CB_SYMMETRIC_GRID, 00750 const Ptr<FeatureDetector> &blobDetector = SimpleBlobDetector::create()); 00751 00752 /** @brief Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern. 00753 00754 @param objectPoints In the new interface it is a vector of vectors of calibration pattern points in 00755 the calibration pattern coordinate space (e.g. std::vector<std::vector<cv::Vec3f>>). The outer 00756 vector contains as many elements as the number of the pattern views. If the same calibration pattern 00757 is shown in each view and it is fully visible, all the vectors will be the same. Although, it is 00758 possible to use partially occluded patterns, or even different patterns in different views. Then, 00759 the vectors will be different. The points are 3D, but since they are in a pattern coordinate system, 00760 then, if the rig is planar, it may make sense to put the model to a XY coordinate plane so that 00761 Z-coordinate of each input object point is 0. 00762 In the old interface all the vectors of object points from different views are concatenated 00763 together. 00764 @param imagePoints In the new interface it is a vector of vectors of the projections of calibration 00765 pattern points (e.g. std::vector<std::vector<cv::Vec2f>>). imagePoints.size() and 00766 objectPoints.size() and imagePoints[i].size() must be equal to objectPoints[i].size() for each i. 00767 In the old interface all the vectors of object points from different views are concatenated 00768 together. 00769 @param imageSize Size of the image used only to initialize the intrinsic camera matrix. 00770 @param cameraMatrix Output 3x3 floating-point camera matrix 00771 \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . If CV\_CALIB\_USE\_INTRINSIC\_GUESS 00772 and/or CV_CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be 00773 initialized before calling the function. 00774 @param distCoeffs Output vector of distortion coefficients 00775 \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of 00776 4, 5, 8, 12 or 14 elements. 00777 @param rvecs Output vector of rotation vectors (see Rodrigues ) estimated for each pattern view 00778 (e.g. std::vector<cv::Mat>>). That is, each k-th rotation vector together with the corresponding 00779 k-th translation vector (see the next output parameter description) brings the calibration pattern 00780 from the model coordinate space (in which object points are specified) to the world coordinate 00781 space, that is, a real position of the calibration pattern in the k-th pattern view (k=0.. *M* -1). 00782 @param tvecs Output vector of translation vectors estimated for each pattern view. 00783 @param stdDeviationsIntrinsics Output vector of standard deviations estimated for intrinsic parameters. 00784 Order of deviations values: 00785 \f$(f_x, f_y, c_x, c_y, k_1, k_2, p_1, p_2, k_3, k_4, k_5, k_6 , s_1, s_2, s_3, 00786 s_4, \tau_x, \tau_y)\f$ If one of parameters is not estimated, it's deviation is equals to zero. 00787 @param stdDeviationsExtrinsics Output vector of standard deviations estimated for extrinsic parameters. 00788 Order of deviations values: \f$(R_1, T_1, \dotsc , R_M, T_M)\f$ where M is number of pattern views, 00789 \f$R_i, T_i\f$ are concatenated 1x3 vectors. 00790 @param perViewErrors Output vector of the RMS re-projection error estimated for each pattern view. 00791 @param flags Different flags that may be zero or a combination of the following values: 00792 - **CV_CALIB_USE_INTRINSIC_GUESS** cameraMatrix contains valid initial values of 00793 fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image 00794 center ( imageSize is used), and focal distances are computed in a least-squares fashion. 00795 Note, that if intrinsic parameters are known, there is no need to use this function just to 00796 estimate extrinsic parameters. Use solvePnP instead. 00797 - **CV_CALIB_FIX_PRINCIPAL_POINT** The principal point is not changed during the global 00798 optimization. It stays at the center or at a different location specified when 00799 CV_CALIB_USE_INTRINSIC_GUESS is set too. 00800 - **CV_CALIB_FIX_ASPECT_RATIO** The functions considers only fy as a free parameter. The 00801 ratio fx/fy stays the same as in the input cameraMatrix . When 00802 CV_CALIB_USE_INTRINSIC_GUESS is not set, the actual input values of fx and fy are 00803 ignored, only their ratio is computed and used further. 00804 - **CV_CALIB_ZERO_TANGENT_DIST** Tangential distortion coefficients \f$(p_1, p_2)\f$ are set 00805 to zeros and stay zero. 00806 - **CV_CALIB_FIX_K1,...,CV_CALIB_FIX_K6** The corresponding radial distortion 00807 coefficient is not changed during the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is 00808 set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0. 00809 - **CV_CALIB_RATIONAL_MODEL** Coefficients k4, k5, and k6 are enabled. To provide the 00810 backward compatibility, this extra flag should be explicitly specified to make the 00811 calibration function use the rational model and return 8 coefficients. If the flag is not 00812 set, the function computes and returns only 5 distortion coefficients. 00813 - **CALIB_THIN_PRISM_MODEL** Coefficients s1, s2, s3 and s4 are enabled. To provide the 00814 backward compatibility, this extra flag should be explicitly specified to make the 00815 calibration function use the thin prism model and return 12 coefficients. If the flag is not 00816 set, the function computes and returns only 5 distortion coefficients. 00817 - **CALIB_FIX_S1_S2_S3_S4** The thin prism distortion coefficients are not changed during 00818 the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the 00819 supplied distCoeffs matrix is used. Otherwise, it is set to 0. 00820 - **CALIB_TILTED_MODEL** Coefficients tauX and tauY are enabled. To provide the 00821 backward compatibility, this extra flag should be explicitly specified to make the 00822 calibration function use the tilted sensor model and return 14 coefficients. If the flag is not 00823 set, the function computes and returns only 5 distortion coefficients. 00824 - **CALIB_FIX_TAUX_TAUY** The coefficients of the tilted sensor model are not changed during 00825 the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the 00826 supplied distCoeffs matrix is used. Otherwise, it is set to 0. 00827 @param criteria Termination criteria for the iterative optimization algorithm. 00828 00829 @return the overall RMS re-projection error. 00830 00831 The function estimates the intrinsic camera parameters and extrinsic parameters for each of the 00832 views. The algorithm is based on @cite Zhang2000 and @cite BouguetMCT . The coordinates of 3D object 00833 points and their corresponding 2D projections in each view must be specified. That may be achieved 00834 by using an object with a known geometry and easily detectable feature points. Such an object is 00835 called a calibration rig or calibration pattern, and OpenCV has built-in support for a chessboard as 00836 a calibration rig (see findChessboardCorners ). Currently, initialization of intrinsic parameters 00837 (when CV_CALIB_USE_INTRINSIC_GUESS is not set) is only implemented for planar calibration 00838 patterns (where Z-coordinates of the object points must be all zeros). 3D calibration rigs can also 00839 be used as long as initial cameraMatrix is provided. 00840 00841 The algorithm performs the following steps: 00842 00843 - Compute the initial intrinsic parameters (the option only available for planar calibration 00844 patterns) or read them from the input parameters. The distortion coefficients are all set to 00845 zeros initially unless some of CV_CALIB_FIX_K? are specified. 00846 00847 - Estimate the initial camera pose as if the intrinsic parameters have been already known. This is 00848 done using solvePnP . 00849 00850 - Run the global Levenberg-Marquardt optimization algorithm to minimize the reprojection error, 00851 that is, the total sum of squared distances between the observed feature points imagePoints and 00852 the projected (using the current estimates for camera parameters and the poses) object points 00853 objectPoints. See projectPoints for details. 00854 00855 @note 00856 If you use a non-square (=non-NxN) grid and findChessboardCorners for calibration, and 00857 calibrateCamera returns bad values (zero distortion coefficients, an image center very far from 00858 (w/2-0.5,h/2-0.5), and/or large differences between \f$f_x\f$ and \f$f_y\f$ (ratios of 10:1 or more)), 00859 then you have probably used patternSize=cvSize(rows,cols) instead of using 00860 patternSize=cvSize(cols,rows) in findChessboardCorners . 00861 00862 @sa 00863 findChessboardCorners, solvePnP, initCameraMatrix2D, stereoCalibrate, undistort 00864 */ 00865 CV_EXPORTS_AS(calibrateCameraExtended) double calibrateCamera( InputArrayOfArrays objectPoints, 00866 InputArrayOfArrays imagePoints, Size imageSize, 00867 InputOutputArray cameraMatrix, InputOutputArray distCoeffs, 00868 OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, 00869 OutputArray stdDeviationsIntrinsics, 00870 OutputArray stdDeviationsExtrinsics, 00871 OutputArray perViewErrors, 00872 int flags = 0, TermCriteria criteria = TermCriteria( 00873 TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ); 00874 00875 /** @overload double calibrateCamera( InputArrayOfArrays objectPoints, 00876 InputArrayOfArrays imagePoints, Size imageSize, 00877 InputOutputArray cameraMatrix, InputOutputArray distCoeffs, 00878 OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, 00879 OutputArray stdDeviations, OutputArray perViewErrors, 00880 int flags = 0, TermCriteria criteria = TermCriteria( 00881 TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ) 00882 */ 00883 CV_EXPORTS_W double calibrateCamera( InputArrayOfArrays objectPoints, 00884 InputArrayOfArrays imagePoints, Size imageSize, 00885 InputOutputArray cameraMatrix, InputOutputArray distCoeffs, 00886 OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, 00887 int flags = 0, TermCriteria criteria = TermCriteria( 00888 TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) ); 00889 00890 /** @brief Computes useful camera characteristics from the camera matrix. 00891 00892 @param cameraMatrix Input camera matrix that can be estimated by calibrateCamera or 00893 stereoCalibrate . 00894 @param imageSize Input image size in pixels. 00895 @param apertureWidth Physical width in mm of the sensor. 00896 @param apertureHeight Physical height in mm of the sensor. 00897 @param fovx Output field of view in degrees along the horizontal sensor axis. 00898 @param fovy Output field of view in degrees along the vertical sensor axis. 00899 @param focalLength Focal length of the lens in mm. 00900 @param principalPoint Principal point in mm. 00901 @param aspectRatio \f$f_y/f_x\f$ 00902 00903 The function computes various useful camera characteristics from the previously estimated camera 00904 matrix. 00905 00906 @note 00907 Do keep in mind that the unity measure 'mm' stands for whatever unit of measure one chooses for 00908 the chessboard pitch (it can thus be any value). 00909 */ 00910 CV_EXPORTS_W void calibrationMatrixValues( InputArray cameraMatrix, Size imageSize, 00911 double apertureWidth, double apertureHeight, 00912 CV_OUT double& fovx, CV_OUT double& fovy, 00913 CV_OUT double& focalLength, CV_OUT Point2d& principalPoint, 00914 CV_OUT double& aspectRatio ); 00915 00916 /** @brief Calibrates the stereo camera. 00917 00918 @param objectPoints Vector of vectors of the calibration pattern points. 00919 @param imagePoints1 Vector of vectors of the projections of the calibration pattern points, 00920 observed by the first camera. 00921 @param imagePoints2 Vector of vectors of the projections of the calibration pattern points, 00922 observed by the second camera. 00923 @param cameraMatrix1 Input/output first camera matrix: 00924 \f$\vecthreethree{f_x^{(j)}}{0}{c_x^{(j)}}{0}{f_y^{(j)}}{c_y^{(j)}}{0}{0}{1}\f$ , \f$j = 0,\, 1\f$ . If 00925 any of CV_CALIB_USE_INTRINSIC_GUESS , CV_CALIB_FIX_ASPECT_RATIO , 00926 CV_CALIB_FIX_INTRINSIC , or CV_CALIB_FIX_FOCAL_LENGTH are specified, some or all of the 00927 matrix components must be initialized. See the flags description for details. 00928 @param distCoeffs1 Input/output vector of distortion coefficients 00929 \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of 00930 4, 5, 8, 12 or 14 elements. The output vector length depends on the flags. 00931 @param cameraMatrix2 Input/output second camera matrix. The parameter is similar to cameraMatrix1 00932 @param distCoeffs2 Input/output lens distortion coefficients for the second camera. The parameter 00933 is similar to distCoeffs1 . 00934 @param imageSize Size of the image used only to initialize intrinsic camera matrix. 00935 @param R Output rotation matrix between the 1st and the 2nd camera coordinate systems. 00936 @param T Output translation vector between the coordinate systems of the cameras. 00937 @param E Output essential matrix. 00938 @param F Output fundamental matrix. 00939 @param flags Different flags that may be zero or a combination of the following values: 00940 - **CV_CALIB_FIX_INTRINSIC** Fix cameraMatrix? and distCoeffs? so that only R, T, E , and F 00941 matrices are estimated. 00942 - **CV_CALIB_USE_INTRINSIC_GUESS** Optimize some or all of the intrinsic parameters 00943 according to the specified flags. Initial values are provided by the user. 00944 - **CV_CALIB_FIX_PRINCIPAL_POINT** Fix the principal points during the optimization. 00945 - **CV_CALIB_FIX_FOCAL_LENGTH** Fix \f$f^{(j)}_x\f$ and \f$f^{(j)}_y\f$ . 00946 - **CV_CALIB_FIX_ASPECT_RATIO** Optimize \f$f^{(j)}_y\f$ . Fix the ratio \f$f^{(j)}_x/f^{(j)}_y\f$ 00947 . 00948 - **CV_CALIB_SAME_FOCAL_LENGTH** Enforce \f$f^{(0)}_x=f^{(1)}_x\f$ and \f$f^{(0)}_y=f^{(1)}_y\f$ . 00949 - **CV_CALIB_ZERO_TANGENT_DIST** Set tangential distortion coefficients for each camera to 00950 zeros and fix there. 00951 - **CV_CALIB_FIX_K1,...,CV_CALIB_FIX_K6** Do not change the corresponding radial 00952 distortion coefficient during the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is set, 00953 the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0. 00954 - **CV_CALIB_RATIONAL_MODEL** Enable coefficients k4, k5, and k6. To provide the backward 00955 compatibility, this extra flag should be explicitly specified to make the calibration 00956 function use the rational model and return 8 coefficients. If the flag is not set, the 00957 function computes and returns only 5 distortion coefficients. 00958 - **CALIB_THIN_PRISM_MODEL** Coefficients s1, s2, s3 and s4 are enabled. To provide the 00959 backward compatibility, this extra flag should be explicitly specified to make the 00960 calibration function use the thin prism model and return 12 coefficients. If the flag is not 00961 set, the function computes and returns only 5 distortion coefficients. 00962 - **CALIB_FIX_S1_S2_S3_S4** The thin prism distortion coefficients are not changed during 00963 the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the 00964 supplied distCoeffs matrix is used. Otherwise, it is set to 0. 00965 - **CALIB_TILTED_MODEL** Coefficients tauX and tauY are enabled. To provide the 00966 backward compatibility, this extra flag should be explicitly specified to make the 00967 calibration function use the tilted sensor model and return 14 coefficients. If the flag is not 00968 set, the function computes and returns only 5 distortion coefficients. 00969 - **CALIB_FIX_TAUX_TAUY** The coefficients of the tilted sensor model are not changed during 00970 the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the 00971 supplied distCoeffs matrix is used. Otherwise, it is set to 0. 00972 @param criteria Termination criteria for the iterative optimization algorithm. 00973 00974 The function estimates transformation between two cameras making a stereo pair. If you have a stereo 00975 camera where the relative position and orientation of two cameras is fixed, and if you computed 00976 poses of an object relative to the first camera and to the second camera, (R1, T1) and (R2, T2), 00977 respectively (this can be done with solvePnP ), then those poses definitely relate to each other. 00978 This means that, given ( \f$R_1\f$,\f$T_1\f$ ), it should be possible to compute ( \f$R_2\f$,\f$T_2\f$ ). You only 00979 need to know the position and orientation of the second camera relative to the first camera. This is 00980 what the described function does. It computes ( \f$R\f$,\f$T\f$ ) so that: 00981 00982 \f[R_2=R*R_1 00983 T_2=R*T_1 + T,\f] 00984 00985 Optionally, it computes the essential matrix E: 00986 00987 \f[E= \vecthreethree{0}{-T_2}{T_1}{T_2}{0}{-T_0}{-T_1}{T_0}{0} *R\f] 00988 00989 where \f$T_i\f$ are components of the translation vector \f$T\f$ : \f$T=[T_0, T_1, T_2]^T\f$ . And the function 00990 can also compute the fundamental matrix F: 00991 00992 \f[F = cameraMatrix2^{-T} E cameraMatrix1^{-1}\f] 00993 00994 Besides the stereo-related information, the function can also perform a full calibration of each of 00995 two cameras. However, due to the high dimensionality of the parameter space and noise in the input 00996 data, the function can diverge from the correct solution. If the intrinsic parameters can be 00997 estimated with high accuracy for each of the cameras individually (for example, using 00998 calibrateCamera ), you are recommended to do so and then pass CV_CALIB_FIX_INTRINSIC flag to the 00999 function along with the computed intrinsic parameters. Otherwise, if all the parameters are 01000 estimated at once, it makes sense to restrict some parameters, for example, pass 01001 CV_CALIB_SAME_FOCAL_LENGTH and CV_CALIB_ZERO_TANGENT_DIST flags, which is usually a 01002 reasonable assumption. 01003 01004 Similarly to calibrateCamera , the function minimizes the total re-projection error for all the 01005 points in all the available views from both cameras. The function returns the final value of the 01006 re-projection error. 01007 */ 01008 CV_EXPORTS_W double stereoCalibrate( InputArrayOfArrays objectPoints, 01009 InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, 01010 InputOutputArray cameraMatrix1, InputOutputArray distCoeffs1, 01011 InputOutputArray cameraMatrix2, InputOutputArray distCoeffs2, 01012 Size imageSize, OutputArray R,OutputArray T, OutputArray E, OutputArray F, 01013 int flags = CALIB_FIX_INTRINSIC, 01014 TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6) ); 01015 01016 01017 /** @brief Computes rectification transforms for each head of a calibrated stereo camera. 01018 01019 @param cameraMatrix1 First camera matrix. 01020 @param distCoeffs1 First camera distortion parameters. 01021 @param cameraMatrix2 Second camera matrix. 01022 @param distCoeffs2 Second camera distortion parameters. 01023 @param imageSize Size of the image used for stereo calibration. 01024 @param R Rotation matrix between the coordinate systems of the first and the second cameras. 01025 @param T Translation vector between coordinate systems of the cameras. 01026 @param R1 Output 3x3 rectification transform (rotation matrix) for the first camera. 01027 @param R2 Output 3x3 rectification transform (rotation matrix) for the second camera. 01028 @param P1 Output 3x4 projection matrix in the new (rectified) coordinate systems for the first 01029 camera. 01030 @param P2 Output 3x4 projection matrix in the new (rectified) coordinate systems for the second 01031 camera. 01032 @param Q Output \f$4 \times 4\f$ disparity-to-depth mapping matrix (see reprojectImageTo3D ). 01033 @param flags Operation flags that may be zero or CV_CALIB_ZERO_DISPARITY . If the flag is set, 01034 the function makes the principal points of each camera have the same pixel coordinates in the 01035 rectified views. And if the flag is not set, the function may still shift the images in the 01036 horizontal or vertical direction (depending on the orientation of epipolar lines) to maximize the 01037 useful image area. 01038 @param alpha Free scaling parameter. If it is -1 or absent, the function performs the default 01039 scaling. Otherwise, the parameter should be between 0 and 1. alpha=0 means that the rectified 01040 images are zoomed and shifted so that only valid pixels are visible (no black areas after 01041 rectification). alpha=1 means that the rectified image is decimated and shifted so that all the 01042 pixels from the original images from the cameras are retained in the rectified images (no source 01043 image pixels are lost). Obviously, any intermediate value yields an intermediate result between 01044 those two extreme cases. 01045 @param newImageSize New image resolution after rectification. The same size should be passed to 01046 initUndistortRectifyMap (see the stereo_calib.cpp sample in OpenCV samples directory). When (0,0) 01047 is passed (default), it is set to the original imageSize . Setting it to larger value can help you 01048 preserve details in the original image, especially when there is a big radial distortion. 01049 @param validPixROI1 Optional output rectangles inside the rectified images where all the pixels 01050 are valid. If alpha=0 , the ROIs cover the whole images. Otherwise, they are likely to be smaller 01051 (see the picture below). 01052 @param validPixROI2 Optional output rectangles inside the rectified images where all the pixels 01053 are valid. If alpha=0 , the ROIs cover the whole images. Otherwise, they are likely to be smaller 01054 (see the picture below). 01055 01056 The function computes the rotation matrices for each camera that (virtually) make both camera image 01057 planes the same plane. Consequently, this makes all the epipolar lines parallel and thus simplifies 01058 the dense stereo correspondence problem. The function takes the matrices computed by stereoCalibrate 01059 as input. As output, it provides two rotation matrices and also two projection matrices in the new 01060 coordinates. The function distinguishes the following two cases: 01061 01062 - **Horizontal stereo**: the first and the second camera views are shifted relative to each other 01063 mainly along the x axis (with possible small vertical shift). In the rectified images, the 01064 corresponding epipolar lines in the left and right cameras are horizontal and have the same 01065 y-coordinate. P1 and P2 look like: 01066 01067 \f[\texttt{P1} = \begin{bmatrix} f & 0 & cx_1 & 0 \\ 0 & f & cy & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix}\f] 01068 01069 \f[\texttt{P2} = \begin{bmatrix} f & 0 & cx_2 & T_x*f \\ 0 & f & cy & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix} ,\f] 01070 01071 where \f$T_x\f$ is a horizontal shift between the cameras and \f$cx_1=cx_2\f$ if 01072 CV_CALIB_ZERO_DISPARITY is set. 01073 01074 - **Vertical stereo**: the first and the second camera views are shifted relative to each other 01075 mainly in vertical direction (and probably a bit in the horizontal direction too). The epipolar 01076 lines in the rectified images are vertical and have the same x-coordinate. P1 and P2 look like: 01077 01078 \f[\texttt{P1} = \begin{bmatrix} f & 0 & cx & 0 \\ 0 & f & cy_1 & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix}\f] 01079 01080 \f[\texttt{P2} = \begin{bmatrix} f & 0 & cx & 0 \\ 0 & f & cy_2 & T_y*f \\ 0 & 0 & 1 & 0 \end{bmatrix} ,\f] 01081 01082 where \f$T_y\f$ is a vertical shift between the cameras and \f$cy_1=cy_2\f$ if CALIB_ZERO_DISPARITY is 01083 set. 01084 01085 As you can see, the first three columns of P1 and P2 will effectively be the new "rectified" camera 01086 matrices. The matrices, together with R1 and R2 , can then be passed to initUndistortRectifyMap to 01087 initialize the rectification map for each camera. 01088 01089 See below the screenshot from the stereo_calib.cpp sample. Some red horizontal lines pass through 01090 the corresponding image regions. This means that the images are well rectified, which is what most 01091 stereo correspondence algorithms rely on. The green rectangles are roi1 and roi2 . You see that 01092 their interiors are all valid pixels. 01093 01094  01095 */ 01096 CV_EXPORTS_W void stereoRectify( InputArray cameraMatrix1, InputArray distCoeffs1, 01097 InputArray cameraMatrix2, InputArray distCoeffs2, 01098 Size imageSize, InputArray R, InputArray T, 01099 OutputArray R1, OutputArray R2, 01100 OutputArray P1, OutputArray P2, 01101 OutputArray Q, int flags = CALIB_ZERO_DISPARITY, 01102 double alpha = -1, Size newImageSize = Size(), 01103 CV_OUT Rect* validPixROI1 = 0, CV_OUT Rect* validPixROI2 = 0 ); 01104 01105 /** @brief Computes a rectification transform for an uncalibrated stereo camera. 01106 01107 @param points1 Array of feature points in the first image. 01108 @param points2 The corresponding points in the second image. The same formats as in 01109 findFundamentalMat are supported. 01110 @param F Input fundamental matrix. It can be computed from the same set of point pairs using 01111 findFundamentalMat . 01112 @param imgSize Size of the image. 01113 @param H1 Output rectification homography matrix for the first image. 01114 @param H2 Output rectification homography matrix for the second image. 01115 @param threshold Optional threshold used to filter out the outliers. If the parameter is greater 01116 than zero, all the point pairs that do not comply with the epipolar geometry (that is, the points 01117 for which \f$|\texttt{points2[i]}^T*\texttt{F}*\texttt{points1[i]}|>\texttt{threshold}\f$ ) are 01118 rejected prior to computing the homographies. Otherwise,all the points are considered inliers. 01119 01120 The function computes the rectification transformations without knowing intrinsic parameters of the 01121 cameras and their relative position in the space, which explains the suffix "uncalibrated". Another 01122 related difference from stereoRectify is that the function outputs not the rectification 01123 transformations in the object (3D) space, but the planar perspective transformations encoded by the 01124 homography matrices H1 and H2 . The function implements the algorithm @cite Hartley99 . 01125 01126 @note 01127 While the algorithm does not need to know the intrinsic parameters of the cameras, it heavily 01128 depends on the epipolar geometry. Therefore, if the camera lenses have a significant distortion, 01129 it would be better to correct it before computing the fundamental matrix and calling this 01130 function. For example, distortion coefficients can be estimated for each head of stereo camera 01131 separately by using calibrateCamera . Then, the images can be corrected using undistort , or 01132 just the point coordinates can be corrected with undistortPoints . 01133 */ 01134 CV_EXPORTS_W bool stereoRectifyUncalibrated( InputArray points1, InputArray points2, 01135 InputArray F, Size imgSize, 01136 OutputArray H1, OutputArray H2, 01137 double threshold = 5 ); 01138 01139 //! computes the rectification transformations for 3-head camera, where all the heads are on the same line. 01140 CV_EXPORTS_W float rectify3Collinear( InputArray cameraMatrix1, InputArray distCoeffs1, 01141 InputArray cameraMatrix2, InputArray distCoeffs2, 01142 InputArray cameraMatrix3, InputArray distCoeffs3, 01143 InputArrayOfArrays imgpt1, InputArrayOfArrays imgpt3, 01144 Size imageSize, InputArray R12, InputArray T12, 01145 InputArray R13, InputArray T13, 01146 OutputArray R1, OutputArray R2, OutputArray R3, 01147 OutputArray P1, OutputArray P2, OutputArray P3, 01148 OutputArray Q, double alpha, Size newImgSize, 01149 CV_OUT Rect* roi1, CV_OUT Rect* roi2, int flags ); 01150 01151 /** @brief Returns the new camera matrix based on the free scaling parameter. 01152 01153 @param cameraMatrix Input camera matrix. 01154 @param distCoeffs Input vector of distortion coefficients 01155 \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \tau_x, \tau_y]]]])\f$ of 01156 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are 01157 assumed. 01158 @param imageSize Original image size. 01159 @param alpha Free scaling parameter between 0 (when all the pixels in the undistorted image are 01160 valid) and 1 (when all the source image pixels are retained in the undistorted image). See 01161 stereoRectify for details. 01162 @param newImgSize Image size after rectification. By default,it is set to imageSize . 01163 @param validPixROI Optional output rectangle that outlines all-good-pixels region in the 01164 undistorted image. See roi1, roi2 description in stereoRectify . 01165 @param centerPrincipalPoint Optional flag that indicates whether in the new camera matrix the 01166 principal point should be at the image center or not. By default, the principal point is chosen to 01167 best fit a subset of the source image (determined by alpha) to the corrected image. 01168 @return new_camera_matrix Output new camera matrix. 01169 01170 The function computes and returns the optimal new camera matrix based on the free scaling parameter. 01171 By varying this parameter, you may retrieve only sensible pixels alpha=0 , keep all the original 01172 image pixels if there is valuable information in the corners alpha=1 , or get something in between. 01173 When alpha>0 , the undistortion result is likely to have some black pixels corresponding to 01174 "virtual" pixels outside of the captured distorted image. The original camera matrix, distortion 01175 coefficients, the computed new camera matrix, and newImageSize should be passed to 01176 initUndistortRectifyMap to produce the maps for remap . 01177 */ 01178 CV_EXPORTS_W Mat getOptimalNewCameraMatrix( InputArray cameraMatrix, InputArray distCoeffs, 01179 Size imageSize, double alpha, Size newImgSize = Size(), 01180 CV_OUT Rect* validPixROI = 0, 01181 bool centerPrincipalPoint = false); 01182 01183 /** @brief Converts points from Euclidean to homogeneous space. 01184 01185 @param src Input vector of N-dimensional points. 01186 @param dst Output vector of N+1-dimensional points. 01187 01188 The function converts points from Euclidean to homogeneous space by appending 1's to the tuple of 01189 point coordinates. That is, each point (x1, x2, ..., xn) is converted to (x1, x2, ..., xn, 1). 01190 */ 01191 CV_EXPORTS_W void convertPointsToHomogeneous( InputArray src, OutputArray dst ); 01192 01193 /** @brief Converts points from homogeneous to Euclidean space. 01194 01195 @param src Input vector of N-dimensional points. 01196 @param dst Output vector of N-1-dimensional points. 01197 01198 The function converts points homogeneous to Euclidean space using perspective projection. That is, 01199 each point (x1, x2, ... x(n-1), xn) is converted to (x1/xn, x2/xn, ..., x(n-1)/xn). When xn=0, the 01200 output point coordinates will be (0,0,0,...). 01201 */ 01202 CV_EXPORTS_W void convertPointsFromHomogeneous( InputArray src, OutputArray dst ); 01203 01204 /** @brief Converts points to/from homogeneous coordinates. 01205 01206 @param src Input array or vector of 2D, 3D, or 4D points. 01207 @param dst Output vector of 2D, 3D, or 4D points. 01208 01209 The function converts 2D or 3D points from/to homogeneous coordinates by calling either 01210 convertPointsToHomogeneous or convertPointsFromHomogeneous. 01211 01212 @note The function is obsolete. Use one of the previous two functions instead. 01213 */ 01214 CV_EXPORTS void convertPointsHomogeneous( InputArray src, OutputArray dst ); 01215 01216 /** @brief Calculates a fundamental matrix from the corresponding points in two images. 01217 01218 @param points1 Array of N points from the first image. The point coordinates should be 01219 floating-point (single or double precision). 01220 @param points2 Array of the second image points of the same size and format as points1 . 01221 @param method Method for computing a fundamental matrix. 01222 - **CV_FM_7POINT** for a 7-point algorithm. \f$N = 7\f$ 01223 - **CV_FM_8POINT** for an 8-point algorithm. \f$N \ge 8\f$ 01224 - **CV_FM_RANSAC** for the RANSAC algorithm. \f$N \ge 8\f$ 01225 - **CV_FM_LMEDS** for the LMedS algorithm. \f$N \ge 8\f$ 01226 @param param1 Parameter used for RANSAC. It is the maximum distance from a point to an epipolar 01227 line in pixels, beyond which the point is considered an outlier and is not used for computing the 01228 final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the 01229 point localization, image resolution, and the image noise. 01230 @param param2 Parameter used for the RANSAC or LMedS methods only. It specifies a desirable level 01231 of confidence (probability) that the estimated matrix is correct. 01232 @param mask 01233 01234 The epipolar geometry is described by the following equation: 01235 01236 \f[[p_2; 1]^T F [p_1; 1] = 0\f] 01237 01238 where \f$F\f$ is a fundamental matrix, \f$p_1\f$ and \f$p_2\f$ are corresponding points in the first and the 01239 second images, respectively. 01240 01241 The function calculates the fundamental matrix using one of four methods listed above and returns 01242 the found fundamental matrix. Normally just one matrix is found. But in case of the 7-point 01243 algorithm, the function may return up to 3 solutions ( \f$9 \times 3\f$ matrix that stores all 3 01244 matrices sequentially). 01245 01246 The calculated fundamental matrix may be passed further to computeCorrespondEpilines that finds the 01247 epipolar lines corresponding to the specified points. It can also be passed to 01248 stereoRectifyUncalibrated to compute the rectification transformation. : 01249 @code 01250 // Example. Estimation of fundamental matrix using the RANSAC algorithm 01251 int point_count = 100; 01252 vector<Point2f> points1(point_count); 01253 vector<Point2f> points2(point_count); 01254 01255 // initialize the points here ... 01256 for( int i = 0; i < point_count; i++ ) 01257 { 01258 points1[i] = ...; 01259 points2[i] = ...; 01260 } 01261 01262 Mat fundamental_matrix = 01263 findFundamentalMat(points1, points2, FM_RANSAC, 3, 0.99); 01264 @endcode 01265 */ 01266 CV_EXPORTS_W Mat findFundamentalMat( InputArray points1, InputArray points2, 01267 int method = FM_RANSAC, 01268 double param1 = 3., double param2 = 0.99, 01269 OutputArray mask = noArray() ); 01270 01271 /** @overload */ 01272 CV_EXPORTS Mat findFundamentalMat( InputArray points1, InputArray points2, 01273 OutputArray mask, int method = FM_RANSAC, 01274 double param1 = 3., double param2 = 0.99 ); 01275 01276 /** @brief Calculates an essential matrix from the corresponding points in two images. 01277 01278 @param points1 Array of N (N >= 5) 2D points from the first image. The point coordinates should 01279 be floating-point (single or double precision). 01280 @param points2 Array of the second image points of the same size and format as points1 . 01281 @param cameraMatrix Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . 01282 Note that this function assumes that points1 and points2 are feature points from cameras with the 01283 same camera matrix. 01284 @param method Method for computing a fundamental matrix. 01285 - **RANSAC** for the RANSAC algorithm. 01286 - **MEDS** for the LMedS algorithm. 01287 @param prob Parameter used for the RANSAC or LMedS methods only. It specifies a desirable level of 01288 confidence (probability) that the estimated matrix is correct. 01289 @param threshold Parameter used for RANSAC. It is the maximum distance from a point to an epipolar 01290 line in pixels, beyond which the point is considered an outlier and is not used for computing the 01291 final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the 01292 point localization, image resolution, and the image noise. 01293 @param mask Output array of N elements, every element of which is set to 0 for outliers and to 1 01294 for the other points. The array is computed only in the RANSAC and LMedS methods. 01295 01296 This function estimates essential matrix based on the five-point algorithm solver in @cite Nister03 . 01297 @cite SteweniusCFS is also a related. The epipolar geometry is described by the following equation: 01298 01299 \f[[p_2; 1]^T K^{-T} E K^{-1} [p_1; 1] = 0\f] 01300 01301 where \f$E\f$ is an essential matrix, \f$p_1\f$ and \f$p_2\f$ are corresponding points in the first and the 01302 second images, respectively. The result of this function may be passed further to 01303 decomposeEssentialMat or recoverPose to recover the relative pose between cameras. 01304 */ 01305 CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2, 01306 InputArray cameraMatrix, int method = RANSAC, 01307 double prob = 0.999, double threshold = 1.0, 01308 OutputArray mask = noArray() ); 01309 01310 /** @overload 01311 @param points1 Array of N (N >= 5) 2D points from the first image. The point coordinates should 01312 be floating-point (single or double precision). 01313 @param points2 Array of the second image points of the same size and format as points1 . 01314 @param focal focal length of the camera. Note that this function assumes that points1 and points2 01315 are feature points from cameras with same focal length and principal point. 01316 @param pp principal point of the camera. 01317 @param method Method for computing a fundamental matrix. 01318 - **RANSAC** for the RANSAC algorithm. 01319 - **LMEDS** for the LMedS algorithm. 01320 @param threshold Parameter used for RANSAC. It is the maximum distance from a point to an epipolar 01321 line in pixels, beyond which the point is considered an outlier and is not used for computing the 01322 final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the 01323 point localization, image resolution, and the image noise. 01324 @param prob Parameter used for the RANSAC or LMedS methods only. It specifies a desirable level of 01325 confidence (probability) that the estimated matrix is correct. 01326 @param mask Output array of N elements, every element of which is set to 0 for outliers and to 1 01327 for the other points. The array is computed only in the RANSAC and LMedS methods. 01328 01329 This function differs from the one above that it computes camera matrix from focal length and 01330 principal point: 01331 01332 \f[K = 01333 \begin{bmatrix} 01334 f & 0 & x_{pp} \\ 01335 0 & f & y_{pp} \\ 01336 0 & 0 & 1 01337 \end{bmatrix}\f] 01338 */ 01339 CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2, 01340 double focal = 1.0, Point2d pp = Point2d(0, 0), 01341 int method = RANSAC, double prob = 0.999, 01342 double threshold = 1.0, OutputArray mask = noArray() ); 01343 01344 /** @brief Decompose an essential matrix to possible rotations and translation. 01345 01346 @param E The input essential matrix. 01347 @param R1 One possible rotation matrix. 01348 @param R2 Another possible rotation matrix. 01349 @param t One possible translation. 01350 01351 This function decompose an essential matrix E using svd decomposition @cite HartleyZ00 . Generally 4 01352 possible poses exists for a given E. They are \f$[R_1, t]\f$, \f$[R_1, -t]\f$, \f$[R_2, t]\f$, \f$[R_2, -t]\f$. By 01353 decomposing E, you can only get the direction of the translation, so the function returns unit t. 01354 */ 01355 CV_EXPORTS_W void decomposeEssentialMat( InputArray E, OutputArray R1, OutputArray R2, OutputArray t ); 01356 01357 /** @brief Recover relative camera rotation and translation from an estimated essential matrix and the 01358 corresponding points in two images, using cheirality check. Returns the number of inliers which pass 01359 the check. 01360 01361 @param E The input essential matrix. 01362 @param points1 Array of N 2D points from the first image. The point coordinates should be 01363 floating-point (single or double precision). 01364 @param points2 Array of the second image points of the same size and format as points1 . 01365 @param cameraMatrix Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . 01366 Note that this function assumes that points1 and points2 are feature points from cameras with the 01367 same camera matrix. 01368 @param R Recovered relative rotation. 01369 @param t Recoverd relative translation. 01370 @param mask Input/output mask for inliers in points1 and points2. 01371 : If it is not empty, then it marks inliers in points1 and points2 for then given essential 01372 matrix E. Only these inliers will be used to recover pose. In the output mask only inliers 01373 which pass the cheirality check. 01374 This function decomposes an essential matrix using decomposeEssentialMat and then verifies possible 01375 pose hypotheses by doing cheirality check. The cheirality check basically means that the 01376 triangulated 3D points should have positive depth. Some details can be found in @cite Nister03 . 01377 01378 This function can be used to process output E and mask from findEssentialMat. In this scenario, 01379 points1 and points2 are the same input for findEssentialMat. : 01380 @code 01381 // Example. Estimation of fundamental matrix using the RANSAC algorithm 01382 int point_count = 100; 01383 vector<Point2f> points1(point_count); 01384 vector<Point2f> points2(point_count); 01385 01386 // initialize the points here ... 01387 for( int i = 0; i < point_count; i++ ) 01388 { 01389 points1[i] = ...; 01390 points2[i] = ...; 01391 } 01392 01393 // cametra matrix with both focal lengths = 1, and principal point = (0, 0) 01394 Mat cameraMatrix = Mat::eye(3, 3, CV_64F); 01395 01396 Mat E, R, t, mask; 01397 01398 E = findEssentialMat(points1, points2, cameraMatrix, RANSAC, 0.999, 1.0, mask); 01399 recoverPose(E, points1, points2, cameraMatrix, R, t, mask); 01400 @endcode 01401 */ 01402 CV_EXPORTS_W int recoverPose( InputArray E, InputArray points1, InputArray points2, 01403 InputArray cameraMatrix, OutputArray R, OutputArray t, 01404 InputOutputArray mask = noArray() ); 01405 01406 /** @overload 01407 @param E The input essential matrix. 01408 @param points1 Array of N 2D points from the first image. The point coordinates should be 01409 floating-point (single or double precision). 01410 @param points2 Array of the second image points of the same size and format as points1 . 01411 @param R Recovered relative rotation. 01412 @param t Recoverd relative translation. 01413 @param focal Focal length of the camera. Note that this function assumes that points1 and points2 01414 are feature points from cameras with same focal length and principal point. 01415 @param pp principal point of the camera. 01416 @param mask Input/output mask for inliers in points1 and points2. 01417 : If it is not empty, then it marks inliers in points1 and points2 for then given essential 01418 matrix E. Only these inliers will be used to recover pose. In the output mask only inliers 01419 which pass the cheirality check. 01420 01421 This function differs from the one above that it computes camera matrix from focal length and 01422 principal point: 01423 01424 \f[K = 01425 \begin{bmatrix} 01426 f & 0 & x_{pp} \\ 01427 0 & f & y_{pp} \\ 01428 0 & 0 & 1 01429 \end{bmatrix}\f] 01430 */ 01431 CV_EXPORTS_W int recoverPose( InputArray E, InputArray points1, InputArray points2, 01432 OutputArray R, OutputArray t, 01433 double focal = 1.0, Point2d pp = Point2d(0, 0), 01434 InputOutputArray mask = noArray() ); 01435 01436 /** @brief For points in an image of a stereo pair, computes the corresponding epilines in the other image. 01437 01438 @param points Input points. \f$N \times 1\f$ or \f$1 \times N\f$ matrix of type CV_32FC2 or 01439 vector<Point2f> . 01440 @param whichImage Index of the image (1 or 2) that contains the points . 01441 @param F Fundamental matrix that can be estimated using findFundamentalMat or stereoRectify . 01442 @param lines Output vector of the epipolar lines corresponding to the points in the other image. 01443 Each line \f$ax + by + c=0\f$ is encoded by 3 numbers \f$(a, b, c)\f$ . 01444 01445 For every point in one of the two images of a stereo pair, the function finds the equation of the 01446 corresponding epipolar line in the other image. 01447 01448 From the fundamental matrix definition (see findFundamentalMat ), line \f$l^{(2)}_i\f$ in the second 01449 image for the point \f$p^{(1)}_i\f$ in the first image (when whichImage=1 ) is computed as: 01450 01451 \f[l^{(2)}_i = F p^{(1)}_i\f] 01452 01453 And vice versa, when whichImage=2, \f$l^{(1)}_i\f$ is computed from \f$p^{(2)}_i\f$ as: 01454 01455 \f[l^{(1)}_i = F^T p^{(2)}_i\f] 01456 01457 Line coefficients are defined up to a scale. They are normalized so that \f$a_i^2+b_i^2=1\f$ . 01458 */ 01459 CV_EXPORTS_W void computeCorrespondEpilines( InputArray points, int whichImage, 01460 InputArray F, OutputArray lines ); 01461 01462 /** @brief Reconstructs points by triangulation. 01463 01464 @param projMatr1 3x4 projection matrix of the first camera. 01465 @param projMatr2 3x4 projection matrix of the second camera. 01466 @param projPoints1 2xN array of feature points in the first image. In case of c++ version it can 01467 be also a vector of feature points or two-channel matrix of size 1xN or Nx1. 01468 @param projPoints2 2xN array of corresponding points in the second image. In case of c++ version 01469 it can be also a vector of feature points or two-channel matrix of size 1xN or Nx1. 01470 @param points4D 4xN array of reconstructed points in homogeneous coordinates. 01471 01472 The function reconstructs 3-dimensional points (in homogeneous coordinates) by using their 01473 observations with a stereo camera. Projections matrices can be obtained from stereoRectify. 01474 01475 @note 01476 Keep in mind that all input data should be of float type in order for this function to work. 01477 01478 @sa 01479 reprojectImageTo3D 01480 */ 01481 CV_EXPORTS_W void triangulatePoints( InputArray projMatr1, InputArray projMatr2, 01482 InputArray projPoints1, InputArray projPoints2, 01483 OutputArray points4D ); 01484 01485 /** @brief Refines coordinates of corresponding points. 01486 01487 @param F 3x3 fundamental matrix. 01488 @param points1 1xN array containing the first set of points. 01489 @param points2 1xN array containing the second set of points. 01490 @param newPoints1 The optimized points1. 01491 @param newPoints2 The optimized points2. 01492 01493 The function implements the Optimal Triangulation Method (see Multiple View Geometry for details). 01494 For each given point correspondence points1[i] <-> points2[i], and a fundamental matrix F, it 01495 computes the corrected correspondences newPoints1[i] <-> newPoints2[i] that minimize the geometric 01496 error \f$d(points1[i], newPoints1[i])^2 + d(points2[i],newPoints2[i])^2\f$ (where \f$d(a,b)\f$ is the 01497 geometric distance between points \f$a\f$ and \f$b\f$ ) subject to the epipolar constraint 01498 \f$newPoints2^T * F * newPoints1 = 0\f$ . 01499 */ 01500 CV_EXPORTS_W void correctMatches( InputArray F, InputArray points1, InputArray points2, 01501 OutputArray newPoints1, OutputArray newPoints2 ); 01502 01503 /** @brief Filters off small noise blobs (speckles) in the disparity map 01504 01505 @param img The input 16-bit signed disparity image 01506 @param newVal The disparity value used to paint-off the speckles 01507 @param maxSpeckleSize The maximum speckle size to consider it a speckle. Larger blobs are not 01508 affected by the algorithm 01509 @param maxDiff Maximum difference between neighbor disparity pixels to put them into the same 01510 blob. Note that since StereoBM, StereoSGBM and may be other algorithms return a fixed-point 01511 disparity map, where disparity values are multiplied by 16, this scale factor should be taken into 01512 account when specifying this parameter value. 01513 @param buf The optional temporary buffer to avoid memory allocation within the function. 01514 */ 01515 CV_EXPORTS_W void filterSpeckles( InputOutputArray img, double newVal, 01516 int maxSpeckleSize, double maxDiff, 01517 InputOutputArray buf = noArray() ); 01518 01519 //! computes valid disparity ROI from the valid ROIs of the rectified images (that are returned by cv::stereoRectify()) 01520 CV_EXPORTS_W Rect getValidDisparityROI( Rect roi1, Rect roi2, 01521 int minDisparity, int numberOfDisparities, 01522 int SADWindowSize ); 01523 01524 //! validates disparity using the left-right check. The matrix "cost" should be computed by the stereo correspondence algorithm 01525 CV_EXPORTS_W void validateDisparity( InputOutputArray disparity, InputArray cost, 01526 int minDisparity, int numberOfDisparities, 01527 int disp12MaxDisp = 1 ); 01528 01529 /** @brief Reprojects a disparity image to 3D space. 01530 01531 @param disparity Input single-channel 8-bit unsigned, 16-bit signed, 32-bit signed or 32-bit 01532 floating-point disparity image. If 16-bit signed format is used, the values are assumed to have no 01533 fractional bits. 01534 @param _3dImage Output 3-channel floating-point image of the same size as disparity . Each 01535 element of _3dImage(x,y) contains 3D coordinates of the point (x,y) computed from the disparity 01536 map. 01537 @param Q \f$4 \times 4\f$ perspective transformation matrix that can be obtained with stereoRectify. 01538 @param handleMissingValues Indicates, whether the function should handle missing values (i.e. 01539 points where the disparity was not computed). If handleMissingValues=true, then pixels with the 01540 minimal disparity that corresponds to the outliers (see StereoMatcher::compute ) are transformed 01541 to 3D points with a very large Z value (currently set to 10000). 01542 @param ddepth The optional output array depth. If it is -1, the output image will have CV_32F 01543 depth. ddepth can also be set to CV_16S, CV_32S or CV_32F. 01544 01545 The function transforms a single-channel disparity map to a 3-channel image representing a 3D 01546 surface. That is, for each pixel (x,y) andthe corresponding disparity d=disparity(x,y) , it 01547 computes: 01548 01549 \f[\begin{array}{l} [X \; Y \; Z \; W]^T = \texttt{Q} *[x \; y \; \texttt{disparity} (x,y) \; 1]^T \\ \texttt{\_3dImage} (x,y) = (X/W, \; Y/W, \; Z/W) \end{array}\f] 01550 01551 The matrix Q can be an arbitrary \f$4 \times 4\f$ matrix (for example, the one computed by 01552 stereoRectify). To reproject a sparse set of points {(x,y,d),...} to 3D space, use 01553 perspectiveTransform . 01554 */ 01555 CV_EXPORTS_W void reprojectImageTo3D( InputArray disparity, 01556 OutputArray _3dImage, InputArray Q, 01557 bool handleMissingValues = false, 01558 int ddepth = -1 ); 01559 01560 /** @brief Calculates the Sampson Distance between two points. 01561 01562 The function sampsonDistance calculates and returns the first order approximation of the geometric error as: 01563 \f[sd( \texttt{pt1} , \texttt{pt2} )= \frac{(\texttt{pt2}^t \cdot \texttt{F} \cdot \texttt{pt1})^2}{(\texttt{F} \cdot \texttt{pt1})(0) + (\texttt{F} \cdot \texttt{pt1})(1) + (\texttt{F}^t \cdot \texttt{pt2})(0) + (\texttt{F}^t \cdot \texttt{pt2})(1)}\f] 01564 The fundamental matrix may be calculated using the cv::findFundamentalMat function. See HZ 11.4.3 for details. 01565 @param pt1 first homogeneous 2d point 01566 @param pt2 second homogeneous 2d point 01567 @param F fundamental matrix 01568 */ 01569 CV_EXPORTS_W double sampsonDistance(InputArray pt1, InputArray pt2, InputArray F); 01570 01571 /** @brief Computes an optimal affine transformation between two 3D point sets. 01572 01573 @param src First input 3D point set. 01574 @param dst Second input 3D point set. 01575 @param out Output 3D affine transformation matrix \f$3 \times 4\f$ . 01576 @param inliers Output vector indicating which points are inliers. 01577 @param ransacThreshold Maximum reprojection error in the RANSAC algorithm to consider a point as 01578 an inlier. 01579 @param confidence Confidence level, between 0 and 1, for the estimated transformation. Anything 01580 between 0.95 and 0.99 is usually good enough. Values too close to 1 can slow down the estimation 01581 significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation. 01582 01583 The function estimates an optimal 3D affine transformation between two 3D point sets using the 01584 RANSAC algorithm. 01585 */ 01586 CV_EXPORTS_W int estimateAffine3D(InputArray src, InputArray dst, 01587 OutputArray out, OutputArray inliers, 01588 double ransacThreshold = 3, double confidence = 0.99); 01589 01590 /** @brief Computes an optimal affine transformation between two 2D point sets. 01591 01592 @param from First input 2D point set. 01593 @param to Second input 2D point set. 01594 @param inliers Output vector indicating which points are inliers. 01595 @param method Robust method used to compute tranformation. The following methods are possible: 01596 - cv::RANSAC - RANSAC-based robust method 01597 - cv::LMEDS - Least-Median robust method 01598 RANSAC is the default method. 01599 @param ransacReprojThreshold Maximum reprojection error in the RANSAC algorithm to consider 01600 a point as an inlier. Applies only to RANSAC. 01601 @param maxIters The maximum number of robust method iterations, 2000 is the maximum it can be. 01602 @param confidence Confidence level, between 0 and 1, for the estimated transformation. Anything 01603 between 0.95 and 0.99 is usually good enough. Values too close to 1 can slow down the estimation 01604 significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation. 01605 @param refineIters Maximum number of iterations of refining algorithm (Levenberg-Marquardt). 01606 Passing 0 will disable refining, so the output matrix will be output of robust method. 01607 01608 @return Output 2D affine transformation matrix \f$2 \times 3\f$ or empty matrix if transformation 01609 could not be estimated. 01610 01611 The function estimates an optimal 2D affine transformation between two 2D point sets using the 01612 selected robust algorithm. 01613 01614 The computed transformation is then refined further (using only inliers) with the 01615 Levenberg-Marquardt method to reduce the re-projection error even more. 01616 01617 @note 01618 The RANSAC method can handle practically any ratio of outliers but need a threshold to 01619 distinguish inliers from outliers. The method LMeDS does not need any threshold but it works 01620 correctly only when there are more than 50% of inliers. 01621 01622 @sa estimateAffinePartial2D, getAffineTransform 01623 */ 01624 CV_EXPORTS_W cv::Mat estimateAffine2D(InputArray from, InputArray to, OutputArray inliers = noArray(), 01625 int method = RANSAC, double ransacReprojThreshold = 3, 01626 size_t maxIters = 2000, double confidence = 0.99, 01627 size_t refineIters = 10); 01628 01629 /** @brief Computes an optimal limited affine transformation with 4 degrees of freedom between 01630 two 2D point sets. 01631 01632 @param from First input 2D point set. 01633 @param to Second input 2D point set. 01634 @param inliers Output vector indicating which points are inliers. 01635 @param method Robust method used to compute tranformation. The following methods are possible: 01636 - cv::RANSAC - RANSAC-based robust method 01637 - cv::LMEDS - Least-Median robust method 01638 RANSAC is the default method. 01639 @param ransacReprojThreshold Maximum reprojection error in the RANSAC algorithm to consider 01640 a point as an inlier. Applies only to RANSAC. 01641 @param maxIters The maximum number of robust method iterations, 2000 is the maximum it can be. 01642 @param confidence Confidence level, between 0 and 1, for the estimated transformation. Anything 01643 between 0.95 and 0.99 is usually good enough. Values too close to 1 can slow down the estimation 01644 significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation. 01645 @param refineIters Maximum number of iterations of refining algorithm (Levenberg-Marquardt). 01646 Passing 0 will disable refining, so the output matrix will be output of robust method. 01647 01648 @return Output 2D affine transformation (4 degrees of freedom) matrix \f$2 \times 3\f$ or 01649 empty matrix if transformation could not be estimated. 01650 01651 The function estimates an optimal 2D affine transformation with 4 degrees of freedom limited to 01652 combinations of translation, rotation, and uniform scaling. Uses the selected algorithm for robust 01653 estimation. 01654 01655 The computed transformation is then refined further (using only inliers) with the 01656 Levenberg-Marquardt method to reduce the re-projection error even more. 01657 01658 Estimated transformation matrix is: 01659 \f[ \begin{bmatrix} \cos(\theta)s & -\sin(\theta)s & tx \\ 01660 \sin(\theta)s & \cos(\theta)s & ty 01661 \end{bmatrix} \f] 01662 Where \f$ \theta \f$ is the rotation angle, \f$ s \f$ the scaling factor and \f$ tx, ty \f$ are 01663 translations in \f$ x, y \f$ axes respectively. 01664 01665 @note 01666 The RANSAC method can handle practically any ratio of outliers but need a threshold to 01667 distinguish inliers from outliers. The method LMeDS does not need any threshold but it works 01668 correctly only when there are more than 50% of inliers. 01669 01670 @sa estimateAffine2D, getAffineTransform 01671 */ 01672 CV_EXPORTS_W cv::Mat estimateAffinePartial2D(InputArray from, InputArray to, OutputArray inliers = noArray(), 01673 int method = RANSAC, double ransacReprojThreshold = 3, 01674 size_t maxIters = 2000, double confidence = 0.99, 01675 size_t refineIters = 10); 01676 01677 /** @brief Decompose a homography matrix to rotation(s), translation(s) and plane normal(s). 01678 01679 @param H The input homography matrix between two images. 01680 @param K The input intrinsic camera calibration matrix. 01681 @param rotations Array of rotation matrices. 01682 @param translations Array of translation matrices. 01683 @param normals Array of plane normal matrices. 01684 01685 This function extracts relative camera motion between two views observing a planar object from the 01686 homography H induced by the plane. The intrinsic camera matrix K must also be provided. The function 01687 may return up to four mathematical solution sets. At least two of the solutions may further be 01688 invalidated if point correspondences are available by applying positive depth constraint (all points 01689 must be in front of the camera). The decomposition method is described in detail in @cite Malis . 01690 */ 01691 CV_EXPORTS_W int decomposeHomographyMat(InputArray H, 01692 InputArray K, 01693 OutputArrayOfArrays rotations, 01694 OutputArrayOfArrays translations, 01695 OutputArrayOfArrays normals); 01696 01697 /** @brief The base class for stereo correspondence algorithms. 01698 */ 01699 class CV_EXPORTS_W StereoMatcher : public Algorithm 01700 { 01701 public: 01702 enum { DISP_SHIFT = 4, 01703 DISP_SCALE = (1 << DISP_SHIFT) 01704 }; 01705 01706 /** @brief Computes disparity map for the specified stereo pair 01707 01708 @param left Left 8-bit single-channel image. 01709 @param right Right image of the same size and the same type as the left one. 01710 @param disparity Output disparity map. It has the same size as the input images. Some algorithms, 01711 like StereoBM or StereoSGBM compute 16-bit fixed-point disparity map (where each disparity value 01712 has 4 fractional bits), whereas other algorithms output 32-bit floating-point disparity map. 01713 */ 01714 CV_WRAP virtual void compute( InputArray left, InputArray right, 01715 OutputArray disparity ) = 0; 01716 01717 CV_WRAP virtual int getMinDisparity() const = 0; 01718 CV_WRAP virtual void setMinDisparity(int minDisparity) = 0; 01719 01720 CV_WRAP virtual int getNumDisparities() const = 0; 01721 CV_WRAP virtual void setNumDisparities(int numDisparities) = 0; 01722 01723 CV_WRAP virtual int getBlockSize() const = 0; 01724 CV_WRAP virtual void setBlockSize(int blockSize) = 0; 01725 01726 CV_WRAP virtual int getSpeckleWindowSize() const = 0; 01727 CV_WRAP virtual void setSpeckleWindowSize(int speckleWindowSize) = 0; 01728 01729 CV_WRAP virtual int getSpeckleRange() const = 0; 01730 CV_WRAP virtual void setSpeckleRange(int speckleRange) = 0; 01731 01732 CV_WRAP virtual int getDisp12MaxDiff() const = 0; 01733 CV_WRAP virtual void setDisp12MaxDiff(int disp12MaxDiff) = 0; 01734 }; 01735 01736 01737 /** @brief Class for computing stereo correspondence using the block matching algorithm, introduced and 01738 contributed to OpenCV by K. Konolige. 01739 */ 01740 class CV_EXPORTS_W StereoBM : public StereoMatcher 01741 { 01742 public: 01743 enum { PREFILTER_NORMALIZED_RESPONSE = 0, 01744 PREFILTER_XSOBEL = 1 01745 }; 01746 01747 CV_WRAP virtual int getPreFilterType() const = 0; 01748 CV_WRAP virtual void setPreFilterType(int preFilterType) = 0; 01749 01750 CV_WRAP virtual int getPreFilterSize() const = 0; 01751 CV_WRAP virtual void setPreFilterSize(int preFilterSize) = 0; 01752 01753 CV_WRAP virtual int getPreFilterCap() const = 0; 01754 CV_WRAP virtual void setPreFilterCap(int preFilterCap) = 0; 01755 01756 CV_WRAP virtual int getTextureThreshold() const = 0; 01757 CV_WRAP virtual void setTextureThreshold(int textureThreshold) = 0; 01758 01759 CV_WRAP virtual int getUniquenessRatio() const = 0; 01760 CV_WRAP virtual void setUniquenessRatio(int uniquenessRatio) = 0; 01761 01762 CV_WRAP virtual int getSmallerBlockSize() const = 0; 01763 CV_WRAP virtual void setSmallerBlockSize(int blockSize) = 0; 01764 01765 CV_WRAP virtual Rect getROI1() const = 0; 01766 CV_WRAP virtual void setROI1(Rect roi1) = 0; 01767 01768 CV_WRAP virtual Rect getROI2() const = 0; 01769 CV_WRAP virtual void setROI2(Rect roi2) = 0; 01770 01771 /** @brief Creates StereoBM object 01772 01773 @param numDisparities the disparity search range. For each pixel algorithm will find the best 01774 disparity from 0 (default minimum disparity) to numDisparities. The search range can then be 01775 shifted by changing the minimum disparity. 01776 @param blockSize the linear size of the blocks compared by the algorithm. The size should be odd 01777 (as the block is centered at the current pixel). Larger block size implies smoother, though less 01778 accurate disparity map. Smaller block size gives more detailed disparity map, but there is higher 01779 chance for algorithm to find a wrong correspondence. 01780 01781 The function create StereoBM object. You can then call StereoBM::compute() to compute disparity for 01782 a specific stereo pair. 01783 */ 01784 CV_WRAP static Ptr<StereoBM> create(int numDisparities = 0, int blockSize = 21); 01785 }; 01786 01787 /** @brief The class implements the modified H. Hirschmuller algorithm @cite HH08 that differs from the original 01788 one as follows: 01789 01790 - By default, the algorithm is single-pass, which means that you consider only 5 directions 01791 instead of 8. Set mode=StereoSGBM::MODE_HH in createStereoSGBM to run the full variant of the 01792 algorithm but beware that it may consume a lot of memory. 01793 - The algorithm matches blocks, not individual pixels. Though, setting blockSize=1 reduces the 01794 blocks to single pixels. 01795 - Mutual information cost function is not implemented. Instead, a simpler Birchfield-Tomasi 01796 sub-pixel metric from @cite BT98 is used. Though, the color images are supported as well. 01797 - Some pre- and post- processing steps from K. Konolige algorithm StereoBM are included, for 01798 example: pre-filtering (StereoBM::PREFILTER_XSOBEL type) and post-filtering (uniqueness 01799 check, quadratic interpolation and speckle filtering). 01800 01801 @note 01802 - (Python) An example illustrating the use of the StereoSGBM matching algorithm can be found 01803 at opencv_source_code/samples/python/stereo_match.py 01804 */ 01805 class CV_EXPORTS_W StereoSGBM : public StereoMatcher 01806 { 01807 public: 01808 enum 01809 { 01810 MODE_SGBM = 0, 01811 MODE_HH = 1, 01812 MODE_SGBM_3WAY = 2 01813 }; 01814 01815 CV_WRAP virtual int getPreFilterCap() const = 0; 01816 CV_WRAP virtual void setPreFilterCap(int preFilterCap) = 0; 01817 01818 CV_WRAP virtual int getUniquenessRatio() const = 0; 01819 CV_WRAP virtual void setUniquenessRatio(int uniquenessRatio) = 0; 01820 01821 CV_WRAP virtual int getP1() const = 0; 01822 CV_WRAP virtual void setP1(int P1) = 0; 01823 01824 CV_WRAP virtual int getP2() const = 0; 01825 CV_WRAP virtual void setP2(int P2) = 0; 01826 01827 CV_WRAP virtual int getMode() const = 0; 01828 CV_WRAP virtual void setMode(int mode) = 0; 01829 01830 /** @brief Creates StereoSGBM object 01831 01832 @param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes 01833 rectification algorithms can shift images, so this parameter needs to be adjusted accordingly. 01834 @param numDisparities Maximum disparity minus minimum disparity. The value is always greater than 01835 zero. In the current implementation, this parameter must be divisible by 16. 01836 @param blockSize Matched block size. It must be an odd number >=1 . Normally, it should be 01837 somewhere in the 3..11 range. 01838 @param P1 The first parameter controlling the disparity smoothness. See below. 01839 @param P2 The second parameter controlling the disparity smoothness. The larger the values are, 01840 the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1 01841 between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor 01842 pixels. The algorithm requires P2 > P1 . See stereo_match.cpp sample where some reasonably good 01843 P1 and P2 values are shown (like 8\*number_of_image_channels\*SADWindowSize\*SADWindowSize and 01844 32\*number_of_image_channels\*SADWindowSize\*SADWindowSize , respectively). 01845 @param disp12MaxDiff Maximum allowed difference (in integer pixel units) in the left-right 01846 disparity check. Set it to a non-positive value to disable the check. 01847 @param preFilterCap Truncation value for the prefiltered image pixels. The algorithm first 01848 computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval. 01849 The result values are passed to the Birchfield-Tomasi pixel cost function. 01850 @param uniquenessRatio Margin in percentage by which the best (minimum) computed cost function 01851 value should "win" the second best value to consider the found match correct. Normally, a value 01852 within the 5-15 range is good enough. 01853 @param speckleWindowSize Maximum size of smooth disparity regions to consider their noise speckles 01854 and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the 01855 50-200 range. 01856 @param speckleRange Maximum disparity variation within each connected component. If you do speckle 01857 filtering, set the parameter to a positive value, it will be implicitly multiplied by 16. 01858 Normally, 1 or 2 is good enough. 01859 @param mode Set it to StereoSGBM::MODE_HH to run the full-scale two-pass dynamic programming 01860 algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and 01861 huge for HD-size pictures. By default, it is set to false . 01862 01863 The first constructor initializes StereoSGBM with all the default parameters. So, you only have to 01864 set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter 01865 to a custom value. 01866 */ 01867 CV_WRAP static Ptr<StereoSGBM> create(int minDisparity, int numDisparities, int blockSize, 01868 int P1 = 0, int P2 = 0, int disp12MaxDiff = 0, 01869 int preFilterCap = 0, int uniquenessRatio = 0, 01870 int speckleWindowSize = 0, int speckleRange = 0, 01871 int mode = StereoSGBM::MODE_SGBM); 01872 }; 01873 01874 //! @} calib3d 01875 01876 /** @brief The methods in this namespace use a so-called fisheye camera model. 01877 @ingroup calib3d_fisheye 01878 */ 01879 namespace fisheye 01880 { 01881 //! @addtogroup calib3d_fisheye 01882 //! @{ 01883 01884 enum{ 01885 CALIB_USE_INTRINSIC_GUESS = 1 << 0, 01886 CALIB_RECOMPUTE_EXTRINSIC = 1 << 1, 01887 CALIB_CHECK_COND = 1 << 2, 01888 CALIB_FIX_SKEW = 1 << 3, 01889 CALIB_FIX_K1 = 1 << 4, 01890 CALIB_FIX_K2 = 1 << 5, 01891 CALIB_FIX_K3 = 1 << 6, 01892 CALIB_FIX_K4 = 1 << 7, 01893 CALIB_FIX_INTRINSIC = 1 << 8, 01894 CALIB_FIX_PRINCIPAL_POINT = 1 << 9 01895 }; 01896 01897 /** @brief Projects points using fisheye model 01898 01899 @param objectPoints Array of object points, 1xN/Nx1 3-channel (or vector<Point3f> ), where N is 01900 the number of points in the view. 01901 @param imagePoints Output array of image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, or 01902 vector<Point2f>. 01903 @param affine 01904 @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. 01905 @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. 01906 @param alpha The skew coefficient. 01907 @param jacobian Optional output 2Nx15 jacobian matrix of derivatives of image points with respect 01908 to components of the focal lengths, coordinates of the principal point, distortion coefficients, 01909 rotation vector, translation vector, and the skew. In the old interface different components of 01910 the jacobian are returned via different output parameters. 01911 01912 The function computes projections of 3D points to the image plane given intrinsic and extrinsic 01913 camera parameters. Optionally, the function computes Jacobians - matrices of partial derivatives of 01914 image points coordinates (as functions of all the input parameters) with respect to the particular 01915 parameters, intrinsic and/or extrinsic. 01916 */ 01917 CV_EXPORTS void projectPoints(InputArray objectPoints, OutputArray imagePoints, const Affine3d& affine, 01918 InputArray K, InputArray D, double alpha = 0, OutputArray jacobian = noArray()); 01919 01920 /** @overload */ 01921 CV_EXPORTS_W void projectPoints(InputArray objectPoints, OutputArray imagePoints, InputArray rvec, InputArray tvec, 01922 InputArray K, InputArray D, double alpha = 0, OutputArray jacobian = noArray()); 01923 01924 /** @brief Distorts 2D points using fisheye model. 01925 01926 @param undistorted Array of object points, 1xN/Nx1 2-channel (or vector<Point2f> ), where N is 01927 the number of points in the view. 01928 @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. 01929 @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. 01930 @param alpha The skew coefficient. 01931 @param distorted Output array of image points, 1xN/Nx1 2-channel, or vector<Point2f> . 01932 01933 Note that the function assumes the camera matrix of the undistorted points to be indentity. 01934 This means if you want to transform back points undistorted with undistortPoints() you have to 01935 multiply them with \f$P^{-1}\f$. 01936 */ 01937 CV_EXPORTS_W void distortPoints(InputArray undistorted, OutputArray distorted, InputArray K, InputArray D, double alpha = 0); 01938 01939 /** @brief Undistorts 2D points using fisheye model 01940 01941 @param distorted Array of object points, 1xN/Nx1 2-channel (or vector<Point2f> ), where N is the 01942 number of points in the view. 01943 @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. 01944 @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. 01945 @param R Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 01946 1-channel or 1x1 3-channel 01947 @param P New camera matrix (3x3) or new projection matrix (3x4) 01948 @param undistorted Output array of image points, 1xN/Nx1 2-channel, or vector<Point2f> . 01949 */ 01950 CV_EXPORTS_W void undistortPoints(InputArray distorted, OutputArray undistorted, 01951 InputArray K, InputArray D, InputArray R = noArray(), InputArray P = noArray()); 01952 01953 /** @brief Computes undistortion and rectification maps for image transform by cv::remap(). If D is empty zero 01954 distortion is used, if R or P is empty identity matrixes are used. 01955 01956 @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. 01957 @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. 01958 @param R Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 01959 1-channel or 1x1 3-channel 01960 @param P New camera matrix (3x3) or new projection matrix (3x4) 01961 @param size Undistorted image size. 01962 @param m1type Type of the first output map that can be CV_32FC1 or CV_16SC2 . See convertMaps() 01963 for details. 01964 @param map1 The first output map. 01965 @param map2 The second output map. 01966 */ 01967 CV_EXPORTS_W void initUndistortRectifyMap(InputArray K, InputArray D, InputArray R, InputArray P, 01968 const cv::Size& size, int m1type, OutputArray map1, OutputArray map2); 01969 01970 /** @brief Transforms an image to compensate for fisheye lens distortion. 01971 01972 @param distorted image with fisheye lens distortion. 01973 @param undistorted Output image with compensated fisheye lens distortion. 01974 @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. 01975 @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. 01976 @param Knew Camera matrix of the distorted image. By default, it is the identity matrix but you 01977 may additionally scale and shift the result by using a different matrix. 01978 @param new_size 01979 01980 The function transforms an image to compensate radial and tangential lens distortion. 01981 01982 The function is simply a combination of fisheye::initUndistortRectifyMap (with unity R ) and remap 01983 (with bilinear interpolation). See the former function for details of the transformation being 01984 performed. 01985 01986 See below the results of undistortImage. 01987 - a\) result of undistort of perspective camera model (all possible coefficients (k_1, k_2, k_3, 01988 k_4, k_5, k_6) of distortion were optimized under calibration) 01989 - b\) result of fisheye::undistortImage of fisheye camera model (all possible coefficients (k_1, k_2, 01990 k_3, k_4) of fisheye distortion were optimized under calibration) 01991 - c\) original image was captured with fisheye lens 01992 01993 Pictures a) and b) almost the same. But if we consider points of image located far from the center 01994 of image, we can notice that on image a) these points are distorted. 01995 01996  01997 */ 01998 CV_EXPORTS_W void undistortImage(InputArray distorted, OutputArray undistorted, 01999 InputArray K, InputArray D, InputArray Knew = cv::noArray(), const Size& new_size = Size()); 02000 02001 /** @brief Estimates new camera matrix for undistortion or rectification. 02002 02003 @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$. 02004 @param image_size 02005 @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. 02006 @param R Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3 02007 1-channel or 1x1 3-channel 02008 @param P New camera matrix (3x3) or new projection matrix (3x4) 02009 @param balance Sets the new focal length in range between the min focal length and the max focal 02010 length. Balance is in range of [0, 1]. 02011 @param new_size 02012 @param fov_scale Divisor for new focal length. 02013 */ 02014 CV_EXPORTS_W void estimateNewCameraMatrixForUndistortRectify(InputArray K, InputArray D, const Size &image_size, InputArray R, 02015 OutputArray P, double balance = 0.0, const Size& new_size = Size(), double fov_scale = 1.0); 02016 02017 /** @brief Performs camera calibaration 02018 02019 @param objectPoints vector of vectors of calibration pattern points in the calibration pattern 02020 coordinate space. 02021 @param imagePoints vector of vectors of the projections of calibration pattern points. 02022 imagePoints.size() and objectPoints.size() and imagePoints[i].size() must be equal to 02023 objectPoints[i].size() for each i. 02024 @param image_size Size of the image used only to initialize the intrinsic camera matrix. 02025 @param K Output 3x3 floating-point camera matrix 02026 \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . If 02027 fisheye::CALIB_USE_INTRINSIC_GUESS/ is specified, some or all of fx, fy, cx, cy must be 02028 initialized before calling the function. 02029 @param D Output vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$. 02030 @param rvecs Output vector of rotation vectors (see Rodrigues ) estimated for each pattern view. 02031 That is, each k-th rotation vector together with the corresponding k-th translation vector (see 02032 the next output parameter description) brings the calibration pattern from the model coordinate 02033 space (in which object points are specified) to the world coordinate space, that is, a real 02034 position of the calibration pattern in the k-th pattern view (k=0.. *M* -1). 02035 @param tvecs Output vector of translation vectors estimated for each pattern view. 02036 @param flags Different flags that may be zero or a combination of the following values: 02037 - **fisheye::CALIB_USE_INTRINSIC_GUESS** cameraMatrix contains valid initial values of 02038 fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image 02039 center ( imageSize is used), and focal distances are computed in a least-squares fashion. 02040 - **fisheye::CALIB_RECOMPUTE_EXTRINSIC** Extrinsic will be recomputed after each iteration 02041 of intrinsic optimization. 02042 - **fisheye::CALIB_CHECK_COND** The functions will check validity of condition number. 02043 - **fisheye::CALIB_FIX_SKEW** Skew coefficient (alpha) is set to zero and stay zero. 02044 - **fisheye::CALIB_FIX_K1..fisheye::CALIB_FIX_K4** Selected distortion coefficients 02045 are set to zeros and stay zero. 02046 - **fisheye::CALIB_FIX_PRINCIPAL_POINT** The principal point is not changed during the global 02047 optimization. It stays at the center or at a different location specified when CALIB_USE_INTRINSIC_GUESS is set too. 02048 @param criteria Termination criteria for the iterative optimization algorithm. 02049 */ 02050 CV_EXPORTS_W double calibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, const Size& image_size, 02051 InputOutputArray K, InputOutputArray D, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, int flags = 0, 02052 TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 100, DBL_EPSILON)); 02053 02054 /** @brief Stereo rectification for fisheye camera model 02055 02056 @param K1 First camera matrix. 02057 @param D1 First camera distortion parameters. 02058 @param K2 Second camera matrix. 02059 @param D2 Second camera distortion parameters. 02060 @param imageSize Size of the image used for stereo calibration. 02061 @param R Rotation matrix between the coordinate systems of the first and the second 02062 cameras. 02063 @param tvec Translation vector between coordinate systems of the cameras. 02064 @param R1 Output 3x3 rectification transform (rotation matrix) for the first camera. 02065 @param R2 Output 3x3 rectification transform (rotation matrix) for the second camera. 02066 @param P1 Output 3x4 projection matrix in the new (rectified) coordinate systems for the first 02067 camera. 02068 @param P2 Output 3x4 projection matrix in the new (rectified) coordinate systems for the second 02069 camera. 02070 @param Q Output \f$4 \times 4\f$ disparity-to-depth mapping matrix (see reprojectImageTo3D ). 02071 @param flags Operation flags that may be zero or CV_CALIB_ZERO_DISPARITY . If the flag is set, 02072 the function makes the principal points of each camera have the same pixel coordinates in the 02073 rectified views. And if the flag is not set, the function may still shift the images in the 02074 horizontal or vertical direction (depending on the orientation of epipolar lines) to maximize the 02075 useful image area. 02076 @param newImageSize New image resolution after rectification. The same size should be passed to 02077 initUndistortRectifyMap (see the stereo_calib.cpp sample in OpenCV samples directory). When (0,0) 02078 is passed (default), it is set to the original imageSize . Setting it to larger value can help you 02079 preserve details in the original image, especially when there is a big radial distortion. 02080 @param balance Sets the new focal length in range between the min focal length and the max focal 02081 length. Balance is in range of [0, 1]. 02082 @param fov_scale Divisor for new focal length. 02083 */ 02084 CV_EXPORTS_W void stereoRectify(InputArray K1, InputArray D1, InputArray K2, InputArray D2, const Size &imageSize, InputArray R, InputArray tvec, 02085 OutputArray R1, OutputArray R2, OutputArray P1, OutputArray P2, OutputArray Q, int flags, const Size &newImageSize = Size(), 02086 double balance = 0.0, double fov_scale = 1.0); 02087 02088 /** @brief Performs stereo calibration 02089 02090 @param objectPoints Vector of vectors of the calibration pattern points. 02091 @param imagePoints1 Vector of vectors of the projections of the calibration pattern points, 02092 observed by the first camera. 02093 @param imagePoints2 Vector of vectors of the projections of the calibration pattern points, 02094 observed by the second camera. 02095 @param K1 Input/output first camera matrix: 02096 \f$\vecthreethree{f_x^{(j)}}{0}{c_x^{(j)}}{0}{f_y^{(j)}}{c_y^{(j)}}{0}{0}{1}\f$ , \f$j = 0,\, 1\f$ . If 02097 any of fisheye::CALIB_USE_INTRINSIC_GUESS , fisheye::CV_CALIB_FIX_INTRINSIC are specified, 02098 some or all of the matrix components must be initialized. 02099 @param D1 Input/output vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$ of 4 elements. 02100 @param K2 Input/output second camera matrix. The parameter is similar to K1 . 02101 @param D2 Input/output lens distortion coefficients for the second camera. The parameter is 02102 similar to D1 . 02103 @param imageSize Size of the image used only to initialize intrinsic camera matrix. 02104 @param R Output rotation matrix between the 1st and the 2nd camera coordinate systems. 02105 @param T Output translation vector between the coordinate systems of the cameras. 02106 @param flags Different flags that may be zero or a combination of the following values: 02107 - **fisheye::CV_CALIB_FIX_INTRINSIC** Fix K1, K2? and D1, D2? so that only R, T matrices 02108 are estimated. 02109 - **fisheye::CALIB_USE_INTRINSIC_GUESS** K1, K2 contains valid initial values of 02110 fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image 02111 center (imageSize is used), and focal distances are computed in a least-squares fashion. 02112 - **fisheye::CALIB_RECOMPUTE_EXTRINSIC** Extrinsic will be recomputed after each iteration 02113 of intrinsic optimization. 02114 - **fisheye::CALIB_CHECK_COND** The functions will check validity of condition number. 02115 - **fisheye::CALIB_FIX_SKEW** Skew coefficient (alpha) is set to zero and stay zero. 02116 - **fisheye::CALIB_FIX_K1..4** Selected distortion coefficients are set to zeros and stay 02117 zero. 02118 @param criteria Termination criteria for the iterative optimization algorithm. 02119 */ 02120 CV_EXPORTS_W double stereoCalibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2, 02121 InputOutputArray K1, InputOutputArray D1, InputOutputArray K2, InputOutputArray D2, Size imageSize, 02122 OutputArray R, OutputArray T, int flags = fisheye::CALIB_FIX_INTRINSIC, 02123 TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 100, DBL_EPSILON)); 02124 02125 //! @} calib3d_fisheye 02126 } 02127 02128 } // cv 02129 02130 #ifndef DISABLE_OPENCV_24_COMPATIBILITY 02131 #include "opencv2/calib3d/calib3d_c.h" 02132 #endif 02133 02134 #endif
Generated on Tue Jul 12 2022 18:20:16 by
