openCV library for Renesas RZ/A

Dependents:   RZ_A2M_Mbed_samples

Committer:
RyoheiHagimoto
Date:
Fri Jan 29 04:53:38 2021 +0000
Revision:
0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RyoheiHagimoto 0:0e0631af0305 1 /*M///////////////////////////////////////////////////////////////////////////////////////
RyoheiHagimoto 0:0e0631af0305 2 //
RyoheiHagimoto 0:0e0631af0305 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
RyoheiHagimoto 0:0e0631af0305 4 //
RyoheiHagimoto 0:0e0631af0305 5 // By downloading, copying, installing or using the software you agree to this license.
RyoheiHagimoto 0:0e0631af0305 6 // If you do not agree to this license, do not download, install,
RyoheiHagimoto 0:0e0631af0305 7 // copy or use the software.
RyoheiHagimoto 0:0e0631af0305 8 //
RyoheiHagimoto 0:0e0631af0305 9 //
RyoheiHagimoto 0:0e0631af0305 10 // License Agreement
RyoheiHagimoto 0:0e0631af0305 11 // For Open Source Computer Vision Library
RyoheiHagimoto 0:0e0631af0305 12 //
RyoheiHagimoto 0:0e0631af0305 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
RyoheiHagimoto 0:0e0631af0305 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
RyoheiHagimoto 0:0e0631af0305 15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
RyoheiHagimoto 0:0e0631af0305 16 // Third party copyrights are property of their respective owners.
RyoheiHagimoto 0:0e0631af0305 17 //
RyoheiHagimoto 0:0e0631af0305 18 // Redistribution and use in source and binary forms, with or without modification,
RyoheiHagimoto 0:0e0631af0305 19 // are permitted provided that the following conditions are met:
RyoheiHagimoto 0:0e0631af0305 20 //
RyoheiHagimoto 0:0e0631af0305 21 // * Redistribution's of source code must retain the above copyright notice,
RyoheiHagimoto 0:0e0631af0305 22 // this list of conditions and the following disclaimer.
RyoheiHagimoto 0:0e0631af0305 23 //
RyoheiHagimoto 0:0e0631af0305 24 // * Redistribution's in binary form must reproduce the above copyright notice,
RyoheiHagimoto 0:0e0631af0305 25 // this list of conditions and the following disclaimer in the documentation
RyoheiHagimoto 0:0e0631af0305 26 // and/or other materials provided with the distribution.
RyoheiHagimoto 0:0e0631af0305 27 //
RyoheiHagimoto 0:0e0631af0305 28 // * The name of the copyright holders may not be used to endorse or promote products
RyoheiHagimoto 0:0e0631af0305 29 // derived from this software without specific prior written permission.
RyoheiHagimoto 0:0e0631af0305 30 //
RyoheiHagimoto 0:0e0631af0305 31 // This software is provided by the copyright holders and contributors "as is" and
RyoheiHagimoto 0:0e0631af0305 32 // any express or implied warranties, including, but not limited to, the implied
RyoheiHagimoto 0:0e0631af0305 33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
RyoheiHagimoto 0:0e0631af0305 34 // In no event shall the Intel Corporation or contributors be liable for any direct,
RyoheiHagimoto 0:0e0631af0305 35 // indirect, incidental, special, exemplary, or consequential damages
RyoheiHagimoto 0:0e0631af0305 36 // (including, but not limited to, procurement of substitute goods or services;
RyoheiHagimoto 0:0e0631af0305 37 // loss of use, data, or profits; or business interruption) however caused
RyoheiHagimoto 0:0e0631af0305 38 // and on any theory of liability, whether in contract, strict liability,
RyoheiHagimoto 0:0e0631af0305 39 // or tort (including negligence or otherwise) arising in any way out of
RyoheiHagimoto 0:0e0631af0305 40 // the use of this software, even if advised of the possibility of such damage.
RyoheiHagimoto 0:0e0631af0305 41 //
RyoheiHagimoto 0:0e0631af0305 42 //M*/
RyoheiHagimoto 0:0e0631af0305 43
RyoheiHagimoto 0:0e0631af0305 44 #ifndef OPENCV_CALIB3D_HPP
RyoheiHagimoto 0:0e0631af0305 45 #define OPENCV_CALIB3D_HPP
RyoheiHagimoto 0:0e0631af0305 46
RyoheiHagimoto 0:0e0631af0305 47 #include "opencv2/core.hpp"
RyoheiHagimoto 0:0e0631af0305 48 #include "opencv2/features2d.hpp"
RyoheiHagimoto 0:0e0631af0305 49 #include "opencv2/core/affine.hpp"
RyoheiHagimoto 0:0e0631af0305 50
RyoheiHagimoto 0:0e0631af0305 51 /**
RyoheiHagimoto 0:0e0631af0305 52 @defgroup calib3d Camera Calibration and 3D Reconstruction
RyoheiHagimoto 0:0e0631af0305 53
RyoheiHagimoto 0:0e0631af0305 54 The functions in this section use a so-called pinhole camera model. In this model, a scene view is
RyoheiHagimoto 0:0e0631af0305 55 formed by projecting 3D points into the image plane using a perspective transformation.
RyoheiHagimoto 0:0e0631af0305 56
RyoheiHagimoto 0:0e0631af0305 57 \f[s \; m' = A [R|t] M'\f]
RyoheiHagimoto 0:0e0631af0305 58
RyoheiHagimoto 0:0e0631af0305 59 or
RyoheiHagimoto 0:0e0631af0305 60
RyoheiHagimoto 0:0e0631af0305 61 \f[s \vecthree{u}{v}{1} = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}
RyoheiHagimoto 0:0e0631af0305 62 \begin{bmatrix}
RyoheiHagimoto 0:0e0631af0305 63 r_{11} & r_{12} & r_{13} & t_1 \\
RyoheiHagimoto 0:0e0631af0305 64 r_{21} & r_{22} & r_{23} & t_2 \\
RyoheiHagimoto 0:0e0631af0305 65 r_{31} & r_{32} & r_{33} & t_3
RyoheiHagimoto 0:0e0631af0305 66 \end{bmatrix}
RyoheiHagimoto 0:0e0631af0305 67 \begin{bmatrix}
RyoheiHagimoto 0:0e0631af0305 68 X \\
RyoheiHagimoto 0:0e0631af0305 69 Y \\
RyoheiHagimoto 0:0e0631af0305 70 Z \\
RyoheiHagimoto 0:0e0631af0305 71 1
RyoheiHagimoto 0:0e0631af0305 72 \end{bmatrix}\f]
RyoheiHagimoto 0:0e0631af0305 73
RyoheiHagimoto 0:0e0631af0305 74 where:
RyoheiHagimoto 0:0e0631af0305 75
RyoheiHagimoto 0:0e0631af0305 76 - \f$(X, Y, Z)\f$ are the coordinates of a 3D point in the world coordinate space
RyoheiHagimoto 0:0e0631af0305 77 - \f$(u, v)\f$ are the coordinates of the projection point in pixels
RyoheiHagimoto 0:0e0631af0305 78 - \f$A\f$ is a camera matrix, or a matrix of intrinsic parameters
RyoheiHagimoto 0:0e0631af0305 79 - \f$(cx, cy)\f$ is a principal point that is usually at the image center
RyoheiHagimoto 0:0e0631af0305 80 - \f$fx, fy\f$ are the focal lengths expressed in pixel units.
RyoheiHagimoto 0:0e0631af0305 81
RyoheiHagimoto 0:0e0631af0305 82 Thus, if an image from the camera is scaled by a factor, all of these parameters should be scaled
RyoheiHagimoto 0:0e0631af0305 83 (multiplied/divided, respectively) by the same factor. The matrix of intrinsic parameters does not
RyoheiHagimoto 0:0e0631af0305 84 depend on the scene viewed. So, once estimated, it can be re-used as long as the focal length is
RyoheiHagimoto 0:0e0631af0305 85 fixed (in case of zoom lens). The joint rotation-translation matrix \f$[R|t]\f$ is called a matrix of
RyoheiHagimoto 0:0e0631af0305 86 extrinsic parameters. It is used to describe the camera motion around a static scene, or vice versa,
RyoheiHagimoto 0:0e0631af0305 87 rigid motion of an object in front of a still camera. That is, \f$[R|t]\f$ translates coordinates of a
RyoheiHagimoto 0:0e0631af0305 88 point \f$(X, Y, Z)\f$ to a coordinate system, fixed with respect to the camera. The transformation above
RyoheiHagimoto 0:0e0631af0305 89 is equivalent to the following (when \f$z \ne 0\f$ ):
RyoheiHagimoto 0:0e0631af0305 90
RyoheiHagimoto 0:0e0631af0305 91 \f[\begin{array}{l}
RyoheiHagimoto 0:0e0631af0305 92 \vecthree{x}{y}{z} = R \vecthree{X}{Y}{Z} + t \\
RyoheiHagimoto 0:0e0631af0305 93 x' = x/z \\
RyoheiHagimoto 0:0e0631af0305 94 y' = y/z \\
RyoheiHagimoto 0:0e0631af0305 95 u = f_x*x' + c_x \\
RyoheiHagimoto 0:0e0631af0305 96 v = f_y*y' + c_y
RyoheiHagimoto 0:0e0631af0305 97 \end{array}\f]
RyoheiHagimoto 0:0e0631af0305 98
RyoheiHagimoto 0:0e0631af0305 99 The following figure illustrates the pinhole camera model.
RyoheiHagimoto 0:0e0631af0305 100
RyoheiHagimoto 0:0e0631af0305 101 ![Pinhole camera model](pics/pinhole_camera_model.png)
RyoheiHagimoto 0:0e0631af0305 102
RyoheiHagimoto 0:0e0631af0305 103 Real lenses usually have some distortion, mostly radial distortion and slight tangential distortion.
RyoheiHagimoto 0:0e0631af0305 104 So, the above model is extended as:
RyoheiHagimoto 0:0e0631af0305 105
RyoheiHagimoto 0:0e0631af0305 106 \f[\begin{array}{l}
RyoheiHagimoto 0:0e0631af0305 107 \vecthree{x}{y}{z} = R \vecthree{X}{Y}{Z} + t \\
RyoheiHagimoto 0:0e0631af0305 108 x' = x/z \\
RyoheiHagimoto 0:0e0631af0305 109 y' = y/z \\
RyoheiHagimoto 0:0e0631af0305 110 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 \\
RyoheiHagimoto 0:0e0631af0305 111 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 \\
RyoheiHagimoto 0:0e0631af0305 112 \text{where} \quad r^2 = x'^2 + y'^2 \\
RyoheiHagimoto 0:0e0631af0305 113 u = f_x*x'' + c_x \\
RyoheiHagimoto 0:0e0631af0305 114 v = f_y*y'' + c_y
RyoheiHagimoto 0:0e0631af0305 115 \end{array}\f]
RyoheiHagimoto 0:0e0631af0305 116
RyoheiHagimoto 0:0e0631af0305 117 \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
RyoheiHagimoto 0:0e0631af0305 118 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
RyoheiHagimoto 0:0e0631af0305 119 coefficients. Higher-order coefficients are not considered in OpenCV.
RyoheiHagimoto 0:0e0631af0305 120
RyoheiHagimoto 0:0e0631af0305 121 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$).
RyoheiHagimoto 0:0e0631af0305 122
RyoheiHagimoto 0:0e0631af0305 123 ![](pics/distortion_examples.png)
RyoheiHagimoto 0:0e0631af0305 124
RyoheiHagimoto 0:0e0631af0305 125 In some cases the image sensor may be tilted in order to focus an oblique plane in front of the
RyoheiHagimoto 0:0e0631af0305 126 camera (Scheimpfug condition). This can be useful for particle image velocimetry (PIV) or
RyoheiHagimoto 0:0e0631af0305 127 triangulation with a laser fan. The tilt causes a perspective distortion of \f$x''\f$ and
RyoheiHagimoto 0:0e0631af0305 128 \f$y''\f$. This distortion can be modelled in the following way, see e.g. @cite Louhichi07.
RyoheiHagimoto 0:0e0631af0305 129
RyoheiHagimoto 0:0e0631af0305 130 \f[\begin{array}{l}
RyoheiHagimoto 0:0e0631af0305 131 s\vecthree{x'''}{y'''}{1} =
RyoheiHagimoto 0:0e0631af0305 132 \vecthreethree{R_{33}(\tau_x, \tau_y)}{0}{-R_{13}(\tau_x, \tau_y)}
RyoheiHagimoto 0:0e0631af0305 133 {0}{R_{33}(\tau_x, \tau_y)}{-R_{23}(\tau_x, \tau_y)}
RyoheiHagimoto 0:0e0631af0305 134 {0}{0}{1} R(\tau_x, \tau_y) \vecthree{x''}{y''}{1}\\
RyoheiHagimoto 0:0e0631af0305 135 u = f_x*x''' + c_x \\
RyoheiHagimoto 0:0e0631af0305 136 v = f_y*y''' + c_y
RyoheiHagimoto 0:0e0631af0305 137 \end{array}\f]
RyoheiHagimoto 0:0e0631af0305 138
RyoheiHagimoto 0:0e0631af0305 139 where the matrix \f$R(\tau_x, \tau_y)\f$ is defined by two rotations with angular parameter \f$\tau_x\f$
RyoheiHagimoto 0:0e0631af0305 140 and \f$\tau_y\f$, respectively,
RyoheiHagimoto 0:0e0631af0305 141
RyoheiHagimoto 0:0e0631af0305 142 \f[
RyoheiHagimoto 0:0e0631af0305 143 R(\tau_x, \tau_y) =
RyoheiHagimoto 0:0e0631af0305 144 \vecthreethree{\cos(\tau_y)}{0}{-\sin(\tau_y)}{0}{1}{0}{\sin(\tau_y)}{0}{\cos(\tau_y)}
RyoheiHagimoto 0:0e0631af0305 145 \vecthreethree{1}{0}{0}{0}{\cos(\tau_x)}{\sin(\tau_x)}{0}{-\sin(\tau_x)}{\cos(\tau_x)} =
RyoheiHagimoto 0:0e0631af0305 146 \vecthreethree{\cos(\tau_y)}{\sin(\tau_y)\sin(\tau_x)}{-\sin(\tau_y)\cos(\tau_x)}
RyoheiHagimoto 0:0e0631af0305 147 {0}{\cos(\tau_x)}{\sin(\tau_x)}
RyoheiHagimoto 0:0e0631af0305 148 {\sin(\tau_y)}{-\cos(\tau_y)\sin(\tau_x)}{\cos(\tau_y)\cos(\tau_x)}.
RyoheiHagimoto 0:0e0631af0305 149 \f]
RyoheiHagimoto 0:0e0631af0305 150
RyoheiHagimoto 0:0e0631af0305 151 In the functions below the coefficients are passed or returned as
RyoheiHagimoto 0:0e0631af0305 152
RyoheiHagimoto 0:0e0631af0305 153 \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]
RyoheiHagimoto 0:0e0631af0305 154
RyoheiHagimoto 0:0e0631af0305 155 vector. That is, if the vector contains four elements, it means that \f$k_3=0\f$ . The distortion
RyoheiHagimoto 0:0e0631af0305 156 coefficients do not depend on the scene viewed. Thus, they also belong to the intrinsic camera
RyoheiHagimoto 0:0e0631af0305 157 parameters. And they remain the same regardless of the captured image resolution. If, for example, a
RyoheiHagimoto 0:0e0631af0305 158 camera has been calibrated on images of 320 x 240 resolution, absolutely the same distortion
RyoheiHagimoto 0:0e0631af0305 159 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
RyoheiHagimoto 0:0e0631af0305 160 \f$c_y\f$ need to be scaled appropriately.
RyoheiHagimoto 0:0e0631af0305 161
RyoheiHagimoto 0:0e0631af0305 162 The functions below use the above model to do the following:
RyoheiHagimoto 0:0e0631af0305 163
RyoheiHagimoto 0:0e0631af0305 164 - Project 3D points to the image plane given intrinsic and extrinsic parameters.
RyoheiHagimoto 0:0e0631af0305 165 - Compute extrinsic parameters given intrinsic parameters, a few 3D points, and their
RyoheiHagimoto 0:0e0631af0305 166 projections.
RyoheiHagimoto 0:0e0631af0305 167 - Estimate intrinsic and extrinsic camera parameters from several views of a known calibration
RyoheiHagimoto 0:0e0631af0305 168 pattern (every view is described by several 3D-2D point correspondences).
RyoheiHagimoto 0:0e0631af0305 169 - Estimate the relative position and orientation of the stereo camera "heads" and compute the
RyoheiHagimoto 0:0e0631af0305 170 *rectification* transformation that makes the camera optical axes parallel.
RyoheiHagimoto 0:0e0631af0305 171
RyoheiHagimoto 0:0e0631af0305 172 @note
RyoheiHagimoto 0:0e0631af0305 173 - A calibration sample for 3 cameras in horizontal position can be found at
RyoheiHagimoto 0:0e0631af0305 174 opencv_source_code/samples/cpp/3calibration.cpp
RyoheiHagimoto 0:0e0631af0305 175 - A calibration sample based on a sequence of images can be found at
RyoheiHagimoto 0:0e0631af0305 176 opencv_source_code/samples/cpp/calibration.cpp
RyoheiHagimoto 0:0e0631af0305 177 - A calibration sample in order to do 3D reconstruction can be found at
RyoheiHagimoto 0:0e0631af0305 178 opencv_source_code/samples/cpp/build3dmodel.cpp
RyoheiHagimoto 0:0e0631af0305 179 - A calibration sample of an artificially generated camera and chessboard patterns can be
RyoheiHagimoto 0:0e0631af0305 180 found at opencv_source_code/samples/cpp/calibration_artificial.cpp
RyoheiHagimoto 0:0e0631af0305 181 - A calibration example on stereo calibration can be found at
RyoheiHagimoto 0:0e0631af0305 182 opencv_source_code/samples/cpp/stereo_calib.cpp
RyoheiHagimoto 0:0e0631af0305 183 - A calibration example on stereo matching can be found at
RyoheiHagimoto 0:0e0631af0305 184 opencv_source_code/samples/cpp/stereo_match.cpp
RyoheiHagimoto 0:0e0631af0305 185 - (Python) A camera calibration sample can be found at
RyoheiHagimoto 0:0e0631af0305 186 opencv_source_code/samples/python/calibrate.py
RyoheiHagimoto 0:0e0631af0305 187
RyoheiHagimoto 0:0e0631af0305 188 @{
RyoheiHagimoto 0:0e0631af0305 189 @defgroup calib3d_fisheye Fisheye camera model
RyoheiHagimoto 0:0e0631af0305 190
RyoheiHagimoto 0:0e0631af0305 191 Definitions: Let P be a point in 3D of coordinates X in the world reference frame (stored in the
RyoheiHagimoto 0:0e0631af0305 192 matrix X) The coordinate vector of P in the camera reference frame is:
RyoheiHagimoto 0:0e0631af0305 193
RyoheiHagimoto 0:0e0631af0305 194 \f[Xc = R X + T\f]
RyoheiHagimoto 0:0e0631af0305 195
RyoheiHagimoto 0:0e0631af0305 196 where R is the rotation matrix corresponding to the rotation vector om: R = rodrigues(om); call x, y
RyoheiHagimoto 0:0e0631af0305 197 and z the 3 coordinates of Xc:
RyoheiHagimoto 0:0e0631af0305 198
RyoheiHagimoto 0:0e0631af0305 199 \f[x = Xc_1 \\ y = Xc_2 \\ z = Xc_3\f]
RyoheiHagimoto 0:0e0631af0305 200
RyoheiHagimoto 0:0e0631af0305 201 The pinhole projection coordinates of P is [a; b] where
RyoheiHagimoto 0:0e0631af0305 202
RyoheiHagimoto 0:0e0631af0305 203 \f[a = x / z \ and \ b = y / z \\ r^2 = a^2 + b^2 \\ \theta = atan(r)\f]
RyoheiHagimoto 0:0e0631af0305 204
RyoheiHagimoto 0:0e0631af0305 205 Fisheye distortion:
RyoheiHagimoto 0:0e0631af0305 206
RyoheiHagimoto 0:0e0631af0305 207 \f[\theta_d = \theta (1 + k_1 \theta^2 + k_2 \theta^4 + k_3 \theta^6 + k_4 \theta^8)\f]
RyoheiHagimoto 0:0e0631af0305 208
RyoheiHagimoto 0:0e0631af0305 209 The distorted point coordinates are [x'; y'] where
RyoheiHagimoto 0:0e0631af0305 210
RyoheiHagimoto 0:0e0631af0305 211 \f[x' = (\theta_d / r) a \\ y' = (\theta_d / r) b \f]
RyoheiHagimoto 0:0e0631af0305 212
RyoheiHagimoto 0:0e0631af0305 213 Finally, conversion into pixel coordinates: The final pixel coordinates vector [u; v] where:
RyoheiHagimoto 0:0e0631af0305 214
RyoheiHagimoto 0:0e0631af0305 215 \f[u = f_x (x' + \alpha y') + c_x \\
RyoheiHagimoto 0:0e0631af0305 216 v = f_y y' + c_y\f]
RyoheiHagimoto 0:0e0631af0305 217
RyoheiHagimoto 0:0e0631af0305 218 @defgroup calib3d_c C API
RyoheiHagimoto 0:0e0631af0305 219
RyoheiHagimoto 0:0e0631af0305 220 @}
RyoheiHagimoto 0:0e0631af0305 221 */
RyoheiHagimoto 0:0e0631af0305 222
RyoheiHagimoto 0:0e0631af0305 223 namespace cv
RyoheiHagimoto 0:0e0631af0305 224 {
RyoheiHagimoto 0:0e0631af0305 225
RyoheiHagimoto 0:0e0631af0305 226 //! @addtogroup calib3d
RyoheiHagimoto 0:0e0631af0305 227 //! @{
RyoheiHagimoto 0:0e0631af0305 228
RyoheiHagimoto 0:0e0631af0305 229 //! type of the robust estimation algorithm
RyoheiHagimoto 0:0e0631af0305 230 enum { LMEDS = 4, //!< least-median algorithm
RyoheiHagimoto 0:0e0631af0305 231 RANSAC = 8, //!< RANSAC algorithm
RyoheiHagimoto 0:0e0631af0305 232 RHO = 16 //!< RHO algorithm
RyoheiHagimoto 0:0e0631af0305 233 };
RyoheiHagimoto 0:0e0631af0305 234
RyoheiHagimoto 0:0e0631af0305 235 enum { SOLVEPNP_ITERATIVE = 0,
RyoheiHagimoto 0:0e0631af0305 236 SOLVEPNP_EPNP = 1, //!< EPnP: Efficient Perspective-n-Point Camera Pose Estimation @cite lepetit2009epnp
RyoheiHagimoto 0:0e0631af0305 237 SOLVEPNP_P3P = 2, //!< Complete Solution Classification for the Perspective-Three-Point Problem @cite gao2003complete
RyoheiHagimoto 0:0e0631af0305 238 SOLVEPNP_DLS = 3, //!< A Direct Least-Squares (DLS) Method for PnP @cite hesch2011direct
RyoheiHagimoto 0:0e0631af0305 239 SOLVEPNP_UPNP = 4 //!< Exhaustive Linearization for Robust Camera Pose and Focal Length Estimation @cite penate2013exhaustive
RyoheiHagimoto 0:0e0631af0305 240
RyoheiHagimoto 0:0e0631af0305 241 };
RyoheiHagimoto 0:0e0631af0305 242
RyoheiHagimoto 0:0e0631af0305 243 enum { CALIB_CB_ADAPTIVE_THRESH = 1,
RyoheiHagimoto 0:0e0631af0305 244 CALIB_CB_NORMALIZE_IMAGE = 2,
RyoheiHagimoto 0:0e0631af0305 245 CALIB_CB_FILTER_QUADS = 4,
RyoheiHagimoto 0:0e0631af0305 246 CALIB_CB_FAST_CHECK = 8
RyoheiHagimoto 0:0e0631af0305 247 };
RyoheiHagimoto 0:0e0631af0305 248
RyoheiHagimoto 0:0e0631af0305 249 enum { CALIB_CB_SYMMETRIC_GRID = 1,
RyoheiHagimoto 0:0e0631af0305 250 CALIB_CB_ASYMMETRIC_GRID = 2,
RyoheiHagimoto 0:0e0631af0305 251 CALIB_CB_CLUSTERING = 4
RyoheiHagimoto 0:0e0631af0305 252 };
RyoheiHagimoto 0:0e0631af0305 253
RyoheiHagimoto 0:0e0631af0305 254 enum { CALIB_USE_INTRINSIC_GUESS = 0x00001,
RyoheiHagimoto 0:0e0631af0305 255 CALIB_FIX_ASPECT_RATIO = 0x00002,
RyoheiHagimoto 0:0e0631af0305 256 CALIB_FIX_PRINCIPAL_POINT = 0x00004,
RyoheiHagimoto 0:0e0631af0305 257 CALIB_ZERO_TANGENT_DIST = 0x00008,
RyoheiHagimoto 0:0e0631af0305 258 CALIB_FIX_FOCAL_LENGTH = 0x00010,
RyoheiHagimoto 0:0e0631af0305 259 CALIB_FIX_K1 = 0x00020,
RyoheiHagimoto 0:0e0631af0305 260 CALIB_FIX_K2 = 0x00040,
RyoheiHagimoto 0:0e0631af0305 261 CALIB_FIX_K3 = 0x00080,
RyoheiHagimoto 0:0e0631af0305 262 CALIB_FIX_K4 = 0x00800,
RyoheiHagimoto 0:0e0631af0305 263 CALIB_FIX_K5 = 0x01000,
RyoheiHagimoto 0:0e0631af0305 264 CALIB_FIX_K6 = 0x02000,
RyoheiHagimoto 0:0e0631af0305 265 CALIB_RATIONAL_MODEL = 0x04000,
RyoheiHagimoto 0:0e0631af0305 266 CALIB_THIN_PRISM_MODEL = 0x08000,
RyoheiHagimoto 0:0e0631af0305 267 CALIB_FIX_S1_S2_S3_S4 = 0x10000,
RyoheiHagimoto 0:0e0631af0305 268 CALIB_TILTED_MODEL = 0x40000,
RyoheiHagimoto 0:0e0631af0305 269 CALIB_FIX_TAUX_TAUY = 0x80000,
RyoheiHagimoto 0:0e0631af0305 270 CALIB_USE_QR = 0x100000, //!< use QR instead of SVD decomposition for solving. Faster but potentially less precise
RyoheiHagimoto 0:0e0631af0305 271 // only for stereo
RyoheiHagimoto 0:0e0631af0305 272 CALIB_FIX_INTRINSIC = 0x00100,
RyoheiHagimoto 0:0e0631af0305 273 CALIB_SAME_FOCAL_LENGTH = 0x00200,
RyoheiHagimoto 0:0e0631af0305 274 // for stereo rectification
RyoheiHagimoto 0:0e0631af0305 275 CALIB_ZERO_DISPARITY = 0x00400,
RyoheiHagimoto 0:0e0631af0305 276 CALIB_USE_LU = (1 << 17), //!< use LU instead of SVD decomposition for solving. much faster but potentially less precise
RyoheiHagimoto 0:0e0631af0305 277 };
RyoheiHagimoto 0:0e0631af0305 278
RyoheiHagimoto 0:0e0631af0305 279 //! the algorithm for finding fundamental matrix
RyoheiHagimoto 0:0e0631af0305 280 enum { FM_7POINT = 1, //!< 7-point algorithm
RyoheiHagimoto 0:0e0631af0305 281 FM_8POINT = 2, //!< 8-point algorithm
RyoheiHagimoto 0:0e0631af0305 282 FM_LMEDS = 4, //!< least-median algorithm
RyoheiHagimoto 0:0e0631af0305 283 FM_RANSAC = 8 //!< RANSAC algorithm
RyoheiHagimoto 0:0e0631af0305 284 };
RyoheiHagimoto 0:0e0631af0305 285
RyoheiHagimoto 0:0e0631af0305 286
RyoheiHagimoto 0:0e0631af0305 287
RyoheiHagimoto 0:0e0631af0305 288 /** @brief Converts a rotation matrix to a rotation vector or vice versa.
RyoheiHagimoto 0:0e0631af0305 289
RyoheiHagimoto 0:0e0631af0305 290 @param src Input rotation vector (3x1 or 1x3) or rotation matrix (3x3).
RyoheiHagimoto 0:0e0631af0305 291 @param dst Output rotation matrix (3x3) or rotation vector (3x1 or 1x3), respectively.
RyoheiHagimoto 0:0e0631af0305 292 @param jacobian Optional output Jacobian matrix, 3x9 or 9x3, which is a matrix of partial
RyoheiHagimoto 0:0e0631af0305 293 derivatives of the output array components with respect to the input array components.
RyoheiHagimoto 0:0e0631af0305 294
RyoheiHagimoto 0:0e0631af0305 295 \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]
RyoheiHagimoto 0:0e0631af0305 296
RyoheiHagimoto 0:0e0631af0305 297 Inverse transformation can be also done easily, since
RyoheiHagimoto 0:0e0631af0305 298
RyoheiHagimoto 0:0e0631af0305 299 \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]
RyoheiHagimoto 0:0e0631af0305 300
RyoheiHagimoto 0:0e0631af0305 301 A rotation vector is a convenient and most compact representation of a rotation matrix (since any
RyoheiHagimoto 0:0e0631af0305 302 rotation matrix has just 3 degrees of freedom). The representation is used in the global 3D geometry
RyoheiHagimoto 0:0e0631af0305 303 optimization procedures like calibrateCamera, stereoCalibrate, or solvePnP .
RyoheiHagimoto 0:0e0631af0305 304 */
RyoheiHagimoto 0:0e0631af0305 305 CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
RyoheiHagimoto 0:0e0631af0305 306
RyoheiHagimoto 0:0e0631af0305 307 /** @brief Finds a perspective transformation between two planes.
RyoheiHagimoto 0:0e0631af0305 308
RyoheiHagimoto 0:0e0631af0305 309 @param srcPoints Coordinates of the points in the original plane, a matrix of the type CV_32FC2
RyoheiHagimoto 0:0e0631af0305 310 or vector\<Point2f\> .
RyoheiHagimoto 0:0e0631af0305 311 @param dstPoints Coordinates of the points in the target plane, a matrix of the type CV_32FC2 or
RyoheiHagimoto 0:0e0631af0305 312 a vector\<Point2f\> .
RyoheiHagimoto 0:0e0631af0305 313 @param method Method used to computed a homography matrix. The following methods are possible:
RyoheiHagimoto 0:0e0631af0305 314 - **0** - a regular method using all the points
RyoheiHagimoto 0:0e0631af0305 315 - **RANSAC** - RANSAC-based robust method
RyoheiHagimoto 0:0e0631af0305 316 - **LMEDS** - Least-Median robust method
RyoheiHagimoto 0:0e0631af0305 317 - **RHO** - PROSAC-based robust method
RyoheiHagimoto 0:0e0631af0305 318 @param ransacReprojThreshold Maximum allowed reprojection error to treat a point pair as an inlier
RyoheiHagimoto 0:0e0631af0305 319 (used in the RANSAC and RHO methods only). That is, if
RyoheiHagimoto 0:0e0631af0305 320 \f[\| \texttt{dstPoints} _i - \texttt{convertPointsHomogeneous} ( \texttt{H} * \texttt{srcPoints} _i) \| > \texttt{ransacReprojThreshold}\f]
RyoheiHagimoto 0:0e0631af0305 321 then the point \f$i\f$ is considered an outlier. If srcPoints and dstPoints are measured in pixels,
RyoheiHagimoto 0:0e0631af0305 322 it usually makes sense to set this parameter somewhere in the range of 1 to 10.
RyoheiHagimoto 0:0e0631af0305 323 @param mask Optional output mask set by a robust method ( RANSAC or LMEDS ). Note that the input
RyoheiHagimoto 0:0e0631af0305 324 mask values are ignored.
RyoheiHagimoto 0:0e0631af0305 325 @param maxIters The maximum number of RANSAC iterations, 2000 is the maximum it can be.
RyoheiHagimoto 0:0e0631af0305 326 @param confidence Confidence level, between 0 and 1.
RyoheiHagimoto 0:0e0631af0305 327
RyoheiHagimoto 0:0e0631af0305 328 The function finds and returns the perspective transformation \f$H\f$ between the source and the
RyoheiHagimoto 0:0e0631af0305 329 destination planes:
RyoheiHagimoto 0:0e0631af0305 330
RyoheiHagimoto 0:0e0631af0305 331 \f[s_i \vecthree{x'_i}{y'_i}{1} \sim H \vecthree{x_i}{y_i}{1}\f]
RyoheiHagimoto 0:0e0631af0305 332
RyoheiHagimoto 0:0e0631af0305 333 so that the back-projection error
RyoheiHagimoto 0:0e0631af0305 334
RyoheiHagimoto 0:0e0631af0305 335 \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]
RyoheiHagimoto 0:0e0631af0305 336
RyoheiHagimoto 0:0e0631af0305 337 is minimized. If the parameter method is set to the default value 0, the function uses all the point
RyoheiHagimoto 0:0e0631af0305 338 pairs to compute an initial homography estimate with a simple least-squares scheme.
RyoheiHagimoto 0:0e0631af0305 339
RyoheiHagimoto 0:0e0631af0305 340 However, if not all of the point pairs ( \f$srcPoints_i\f$, \f$dstPoints_i\f$ ) fit the rigid perspective
RyoheiHagimoto 0:0e0631af0305 341 transformation (that is, there are some outliers), this initial estimate will be poor. In this case,
RyoheiHagimoto 0:0e0631af0305 342 you can use one of the three robust methods. The methods RANSAC, LMeDS and RHO try many different
RyoheiHagimoto 0:0e0631af0305 343 random subsets of the corresponding point pairs (of four pairs each), estimate the homography matrix
RyoheiHagimoto 0:0e0631af0305 344 using this subset and a simple least-square algorithm, and then compute the quality/goodness of the
RyoheiHagimoto 0:0e0631af0305 345 computed homography (which is the number of inliers for RANSAC or the median re-projection error for
RyoheiHagimoto 0:0e0631af0305 346 LMeDs). The best subset is then used to produce the initial estimate of the homography matrix and
RyoheiHagimoto 0:0e0631af0305 347 the mask of inliers/outliers.
RyoheiHagimoto 0:0e0631af0305 348
RyoheiHagimoto 0:0e0631af0305 349 Regardless of the method, robust or not, the computed homography matrix is refined further (using
RyoheiHagimoto 0:0e0631af0305 350 inliers only in case of a robust method) with the Levenberg-Marquardt method to reduce the
RyoheiHagimoto 0:0e0631af0305 351 re-projection error even more.
RyoheiHagimoto 0:0e0631af0305 352
RyoheiHagimoto 0:0e0631af0305 353 The methods RANSAC and RHO can handle practically any ratio of outliers but need a threshold to
RyoheiHagimoto 0:0e0631af0305 354 distinguish inliers from outliers. The method LMeDS does not need any threshold but it works
RyoheiHagimoto 0:0e0631af0305 355 correctly only when there are more than 50% of inliers. Finally, if there are no outliers and the
RyoheiHagimoto 0:0e0631af0305 356 noise is rather small, use the default method (method=0).
RyoheiHagimoto 0:0e0631af0305 357
RyoheiHagimoto 0:0e0631af0305 358 The function is used to find initial intrinsic and extrinsic matrices. Homography matrix is
RyoheiHagimoto 0:0e0631af0305 359 determined up to a scale. Thus, it is normalized so that \f$h_{33}=1\f$. Note that whenever an H matrix
RyoheiHagimoto 0:0e0631af0305 360 cannot be estimated, an empty one will be returned.
RyoheiHagimoto 0:0e0631af0305 361
RyoheiHagimoto 0:0e0631af0305 362 @sa
RyoheiHagimoto 0:0e0631af0305 363 getAffineTransform, estimateAffine2D, estimateAffinePartial2D, getPerspectiveTransform, warpPerspective,
RyoheiHagimoto 0:0e0631af0305 364 perspectiveTransform
RyoheiHagimoto 0:0e0631af0305 365
RyoheiHagimoto 0:0e0631af0305 366
RyoheiHagimoto 0:0e0631af0305 367 @note
RyoheiHagimoto 0:0e0631af0305 368 - A example on calculating a homography for image matching can be found at
RyoheiHagimoto 0:0e0631af0305 369 opencv_source_code/samples/cpp/video_homography.cpp
RyoheiHagimoto 0:0e0631af0305 370
RyoheiHagimoto 0:0e0631af0305 371 */
RyoheiHagimoto 0:0e0631af0305 372 CV_EXPORTS_W Mat findHomography( InputArray srcPoints, InputArray dstPoints,
RyoheiHagimoto 0:0e0631af0305 373 int method = 0, double ransacReprojThreshold = 3,
RyoheiHagimoto 0:0e0631af0305 374 OutputArray mask=noArray(), const int maxIters = 2000,
RyoheiHagimoto 0:0e0631af0305 375 const double confidence = 0.995);
RyoheiHagimoto 0:0e0631af0305 376
RyoheiHagimoto 0:0e0631af0305 377 /** @overload */
RyoheiHagimoto 0:0e0631af0305 378 CV_EXPORTS Mat findHomography( InputArray srcPoints, InputArray dstPoints,
RyoheiHagimoto 0:0e0631af0305 379 OutputArray mask, int method = 0, double ransacReprojThreshold = 3 );
RyoheiHagimoto 0:0e0631af0305 380
RyoheiHagimoto 0:0e0631af0305 381 /** @brief Computes an RQ decomposition of 3x3 matrices.
RyoheiHagimoto 0:0e0631af0305 382
RyoheiHagimoto 0:0e0631af0305 383 @param src 3x3 input matrix.
RyoheiHagimoto 0:0e0631af0305 384 @param mtxR Output 3x3 upper-triangular matrix.
RyoheiHagimoto 0:0e0631af0305 385 @param mtxQ Output 3x3 orthogonal matrix.
RyoheiHagimoto 0:0e0631af0305 386 @param Qx Optional output 3x3 rotation matrix around x-axis.
RyoheiHagimoto 0:0e0631af0305 387 @param Qy Optional output 3x3 rotation matrix around y-axis.
RyoheiHagimoto 0:0e0631af0305 388 @param Qz Optional output 3x3 rotation matrix around z-axis.
RyoheiHagimoto 0:0e0631af0305 389
RyoheiHagimoto 0:0e0631af0305 390 The function computes a RQ decomposition using the given rotations. This function is used in
RyoheiHagimoto 0:0e0631af0305 391 decomposeProjectionMatrix to decompose the left 3x3 submatrix of a projection matrix into a camera
RyoheiHagimoto 0:0e0631af0305 392 and a rotation matrix.
RyoheiHagimoto 0:0e0631af0305 393
RyoheiHagimoto 0:0e0631af0305 394 It optionally returns three rotation matrices, one for each axis, and the three Euler angles in
RyoheiHagimoto 0:0e0631af0305 395 degrees (as the return value) that could be used in OpenGL. Note, there is always more than one
RyoheiHagimoto 0:0e0631af0305 396 sequence of rotations about the three principal axes that results in the same orientation of an
RyoheiHagimoto 0:0e0631af0305 397 object, eg. see @cite Slabaugh . Returned tree rotation matrices and corresponding three Euler angules
RyoheiHagimoto 0:0e0631af0305 398 are only one of the possible solutions.
RyoheiHagimoto 0:0e0631af0305 399 */
RyoheiHagimoto 0:0e0631af0305 400 CV_EXPORTS_W Vec3d RQDecomp3x3( InputArray src, OutputArray mtxR, OutputArray mtxQ,
RyoheiHagimoto 0:0e0631af0305 401 OutputArray Qx = noArray(),
RyoheiHagimoto 0:0e0631af0305 402 OutputArray Qy = noArray(),
RyoheiHagimoto 0:0e0631af0305 403 OutputArray Qz = noArray());
RyoheiHagimoto 0:0e0631af0305 404
RyoheiHagimoto 0:0e0631af0305 405 /** @brief Decomposes a projection matrix into a rotation matrix and a camera matrix.
RyoheiHagimoto 0:0e0631af0305 406
RyoheiHagimoto 0:0e0631af0305 407 @param projMatrix 3x4 input projection matrix P.
RyoheiHagimoto 0:0e0631af0305 408 @param cameraMatrix Output 3x3 camera matrix K.
RyoheiHagimoto 0:0e0631af0305 409 @param rotMatrix Output 3x3 external rotation matrix R.
RyoheiHagimoto 0:0e0631af0305 410 @param transVect Output 4x1 translation vector T.
RyoheiHagimoto 0:0e0631af0305 411 @param rotMatrixX Optional 3x3 rotation matrix around x-axis.
RyoheiHagimoto 0:0e0631af0305 412 @param rotMatrixY Optional 3x3 rotation matrix around y-axis.
RyoheiHagimoto 0:0e0631af0305 413 @param rotMatrixZ Optional 3x3 rotation matrix around z-axis.
RyoheiHagimoto 0:0e0631af0305 414 @param eulerAngles Optional three-element vector containing three Euler angles of rotation in
RyoheiHagimoto 0:0e0631af0305 415 degrees.
RyoheiHagimoto 0:0e0631af0305 416
RyoheiHagimoto 0:0e0631af0305 417 The function computes a decomposition of a projection matrix into a calibration and a rotation
RyoheiHagimoto 0:0e0631af0305 418 matrix and the position of a camera.
RyoheiHagimoto 0:0e0631af0305 419
RyoheiHagimoto 0:0e0631af0305 420 It optionally returns three rotation matrices, one for each axis, and three Euler angles that could
RyoheiHagimoto 0:0e0631af0305 421 be used in OpenGL. Note, there is always more than one sequence of rotations about the three
RyoheiHagimoto 0:0e0631af0305 422 principal axes that results in the same orientation of an object, eg. see @cite Slabaugh . Returned
RyoheiHagimoto 0:0e0631af0305 423 tree rotation matrices and corresponding three Euler angules are only one of the possible solutions.
RyoheiHagimoto 0:0e0631af0305 424
RyoheiHagimoto 0:0e0631af0305 425 The function is based on RQDecomp3x3 .
RyoheiHagimoto 0:0e0631af0305 426 */
RyoheiHagimoto 0:0e0631af0305 427 CV_EXPORTS_W void decomposeProjectionMatrix( InputArray projMatrix, OutputArray cameraMatrix,
RyoheiHagimoto 0:0e0631af0305 428 OutputArray rotMatrix, OutputArray transVect,
RyoheiHagimoto 0:0e0631af0305 429 OutputArray rotMatrixX = noArray(),
RyoheiHagimoto 0:0e0631af0305 430 OutputArray rotMatrixY = noArray(),
RyoheiHagimoto 0:0e0631af0305 431 OutputArray rotMatrixZ = noArray(),
RyoheiHagimoto 0:0e0631af0305 432 OutputArray eulerAngles =noArray() );
RyoheiHagimoto 0:0e0631af0305 433
RyoheiHagimoto 0:0e0631af0305 434 /** @brief Computes partial derivatives of the matrix product for each multiplied matrix.
RyoheiHagimoto 0:0e0631af0305 435
RyoheiHagimoto 0:0e0631af0305 436 @param A First multiplied matrix.
RyoheiHagimoto 0:0e0631af0305 437 @param B Second multiplied matrix.
RyoheiHagimoto 0:0e0631af0305 438 @param dABdA First output derivative matrix d(A\*B)/dA of size
RyoheiHagimoto 0:0e0631af0305 439 \f$\texttt{A.rows*B.cols} \times {A.rows*A.cols}\f$ .
RyoheiHagimoto 0:0e0631af0305 440 @param dABdB Second output derivative matrix d(A\*B)/dB of size
RyoheiHagimoto 0:0e0631af0305 441 \f$\texttt{A.rows*B.cols} \times {B.rows*B.cols}\f$ .
RyoheiHagimoto 0:0e0631af0305 442
RyoheiHagimoto 0:0e0631af0305 443 The function computes partial derivatives of the elements of the matrix product \f$A*B\f$ with regard to
RyoheiHagimoto 0:0e0631af0305 444 the elements of each of the two input matrices. The function is used to compute the Jacobian
RyoheiHagimoto 0:0e0631af0305 445 matrices in stereoCalibrate but can also be used in any other similar optimization function.
RyoheiHagimoto 0:0e0631af0305 446 */
RyoheiHagimoto 0:0e0631af0305 447 CV_EXPORTS_W void matMulDeriv( InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB );
RyoheiHagimoto 0:0e0631af0305 448
RyoheiHagimoto 0:0e0631af0305 449 /** @brief Combines two rotation-and-shift transformations.
RyoheiHagimoto 0:0e0631af0305 450
RyoheiHagimoto 0:0e0631af0305 451 @param rvec1 First rotation vector.
RyoheiHagimoto 0:0e0631af0305 452 @param tvec1 First translation vector.
RyoheiHagimoto 0:0e0631af0305 453 @param rvec2 Second rotation vector.
RyoheiHagimoto 0:0e0631af0305 454 @param tvec2 Second translation vector.
RyoheiHagimoto 0:0e0631af0305 455 @param rvec3 Output rotation vector of the superposition.
RyoheiHagimoto 0:0e0631af0305 456 @param tvec3 Output translation vector of the superposition.
RyoheiHagimoto 0:0e0631af0305 457 @param dr3dr1
RyoheiHagimoto 0:0e0631af0305 458 @param dr3dt1
RyoheiHagimoto 0:0e0631af0305 459 @param dr3dr2
RyoheiHagimoto 0:0e0631af0305 460 @param dr3dt2
RyoheiHagimoto 0:0e0631af0305 461 @param dt3dr1
RyoheiHagimoto 0:0e0631af0305 462 @param dt3dt1
RyoheiHagimoto 0:0e0631af0305 463 @param dt3dr2
RyoheiHagimoto 0:0e0631af0305 464 @param dt3dt2 Optional output derivatives of rvec3 or tvec3 with regard to rvec1, rvec2, tvec1 and
RyoheiHagimoto 0:0e0631af0305 465 tvec2, respectively.
RyoheiHagimoto 0:0e0631af0305 466
RyoheiHagimoto 0:0e0631af0305 467 The functions compute:
RyoheiHagimoto 0:0e0631af0305 468
RyoheiHagimoto 0:0e0631af0305 469 \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]
RyoheiHagimoto 0:0e0631af0305 470
RyoheiHagimoto 0:0e0631af0305 471 where \f$\mathrm{rodrigues}\f$ denotes a rotation vector to a rotation matrix transformation, and
RyoheiHagimoto 0:0e0631af0305 472 \f$\mathrm{rodrigues}^{-1}\f$ denotes the inverse transformation. See Rodrigues for details.
RyoheiHagimoto 0:0e0631af0305 473
RyoheiHagimoto 0:0e0631af0305 474 Also, the functions can compute the derivatives of the output vectors with regards to the input
RyoheiHagimoto 0:0e0631af0305 475 vectors (see matMulDeriv ). The functions are used inside stereoCalibrate but can also be used in
RyoheiHagimoto 0:0e0631af0305 476 your own code where Levenberg-Marquardt or another gradient-based solver is used to optimize a
RyoheiHagimoto 0:0e0631af0305 477 function that contains a matrix multiplication.
RyoheiHagimoto 0:0e0631af0305 478 */
RyoheiHagimoto 0:0e0631af0305 479 CV_EXPORTS_W void composeRT( InputArray rvec1, InputArray tvec1,
RyoheiHagimoto 0:0e0631af0305 480 InputArray rvec2, InputArray tvec2,
RyoheiHagimoto 0:0e0631af0305 481 OutputArray rvec3, OutputArray tvec3,
RyoheiHagimoto 0:0e0631af0305 482 OutputArray dr3dr1 = noArray(), OutputArray dr3dt1 = noArray(),
RyoheiHagimoto 0:0e0631af0305 483 OutputArray dr3dr2 = noArray(), OutputArray dr3dt2 = noArray(),
RyoheiHagimoto 0:0e0631af0305 484 OutputArray dt3dr1 = noArray(), OutputArray dt3dt1 = noArray(),
RyoheiHagimoto 0:0e0631af0305 485 OutputArray dt3dr2 = noArray(), OutputArray dt3dt2 = noArray() );
RyoheiHagimoto 0:0e0631af0305 486
RyoheiHagimoto 0:0e0631af0305 487 /** @brief Projects 3D points to an image plane.
RyoheiHagimoto 0:0e0631af0305 488
RyoheiHagimoto 0:0e0631af0305 489 @param objectPoints Array of object points, 3xN/Nx3 1-channel or 1xN/Nx1 3-channel (or
RyoheiHagimoto 0:0e0631af0305 490 vector\<Point3f\> ), where N is the number of points in the view.
RyoheiHagimoto 0:0e0631af0305 491 @param rvec Rotation vector. See Rodrigues for details.
RyoheiHagimoto 0:0e0631af0305 492 @param tvec Translation vector.
RyoheiHagimoto 0:0e0631af0305 493 @param cameraMatrix Camera matrix \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$ .
RyoheiHagimoto 0:0e0631af0305 494 @param distCoeffs Input vector of distortion coefficients
RyoheiHagimoto 0:0e0631af0305 495 \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
RyoheiHagimoto 0:0e0631af0305 496 4, 5, 8, 12 or 14 elements. If the vector is empty, the zero distortion coefficients are assumed.
RyoheiHagimoto 0:0e0631af0305 497 @param imagePoints Output array of image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, or
RyoheiHagimoto 0:0e0631af0305 498 vector\<Point2f\> .
RyoheiHagimoto 0:0e0631af0305 499 @param jacobian Optional output 2Nx(10+\<numDistCoeffs\>) jacobian matrix of derivatives of image
RyoheiHagimoto 0:0e0631af0305 500 points with respect to components of the rotation vector, translation vector, focal lengths,
RyoheiHagimoto 0:0e0631af0305 501 coordinates of the principal point and the distortion coefficients. In the old interface different
RyoheiHagimoto 0:0e0631af0305 502 components of the jacobian are returned via different output parameters.
RyoheiHagimoto 0:0e0631af0305 503 @param aspectRatio Optional "fixed aspect ratio" parameter. If the parameter is not 0, the
RyoheiHagimoto 0:0e0631af0305 504 function assumes that the aspect ratio (*fx/fy*) is fixed and correspondingly adjusts the jacobian
RyoheiHagimoto 0:0e0631af0305 505 matrix.
RyoheiHagimoto 0:0e0631af0305 506
RyoheiHagimoto 0:0e0631af0305 507 The function computes projections of 3D points to the image plane given intrinsic and extrinsic
RyoheiHagimoto 0:0e0631af0305 508 camera parameters. Optionally, the function computes Jacobians - matrices of partial derivatives of
RyoheiHagimoto 0:0e0631af0305 509 image points coordinates (as functions of all the input parameters) with respect to the particular
RyoheiHagimoto 0:0e0631af0305 510 parameters, intrinsic and/or extrinsic. The Jacobians are used during the global optimization in
RyoheiHagimoto 0:0e0631af0305 511 calibrateCamera, solvePnP, and stereoCalibrate . The function itself can also be used to compute a
RyoheiHagimoto 0:0e0631af0305 512 re-projection error given the current intrinsic and extrinsic parameters.
RyoheiHagimoto 0:0e0631af0305 513
RyoheiHagimoto 0:0e0631af0305 514 @note By setting rvec=tvec=(0,0,0) or by setting cameraMatrix to a 3x3 identity matrix, or by
RyoheiHagimoto 0:0e0631af0305 515 passing zero distortion coefficients, you can get various useful partial cases of the function. This
RyoheiHagimoto 0:0e0631af0305 516 means that you can compute the distorted coordinates for a sparse set of points or apply a
RyoheiHagimoto 0:0e0631af0305 517 perspective transformation (and also compute the derivatives) in the ideal zero-distortion setup.
RyoheiHagimoto 0:0e0631af0305 518 */
RyoheiHagimoto 0:0e0631af0305 519 CV_EXPORTS_W void projectPoints( InputArray objectPoints,
RyoheiHagimoto 0:0e0631af0305 520 InputArray rvec, InputArray tvec,
RyoheiHagimoto 0:0e0631af0305 521 InputArray cameraMatrix, InputArray distCoeffs,
RyoheiHagimoto 0:0e0631af0305 522 OutputArray imagePoints,
RyoheiHagimoto 0:0e0631af0305 523 OutputArray jacobian = noArray(),
RyoheiHagimoto 0:0e0631af0305 524 double aspectRatio = 0 );
RyoheiHagimoto 0:0e0631af0305 525
RyoheiHagimoto 0:0e0631af0305 526 /** @brief Finds an object pose from 3D-2D point correspondences.
RyoheiHagimoto 0:0e0631af0305 527
RyoheiHagimoto 0:0e0631af0305 528 @param objectPoints Array of object points in the object coordinate space, Nx3 1-channel or
RyoheiHagimoto 0:0e0631af0305 529 1xN/Nx1 3-channel, where N is the number of points. vector\<Point3f\> can be also passed here.
RyoheiHagimoto 0:0e0631af0305 530 @param imagePoints Array of corresponding image points, Nx2 1-channel or 1xN/Nx1 2-channel,
RyoheiHagimoto 0:0e0631af0305 531 where N is the number of points. vector\<Point2f\> can be also passed here.
RyoheiHagimoto 0:0e0631af0305 532 @param cameraMatrix Input camera matrix \f$A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1}\f$ .
RyoheiHagimoto 0:0e0631af0305 533 @param distCoeffs Input vector of distortion coefficients
RyoheiHagimoto 0:0e0631af0305 534 \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
RyoheiHagimoto 0:0e0631af0305 535 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are
RyoheiHagimoto 0:0e0631af0305 536 assumed.
RyoheiHagimoto 0:0e0631af0305 537 @param rvec Output rotation vector (see Rodrigues ) that, together with tvec , brings points from
RyoheiHagimoto 0:0e0631af0305 538 the model coordinate system to the camera coordinate system.
RyoheiHagimoto 0:0e0631af0305 539 @param tvec Output translation vector.
RyoheiHagimoto 0:0e0631af0305 540 @param useExtrinsicGuess Parameter used for SOLVEPNP_ITERATIVE. If true (1), the function uses
RyoheiHagimoto 0:0e0631af0305 541 the provided rvec and tvec values as initial approximations of the rotation and translation
RyoheiHagimoto 0:0e0631af0305 542 vectors, respectively, and further optimizes them.
RyoheiHagimoto 0:0e0631af0305 543 @param flags Method for solving a PnP problem:
RyoheiHagimoto 0:0e0631af0305 544 - **SOLVEPNP_ITERATIVE** Iterative method is based on Levenberg-Marquardt optimization. In
RyoheiHagimoto 0:0e0631af0305 545 this case the function finds such a pose that minimizes reprojection error, that is the sum
RyoheiHagimoto 0:0e0631af0305 546 of squared distances between the observed projections imagePoints and the projected (using
RyoheiHagimoto 0:0e0631af0305 547 projectPoints ) objectPoints .
RyoheiHagimoto 0:0e0631af0305 548 - **SOLVEPNP_P3P** Method is based on the paper of X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang
RyoheiHagimoto 0:0e0631af0305 549 "Complete Solution Classification for the Perspective-Three-Point Problem". In this case the
RyoheiHagimoto 0:0e0631af0305 550 function requires exactly four object and image points.
RyoheiHagimoto 0:0e0631af0305 551 - **SOLVEPNP_EPNP** Method has been introduced by F.Moreno-Noguer, V.Lepetit and P.Fua in the
RyoheiHagimoto 0:0e0631af0305 552 paper "EPnP: Efficient Perspective-n-Point Camera Pose Estimation".
RyoheiHagimoto 0:0e0631af0305 553 - **SOLVEPNP_DLS** Method is based on the paper of Joel A. Hesch and Stergios I. Roumeliotis.
RyoheiHagimoto 0:0e0631af0305 554 "A Direct Least-Squares (DLS) Method for PnP".
RyoheiHagimoto 0:0e0631af0305 555 - **SOLVEPNP_UPNP** Method is based on the paper of A.Penate-Sanchez, J.Andrade-Cetto,
RyoheiHagimoto 0:0e0631af0305 556 F.Moreno-Noguer. "Exhaustive Linearization for Robust Camera Pose and Focal Length
RyoheiHagimoto 0:0e0631af0305 557 Estimation". In this case the function also estimates the parameters \f$f_x\f$ and \f$f_y\f$
RyoheiHagimoto 0:0e0631af0305 558 assuming that both have the same value. Then the cameraMatrix is updated with the estimated
RyoheiHagimoto 0:0e0631af0305 559 focal length.
RyoheiHagimoto 0:0e0631af0305 560
RyoheiHagimoto 0:0e0631af0305 561 The function estimates the object pose given a set of object points, their corresponding image
RyoheiHagimoto 0:0e0631af0305 562 projections, as well as the camera matrix and the distortion coefficients.
RyoheiHagimoto 0:0e0631af0305 563
RyoheiHagimoto 0:0e0631af0305 564 @note
RyoheiHagimoto 0:0e0631af0305 565 - An example of how to use solvePnP for planar augmented reality can be found at
RyoheiHagimoto 0:0e0631af0305 566 opencv_source_code/samples/python/plane_ar.py
RyoheiHagimoto 0:0e0631af0305 567 - If you are using Python:
RyoheiHagimoto 0:0e0631af0305 568 - Numpy array slices won't work as input because solvePnP requires contiguous
RyoheiHagimoto 0:0e0631af0305 569 arrays (enforced by the assertion using cv::Mat::checkVector() around line 55 of
RyoheiHagimoto 0:0e0631af0305 570 modules/calib3d/src/solvepnp.cpp version 2.4.9)
RyoheiHagimoto 0:0e0631af0305 571 - The P3P algorithm requires image points to be in an array of shape (N,1,2) due
RyoheiHagimoto 0:0e0631af0305 572 to its calling of cv::undistortPoints (around line 75 of modules/calib3d/src/solvepnp.cpp version 2.4.9)
RyoheiHagimoto 0:0e0631af0305 573 which requires 2-channel information.
RyoheiHagimoto 0:0e0631af0305 574 - Thus, given some data D = np.array(...) where D.shape = (N,M), in order to use a subset of
RyoheiHagimoto 0:0e0631af0305 575 it as, e.g., imagePoints, one must effectively copy it into a new array: imagePoints =
RyoheiHagimoto 0:0e0631af0305 576 np.ascontiguousarray(D[:,:2]).reshape((N,1,2))
RyoheiHagimoto 0:0e0631af0305 577 - The methods **SOLVEPNP_DLS** and **SOLVEPNP_UPNP** cannot be used as the current implementations are
RyoheiHagimoto 0:0e0631af0305 578 unstable and sometimes give completly wrong results. If you pass one of these two flags,
RyoheiHagimoto 0:0e0631af0305 579 **SOLVEPNP_EPNP** method will be used instead.
RyoheiHagimoto 0:0e0631af0305 580 */
RyoheiHagimoto 0:0e0631af0305 581 CV_EXPORTS_W bool solvePnP( InputArray objectPoints, InputArray imagePoints,
RyoheiHagimoto 0:0e0631af0305 582 InputArray cameraMatrix, InputArray distCoeffs,
RyoheiHagimoto 0:0e0631af0305 583 OutputArray rvec, OutputArray tvec,
RyoheiHagimoto 0:0e0631af0305 584 bool useExtrinsicGuess = false, int flags = SOLVEPNP_ITERATIVE );
RyoheiHagimoto 0:0e0631af0305 585
RyoheiHagimoto 0:0e0631af0305 586 /** @brief Finds an object pose from 3D-2D point correspondences using the RANSAC scheme.
RyoheiHagimoto 0:0e0631af0305 587
RyoheiHagimoto 0:0e0631af0305 588 @param objectPoints Array of object points in the object coordinate space, Nx3 1-channel or
RyoheiHagimoto 0:0e0631af0305 589 1xN/Nx1 3-channel, where N is the number of points. vector\<Point3f\> can be also passed here.
RyoheiHagimoto 0:0e0631af0305 590 @param imagePoints Array of corresponding image points, Nx2 1-channel or 1xN/Nx1 2-channel,
RyoheiHagimoto 0:0e0631af0305 591 where N is the number of points. vector\<Point2f\> can be also passed here.
RyoheiHagimoto 0:0e0631af0305 592 @param cameraMatrix Input camera matrix \f$A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1}\f$ .
RyoheiHagimoto 0:0e0631af0305 593 @param distCoeffs Input vector of distortion coefficients
RyoheiHagimoto 0:0e0631af0305 594 \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
RyoheiHagimoto 0:0e0631af0305 595 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are
RyoheiHagimoto 0:0e0631af0305 596 assumed.
RyoheiHagimoto 0:0e0631af0305 597 @param rvec Output rotation vector (see Rodrigues ) that, together with tvec , brings points from
RyoheiHagimoto 0:0e0631af0305 598 the model coordinate system to the camera coordinate system.
RyoheiHagimoto 0:0e0631af0305 599 @param tvec Output translation vector.
RyoheiHagimoto 0:0e0631af0305 600 @param useExtrinsicGuess Parameter used for SOLVEPNP_ITERATIVE. If true (1), the function uses
RyoheiHagimoto 0:0e0631af0305 601 the provided rvec and tvec values as initial approximations of the rotation and translation
RyoheiHagimoto 0:0e0631af0305 602 vectors, respectively, and further optimizes them.
RyoheiHagimoto 0:0e0631af0305 603 @param iterationsCount Number of iterations.
RyoheiHagimoto 0:0e0631af0305 604 @param reprojectionError Inlier threshold value used by the RANSAC procedure. The parameter value
RyoheiHagimoto 0:0e0631af0305 605 is the maximum allowed distance between the observed and computed point projections to consider it
RyoheiHagimoto 0:0e0631af0305 606 an inlier.
RyoheiHagimoto 0:0e0631af0305 607 @param confidence The probability that the algorithm produces a useful result.
RyoheiHagimoto 0:0e0631af0305 608 @param inliers Output vector that contains indices of inliers in objectPoints and imagePoints .
RyoheiHagimoto 0:0e0631af0305 609 @param flags Method for solving a PnP problem (see solvePnP ).
RyoheiHagimoto 0:0e0631af0305 610
RyoheiHagimoto 0:0e0631af0305 611 The function estimates an object pose given a set of object points, their corresponding image
RyoheiHagimoto 0:0e0631af0305 612 projections, as well as the camera matrix and the distortion coefficients. This function finds such
RyoheiHagimoto 0:0e0631af0305 613 a pose that minimizes reprojection error, that is, the sum of squared distances between the observed
RyoheiHagimoto 0:0e0631af0305 614 projections imagePoints and the projected (using projectPoints ) objectPoints. The use of RANSAC
RyoheiHagimoto 0:0e0631af0305 615 makes the function resistant to outliers.
RyoheiHagimoto 0:0e0631af0305 616
RyoheiHagimoto 0:0e0631af0305 617 @note
RyoheiHagimoto 0:0e0631af0305 618 - An example of how to use solvePNPRansac for object detection can be found at
RyoheiHagimoto 0:0e0631af0305 619 opencv_source_code/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/
RyoheiHagimoto 0:0e0631af0305 620 */
RyoheiHagimoto 0:0e0631af0305 621 CV_EXPORTS_W bool solvePnPRansac( InputArray objectPoints, InputArray imagePoints,
RyoheiHagimoto 0:0e0631af0305 622 InputArray cameraMatrix, InputArray distCoeffs,
RyoheiHagimoto 0:0e0631af0305 623 OutputArray rvec, OutputArray tvec,
RyoheiHagimoto 0:0e0631af0305 624 bool useExtrinsicGuess = false, int iterationsCount = 100,
RyoheiHagimoto 0:0e0631af0305 625 float reprojectionError = 8.0, double confidence = 0.99,
RyoheiHagimoto 0:0e0631af0305 626 OutputArray inliers = noArray(), int flags = SOLVEPNP_ITERATIVE );
RyoheiHagimoto 0:0e0631af0305 627
RyoheiHagimoto 0:0e0631af0305 628 /** @brief Finds an initial camera matrix from 3D-2D point correspondences.
RyoheiHagimoto 0:0e0631af0305 629
RyoheiHagimoto 0:0e0631af0305 630 @param objectPoints Vector of vectors of the calibration pattern points in the calibration pattern
RyoheiHagimoto 0:0e0631af0305 631 coordinate space. In the old interface all the per-view vectors are concatenated. See
RyoheiHagimoto 0:0e0631af0305 632 calibrateCamera for details.
RyoheiHagimoto 0:0e0631af0305 633 @param imagePoints Vector of vectors of the projections of the calibration pattern points. In the
RyoheiHagimoto 0:0e0631af0305 634 old interface all the per-view vectors are concatenated.
RyoheiHagimoto 0:0e0631af0305 635 @param imageSize Image size in pixels used to initialize the principal point.
RyoheiHagimoto 0:0e0631af0305 636 @param aspectRatio If it is zero or negative, both \f$f_x\f$ and \f$f_y\f$ are estimated independently.
RyoheiHagimoto 0:0e0631af0305 637 Otherwise, \f$f_x = f_y * \texttt{aspectRatio}\f$ .
RyoheiHagimoto 0:0e0631af0305 638
RyoheiHagimoto 0:0e0631af0305 639 The function estimates and returns an initial camera matrix for the camera calibration process.
RyoheiHagimoto 0:0e0631af0305 640 Currently, the function only supports planar calibration patterns, which are patterns where each
RyoheiHagimoto 0:0e0631af0305 641 object point has z-coordinate =0.
RyoheiHagimoto 0:0e0631af0305 642 */
RyoheiHagimoto 0:0e0631af0305 643 CV_EXPORTS_W Mat initCameraMatrix2D( InputArrayOfArrays objectPoints,
RyoheiHagimoto 0:0e0631af0305 644 InputArrayOfArrays imagePoints,
RyoheiHagimoto 0:0e0631af0305 645 Size imageSize, double aspectRatio = 1.0 );
RyoheiHagimoto 0:0e0631af0305 646
RyoheiHagimoto 0:0e0631af0305 647 /** @brief Finds the positions of internal corners of the chessboard.
RyoheiHagimoto 0:0e0631af0305 648
RyoheiHagimoto 0:0e0631af0305 649 @param image Source chessboard view. It must be an 8-bit grayscale or color image.
RyoheiHagimoto 0:0e0631af0305 650 @param patternSize Number of inner corners per a chessboard row and column
RyoheiHagimoto 0:0e0631af0305 651 ( patternSize = cvSize(points_per_row,points_per_colum) = cvSize(columns,rows) ).
RyoheiHagimoto 0:0e0631af0305 652 @param corners Output array of detected corners.
RyoheiHagimoto 0:0e0631af0305 653 @param flags Various operation flags that can be zero or a combination of the following values:
RyoheiHagimoto 0:0e0631af0305 654 - **CV_CALIB_CB_ADAPTIVE_THRESH** Use adaptive thresholding to convert the image to black
RyoheiHagimoto 0:0e0631af0305 655 and white, rather than a fixed threshold level (computed from the average image brightness).
RyoheiHagimoto 0:0e0631af0305 656 - **CV_CALIB_CB_NORMALIZE_IMAGE** Normalize the image gamma with equalizeHist before
RyoheiHagimoto 0:0e0631af0305 657 applying fixed or adaptive thresholding.
RyoheiHagimoto 0:0e0631af0305 658 - **CV_CALIB_CB_FILTER_QUADS** Use additional criteria (like contour area, perimeter,
RyoheiHagimoto 0:0e0631af0305 659 square-like shape) to filter out false quads extracted at the contour retrieval stage.
RyoheiHagimoto 0:0e0631af0305 660 - **CALIB_CB_FAST_CHECK** Run a fast check on the image that looks for chessboard corners,
RyoheiHagimoto 0:0e0631af0305 661 and shortcut the call if none is found. This can drastically speed up the call in the
RyoheiHagimoto 0:0e0631af0305 662 degenerate condition when no chessboard is observed.
RyoheiHagimoto 0:0e0631af0305 663
RyoheiHagimoto 0:0e0631af0305 664 The function attempts to determine whether the input image is a view of the chessboard pattern and
RyoheiHagimoto 0:0e0631af0305 665 locate the internal chessboard corners. The function returns a non-zero value if all of the corners
RyoheiHagimoto 0:0e0631af0305 666 are found and they are placed in a certain order (row by row, left to right in every row).
RyoheiHagimoto 0:0e0631af0305 667 Otherwise, if the function fails to find all the corners or reorder them, it returns 0. For example,
RyoheiHagimoto 0:0e0631af0305 668 a regular chessboard has 8 x 8 squares and 7 x 7 internal corners, that is, points where the black
RyoheiHagimoto 0:0e0631af0305 669 squares touch each other. The detected coordinates are approximate, and to determine their positions
RyoheiHagimoto 0:0e0631af0305 670 more accurately, the function calls cornerSubPix. You also may use the function cornerSubPix with
RyoheiHagimoto 0:0e0631af0305 671 different parameters if returned coordinates are not accurate enough.
RyoheiHagimoto 0:0e0631af0305 672
RyoheiHagimoto 0:0e0631af0305 673 Sample usage of detecting and drawing chessboard corners: :
RyoheiHagimoto 0:0e0631af0305 674 @code
RyoheiHagimoto 0:0e0631af0305 675 Size patternsize(8,6); //interior number of corners
RyoheiHagimoto 0:0e0631af0305 676 Mat gray = ....; //source image
RyoheiHagimoto 0:0e0631af0305 677 vector<Point2f> corners; //this will be filled by the detected corners
RyoheiHagimoto 0:0e0631af0305 678
RyoheiHagimoto 0:0e0631af0305 679 //CALIB_CB_FAST_CHECK saves a lot of time on images
RyoheiHagimoto 0:0e0631af0305 680 //that do not contain any chessboard corners
RyoheiHagimoto 0:0e0631af0305 681 bool patternfound = findChessboardCorners(gray, patternsize, corners,
RyoheiHagimoto 0:0e0631af0305 682 CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE
RyoheiHagimoto 0:0e0631af0305 683 + CALIB_CB_FAST_CHECK);
RyoheiHagimoto 0:0e0631af0305 684
RyoheiHagimoto 0:0e0631af0305 685 if(patternfound)
RyoheiHagimoto 0:0e0631af0305 686 cornerSubPix(gray, corners, Size(11, 11), Size(-1, -1),
RyoheiHagimoto 0:0e0631af0305 687 TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1));
RyoheiHagimoto 0:0e0631af0305 688
RyoheiHagimoto 0:0e0631af0305 689 drawChessboardCorners(img, patternsize, Mat(corners), patternfound);
RyoheiHagimoto 0:0e0631af0305 690 @endcode
RyoheiHagimoto 0:0e0631af0305 691 @note The function requires white space (like a square-thick border, the wider the better) around
RyoheiHagimoto 0:0e0631af0305 692 the board to make the detection more robust in various environments. Otherwise, if there is no
RyoheiHagimoto 0:0e0631af0305 693 border and the background is dark, the outer black squares cannot be segmented properly and so the
RyoheiHagimoto 0:0e0631af0305 694 square grouping and ordering algorithm fails.
RyoheiHagimoto 0:0e0631af0305 695 */
RyoheiHagimoto 0:0e0631af0305 696 CV_EXPORTS_W bool findChessboardCorners( InputArray image, Size patternSize, OutputArray corners,
RyoheiHagimoto 0:0e0631af0305 697 int flags = CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE );
RyoheiHagimoto 0:0e0631af0305 698
RyoheiHagimoto 0:0e0631af0305 699 //! finds subpixel-accurate positions of the chessboard corners
RyoheiHagimoto 0:0e0631af0305 700 CV_EXPORTS bool find4QuadCornerSubpix( InputArray img, InputOutputArray corners, Size region_size );
RyoheiHagimoto 0:0e0631af0305 701
RyoheiHagimoto 0:0e0631af0305 702 /** @brief Renders the detected chessboard corners.
RyoheiHagimoto 0:0e0631af0305 703
RyoheiHagimoto 0:0e0631af0305 704 @param image Destination image. It must be an 8-bit color image.
RyoheiHagimoto 0:0e0631af0305 705 @param patternSize Number of inner corners per a chessboard row and column
RyoheiHagimoto 0:0e0631af0305 706 (patternSize = cv::Size(points_per_row,points_per_column)).
RyoheiHagimoto 0:0e0631af0305 707 @param corners Array of detected corners, the output of findChessboardCorners.
RyoheiHagimoto 0:0e0631af0305 708 @param patternWasFound Parameter indicating whether the complete board was found or not. The
RyoheiHagimoto 0:0e0631af0305 709 return value of findChessboardCorners should be passed here.
RyoheiHagimoto 0:0e0631af0305 710
RyoheiHagimoto 0:0e0631af0305 711 The function draws individual chessboard corners detected either as red circles if the board was not
RyoheiHagimoto 0:0e0631af0305 712 found, or as colored corners connected with lines if the board was found.
RyoheiHagimoto 0:0e0631af0305 713 */
RyoheiHagimoto 0:0e0631af0305 714 CV_EXPORTS_W void drawChessboardCorners( InputOutputArray image, Size patternSize,
RyoheiHagimoto 0:0e0631af0305 715 InputArray corners, bool patternWasFound );
RyoheiHagimoto 0:0e0631af0305 716
RyoheiHagimoto 0:0e0631af0305 717 /** @brief Finds centers in the grid of circles.
RyoheiHagimoto 0:0e0631af0305 718
RyoheiHagimoto 0:0e0631af0305 719 @param image grid view of input circles; it must be an 8-bit grayscale or color image.
RyoheiHagimoto 0:0e0631af0305 720 @param patternSize number of circles per row and column
RyoheiHagimoto 0:0e0631af0305 721 ( patternSize = Size(points_per_row, points_per_colum) ).
RyoheiHagimoto 0:0e0631af0305 722 @param centers output array of detected centers.
RyoheiHagimoto 0:0e0631af0305 723 @param flags various operation flags that can be one of the following values:
RyoheiHagimoto 0:0e0631af0305 724 - **CALIB_CB_SYMMETRIC_GRID** uses symmetric pattern of circles.
RyoheiHagimoto 0:0e0631af0305 725 - **CALIB_CB_ASYMMETRIC_GRID** uses asymmetric pattern of circles.
RyoheiHagimoto 0:0e0631af0305 726 - **CALIB_CB_CLUSTERING** uses a special algorithm for grid detection. It is more robust to
RyoheiHagimoto 0:0e0631af0305 727 perspective distortions but much more sensitive to background clutter.
RyoheiHagimoto 0:0e0631af0305 728 @param blobDetector feature detector that finds blobs like dark circles on light background.
RyoheiHagimoto 0:0e0631af0305 729
RyoheiHagimoto 0:0e0631af0305 730 The function attempts to determine whether the input image contains a grid of circles. If it is, the
RyoheiHagimoto 0:0e0631af0305 731 function locates centers of the circles. The function returns a non-zero value if all of the centers
RyoheiHagimoto 0:0e0631af0305 732 have been found and they have been placed in a certain order (row by row, left to right in every
RyoheiHagimoto 0:0e0631af0305 733 row). Otherwise, if the function fails to find all the corners or reorder them, it returns 0.
RyoheiHagimoto 0:0e0631af0305 734
RyoheiHagimoto 0:0e0631af0305 735 Sample usage of detecting and drawing the centers of circles: :
RyoheiHagimoto 0:0e0631af0305 736 @code
RyoheiHagimoto 0:0e0631af0305 737 Size patternsize(7,7); //number of centers
RyoheiHagimoto 0:0e0631af0305 738 Mat gray = ....; //source image
RyoheiHagimoto 0:0e0631af0305 739 vector<Point2f> centers; //this will be filled by the detected centers
RyoheiHagimoto 0:0e0631af0305 740
RyoheiHagimoto 0:0e0631af0305 741 bool patternfound = findCirclesGrid(gray, patternsize, centers);
RyoheiHagimoto 0:0e0631af0305 742
RyoheiHagimoto 0:0e0631af0305 743 drawChessboardCorners(img, patternsize, Mat(centers), patternfound);
RyoheiHagimoto 0:0e0631af0305 744 @endcode
RyoheiHagimoto 0:0e0631af0305 745 @note The function requires white space (like a square-thick border, the wider the better) around
RyoheiHagimoto 0:0e0631af0305 746 the board to make the detection more robust in various environments.
RyoheiHagimoto 0:0e0631af0305 747 */
RyoheiHagimoto 0:0e0631af0305 748 CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize,
RyoheiHagimoto 0:0e0631af0305 749 OutputArray centers, int flags = CALIB_CB_SYMMETRIC_GRID,
RyoheiHagimoto 0:0e0631af0305 750 const Ptr<FeatureDetector> &blobDetector = SimpleBlobDetector::create());
RyoheiHagimoto 0:0e0631af0305 751
RyoheiHagimoto 0:0e0631af0305 752 /** @brief Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern.
RyoheiHagimoto 0:0e0631af0305 753
RyoheiHagimoto 0:0e0631af0305 754 @param objectPoints In the new interface it is a vector of vectors of calibration pattern points in
RyoheiHagimoto 0:0e0631af0305 755 the calibration pattern coordinate space (e.g. std::vector<std::vector<cv::Vec3f>>). The outer
RyoheiHagimoto 0:0e0631af0305 756 vector contains as many elements as the number of the pattern views. If the same calibration pattern
RyoheiHagimoto 0:0e0631af0305 757 is shown in each view and it is fully visible, all the vectors will be the same. Although, it is
RyoheiHagimoto 0:0e0631af0305 758 possible to use partially occluded patterns, or even different patterns in different views. Then,
RyoheiHagimoto 0:0e0631af0305 759 the vectors will be different. The points are 3D, but since they are in a pattern coordinate system,
RyoheiHagimoto 0:0e0631af0305 760 then, if the rig is planar, it may make sense to put the model to a XY coordinate plane so that
RyoheiHagimoto 0:0e0631af0305 761 Z-coordinate of each input object point is 0.
RyoheiHagimoto 0:0e0631af0305 762 In the old interface all the vectors of object points from different views are concatenated
RyoheiHagimoto 0:0e0631af0305 763 together.
RyoheiHagimoto 0:0e0631af0305 764 @param imagePoints In the new interface it is a vector of vectors of the projections of calibration
RyoheiHagimoto 0:0e0631af0305 765 pattern points (e.g. std::vector<std::vector<cv::Vec2f>>). imagePoints.size() and
RyoheiHagimoto 0:0e0631af0305 766 objectPoints.size() and imagePoints[i].size() must be equal to objectPoints[i].size() for each i.
RyoheiHagimoto 0:0e0631af0305 767 In the old interface all the vectors of object points from different views are concatenated
RyoheiHagimoto 0:0e0631af0305 768 together.
RyoheiHagimoto 0:0e0631af0305 769 @param imageSize Size of the image used only to initialize the intrinsic camera matrix.
RyoheiHagimoto 0:0e0631af0305 770 @param cameraMatrix Output 3x3 floating-point camera matrix
RyoheiHagimoto 0:0e0631af0305 771 \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . If CV\_CALIB\_USE\_INTRINSIC\_GUESS
RyoheiHagimoto 0:0e0631af0305 772 and/or CV_CALIB_FIX_ASPECT_RATIO are specified, some or all of fx, fy, cx, cy must be
RyoheiHagimoto 0:0e0631af0305 773 initialized before calling the function.
RyoheiHagimoto 0:0e0631af0305 774 @param distCoeffs Output vector of distortion coefficients
RyoheiHagimoto 0:0e0631af0305 775 \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
RyoheiHagimoto 0:0e0631af0305 776 4, 5, 8, 12 or 14 elements.
RyoheiHagimoto 0:0e0631af0305 777 @param rvecs Output vector of rotation vectors (see Rodrigues ) estimated for each pattern view
RyoheiHagimoto 0:0e0631af0305 778 (e.g. std::vector<cv::Mat>>). That is, each k-th rotation vector together with the corresponding
RyoheiHagimoto 0:0e0631af0305 779 k-th translation vector (see the next output parameter description) brings the calibration pattern
RyoheiHagimoto 0:0e0631af0305 780 from the model coordinate space (in which object points are specified) to the world coordinate
RyoheiHagimoto 0:0e0631af0305 781 space, that is, a real position of the calibration pattern in the k-th pattern view (k=0.. *M* -1).
RyoheiHagimoto 0:0e0631af0305 782 @param tvecs Output vector of translation vectors estimated for each pattern view.
RyoheiHagimoto 0:0e0631af0305 783 @param stdDeviationsIntrinsics Output vector of standard deviations estimated for intrinsic parameters.
RyoheiHagimoto 0:0e0631af0305 784 Order of deviations values:
RyoheiHagimoto 0:0e0631af0305 785 \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,
RyoheiHagimoto 0:0e0631af0305 786 s_4, \tau_x, \tau_y)\f$ If one of parameters is not estimated, it's deviation is equals to zero.
RyoheiHagimoto 0:0e0631af0305 787 @param stdDeviationsExtrinsics Output vector of standard deviations estimated for extrinsic parameters.
RyoheiHagimoto 0:0e0631af0305 788 Order of deviations values: \f$(R_1, T_1, \dotsc , R_M, T_M)\f$ where M is number of pattern views,
RyoheiHagimoto 0:0e0631af0305 789 \f$R_i, T_i\f$ are concatenated 1x3 vectors.
RyoheiHagimoto 0:0e0631af0305 790 @param perViewErrors Output vector of the RMS re-projection error estimated for each pattern view.
RyoheiHagimoto 0:0e0631af0305 791 @param flags Different flags that may be zero or a combination of the following values:
RyoheiHagimoto 0:0e0631af0305 792 - **CV_CALIB_USE_INTRINSIC_GUESS** cameraMatrix contains valid initial values of
RyoheiHagimoto 0:0e0631af0305 793 fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image
RyoheiHagimoto 0:0e0631af0305 794 center ( imageSize is used), and focal distances are computed in a least-squares fashion.
RyoheiHagimoto 0:0e0631af0305 795 Note, that if intrinsic parameters are known, there is no need to use this function just to
RyoheiHagimoto 0:0e0631af0305 796 estimate extrinsic parameters. Use solvePnP instead.
RyoheiHagimoto 0:0e0631af0305 797 - **CV_CALIB_FIX_PRINCIPAL_POINT** The principal point is not changed during the global
RyoheiHagimoto 0:0e0631af0305 798 optimization. It stays at the center or at a different location specified when
RyoheiHagimoto 0:0e0631af0305 799 CV_CALIB_USE_INTRINSIC_GUESS is set too.
RyoheiHagimoto 0:0e0631af0305 800 - **CV_CALIB_FIX_ASPECT_RATIO** The functions considers only fy as a free parameter. The
RyoheiHagimoto 0:0e0631af0305 801 ratio fx/fy stays the same as in the input cameraMatrix . When
RyoheiHagimoto 0:0e0631af0305 802 CV_CALIB_USE_INTRINSIC_GUESS is not set, the actual input values of fx and fy are
RyoheiHagimoto 0:0e0631af0305 803 ignored, only their ratio is computed and used further.
RyoheiHagimoto 0:0e0631af0305 804 - **CV_CALIB_ZERO_TANGENT_DIST** Tangential distortion coefficients \f$(p_1, p_2)\f$ are set
RyoheiHagimoto 0:0e0631af0305 805 to zeros and stay zero.
RyoheiHagimoto 0:0e0631af0305 806 - **CV_CALIB_FIX_K1,...,CV_CALIB_FIX_K6** The corresponding radial distortion
RyoheiHagimoto 0:0e0631af0305 807 coefficient is not changed during the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is
RyoheiHagimoto 0:0e0631af0305 808 set, the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0.
RyoheiHagimoto 0:0e0631af0305 809 - **CV_CALIB_RATIONAL_MODEL** Coefficients k4, k5, and k6 are enabled. To provide the
RyoheiHagimoto 0:0e0631af0305 810 backward compatibility, this extra flag should be explicitly specified to make the
RyoheiHagimoto 0:0e0631af0305 811 calibration function use the rational model and return 8 coefficients. If the flag is not
RyoheiHagimoto 0:0e0631af0305 812 set, the function computes and returns only 5 distortion coefficients.
RyoheiHagimoto 0:0e0631af0305 813 - **CALIB_THIN_PRISM_MODEL** Coefficients s1, s2, s3 and s4 are enabled. To provide the
RyoheiHagimoto 0:0e0631af0305 814 backward compatibility, this extra flag should be explicitly specified to make the
RyoheiHagimoto 0:0e0631af0305 815 calibration function use the thin prism model and return 12 coefficients. If the flag is not
RyoheiHagimoto 0:0e0631af0305 816 set, the function computes and returns only 5 distortion coefficients.
RyoheiHagimoto 0:0e0631af0305 817 - **CALIB_FIX_S1_S2_S3_S4** The thin prism distortion coefficients are not changed during
RyoheiHagimoto 0:0e0631af0305 818 the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the
RyoheiHagimoto 0:0e0631af0305 819 supplied distCoeffs matrix is used. Otherwise, it is set to 0.
RyoheiHagimoto 0:0e0631af0305 820 - **CALIB_TILTED_MODEL** Coefficients tauX and tauY are enabled. To provide the
RyoheiHagimoto 0:0e0631af0305 821 backward compatibility, this extra flag should be explicitly specified to make the
RyoheiHagimoto 0:0e0631af0305 822 calibration function use the tilted sensor model and return 14 coefficients. If the flag is not
RyoheiHagimoto 0:0e0631af0305 823 set, the function computes and returns only 5 distortion coefficients.
RyoheiHagimoto 0:0e0631af0305 824 - **CALIB_FIX_TAUX_TAUY** The coefficients of the tilted sensor model are not changed during
RyoheiHagimoto 0:0e0631af0305 825 the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the
RyoheiHagimoto 0:0e0631af0305 826 supplied distCoeffs matrix is used. Otherwise, it is set to 0.
RyoheiHagimoto 0:0e0631af0305 827 @param criteria Termination criteria for the iterative optimization algorithm.
RyoheiHagimoto 0:0e0631af0305 828
RyoheiHagimoto 0:0e0631af0305 829 @return the overall RMS re-projection error.
RyoheiHagimoto 0:0e0631af0305 830
RyoheiHagimoto 0:0e0631af0305 831 The function estimates the intrinsic camera parameters and extrinsic parameters for each of the
RyoheiHagimoto 0:0e0631af0305 832 views. The algorithm is based on @cite Zhang2000 and @cite BouguetMCT . The coordinates of 3D object
RyoheiHagimoto 0:0e0631af0305 833 points and their corresponding 2D projections in each view must be specified. That may be achieved
RyoheiHagimoto 0:0e0631af0305 834 by using an object with a known geometry and easily detectable feature points. Such an object is
RyoheiHagimoto 0:0e0631af0305 835 called a calibration rig or calibration pattern, and OpenCV has built-in support for a chessboard as
RyoheiHagimoto 0:0e0631af0305 836 a calibration rig (see findChessboardCorners ). Currently, initialization of intrinsic parameters
RyoheiHagimoto 0:0e0631af0305 837 (when CV_CALIB_USE_INTRINSIC_GUESS is not set) is only implemented for planar calibration
RyoheiHagimoto 0:0e0631af0305 838 patterns (where Z-coordinates of the object points must be all zeros). 3D calibration rigs can also
RyoheiHagimoto 0:0e0631af0305 839 be used as long as initial cameraMatrix is provided.
RyoheiHagimoto 0:0e0631af0305 840
RyoheiHagimoto 0:0e0631af0305 841 The algorithm performs the following steps:
RyoheiHagimoto 0:0e0631af0305 842
RyoheiHagimoto 0:0e0631af0305 843 - Compute the initial intrinsic parameters (the option only available for planar calibration
RyoheiHagimoto 0:0e0631af0305 844 patterns) or read them from the input parameters. The distortion coefficients are all set to
RyoheiHagimoto 0:0e0631af0305 845 zeros initially unless some of CV_CALIB_FIX_K? are specified.
RyoheiHagimoto 0:0e0631af0305 846
RyoheiHagimoto 0:0e0631af0305 847 - Estimate the initial camera pose as if the intrinsic parameters have been already known. This is
RyoheiHagimoto 0:0e0631af0305 848 done using solvePnP .
RyoheiHagimoto 0:0e0631af0305 849
RyoheiHagimoto 0:0e0631af0305 850 - Run the global Levenberg-Marquardt optimization algorithm to minimize the reprojection error,
RyoheiHagimoto 0:0e0631af0305 851 that is, the total sum of squared distances between the observed feature points imagePoints and
RyoheiHagimoto 0:0e0631af0305 852 the projected (using the current estimates for camera parameters and the poses) object points
RyoheiHagimoto 0:0e0631af0305 853 objectPoints. See projectPoints for details.
RyoheiHagimoto 0:0e0631af0305 854
RyoheiHagimoto 0:0e0631af0305 855 @note
RyoheiHagimoto 0:0e0631af0305 856 If you use a non-square (=non-NxN) grid and findChessboardCorners for calibration, and
RyoheiHagimoto 0:0e0631af0305 857 calibrateCamera returns bad values (zero distortion coefficients, an image center very far from
RyoheiHagimoto 0:0e0631af0305 858 (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)),
RyoheiHagimoto 0:0e0631af0305 859 then you have probably used patternSize=cvSize(rows,cols) instead of using
RyoheiHagimoto 0:0e0631af0305 860 patternSize=cvSize(cols,rows) in findChessboardCorners .
RyoheiHagimoto 0:0e0631af0305 861
RyoheiHagimoto 0:0e0631af0305 862 @sa
RyoheiHagimoto 0:0e0631af0305 863 findChessboardCorners, solvePnP, initCameraMatrix2D, stereoCalibrate, undistort
RyoheiHagimoto 0:0e0631af0305 864 */
RyoheiHagimoto 0:0e0631af0305 865 CV_EXPORTS_AS(calibrateCameraExtended) double calibrateCamera( InputArrayOfArrays objectPoints,
RyoheiHagimoto 0:0e0631af0305 866 InputArrayOfArrays imagePoints, Size imageSize,
RyoheiHagimoto 0:0e0631af0305 867 InputOutputArray cameraMatrix, InputOutputArray distCoeffs,
RyoheiHagimoto 0:0e0631af0305 868 OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs,
RyoheiHagimoto 0:0e0631af0305 869 OutputArray stdDeviationsIntrinsics,
RyoheiHagimoto 0:0e0631af0305 870 OutputArray stdDeviationsExtrinsics,
RyoheiHagimoto 0:0e0631af0305 871 OutputArray perViewErrors,
RyoheiHagimoto 0:0e0631af0305 872 int flags = 0, TermCriteria criteria = TermCriteria(
RyoheiHagimoto 0:0e0631af0305 873 TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) );
RyoheiHagimoto 0:0e0631af0305 874
RyoheiHagimoto 0:0e0631af0305 875 /** @overload double calibrateCamera( InputArrayOfArrays objectPoints,
RyoheiHagimoto 0:0e0631af0305 876 InputArrayOfArrays imagePoints, Size imageSize,
RyoheiHagimoto 0:0e0631af0305 877 InputOutputArray cameraMatrix, InputOutputArray distCoeffs,
RyoheiHagimoto 0:0e0631af0305 878 OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs,
RyoheiHagimoto 0:0e0631af0305 879 OutputArray stdDeviations, OutputArray perViewErrors,
RyoheiHagimoto 0:0e0631af0305 880 int flags = 0, TermCriteria criteria = TermCriteria(
RyoheiHagimoto 0:0e0631af0305 881 TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) )
RyoheiHagimoto 0:0e0631af0305 882 */
RyoheiHagimoto 0:0e0631af0305 883 CV_EXPORTS_W double calibrateCamera( InputArrayOfArrays objectPoints,
RyoheiHagimoto 0:0e0631af0305 884 InputArrayOfArrays imagePoints, Size imageSize,
RyoheiHagimoto 0:0e0631af0305 885 InputOutputArray cameraMatrix, InputOutputArray distCoeffs,
RyoheiHagimoto 0:0e0631af0305 886 OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs,
RyoheiHagimoto 0:0e0631af0305 887 int flags = 0, TermCriteria criteria = TermCriteria(
RyoheiHagimoto 0:0e0631af0305 888 TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) );
RyoheiHagimoto 0:0e0631af0305 889
RyoheiHagimoto 0:0e0631af0305 890 /** @brief Computes useful camera characteristics from the camera matrix.
RyoheiHagimoto 0:0e0631af0305 891
RyoheiHagimoto 0:0e0631af0305 892 @param cameraMatrix Input camera matrix that can be estimated by calibrateCamera or
RyoheiHagimoto 0:0e0631af0305 893 stereoCalibrate .
RyoheiHagimoto 0:0e0631af0305 894 @param imageSize Input image size in pixels.
RyoheiHagimoto 0:0e0631af0305 895 @param apertureWidth Physical width in mm of the sensor.
RyoheiHagimoto 0:0e0631af0305 896 @param apertureHeight Physical height in mm of the sensor.
RyoheiHagimoto 0:0e0631af0305 897 @param fovx Output field of view in degrees along the horizontal sensor axis.
RyoheiHagimoto 0:0e0631af0305 898 @param fovy Output field of view in degrees along the vertical sensor axis.
RyoheiHagimoto 0:0e0631af0305 899 @param focalLength Focal length of the lens in mm.
RyoheiHagimoto 0:0e0631af0305 900 @param principalPoint Principal point in mm.
RyoheiHagimoto 0:0e0631af0305 901 @param aspectRatio \f$f_y/f_x\f$
RyoheiHagimoto 0:0e0631af0305 902
RyoheiHagimoto 0:0e0631af0305 903 The function computes various useful camera characteristics from the previously estimated camera
RyoheiHagimoto 0:0e0631af0305 904 matrix.
RyoheiHagimoto 0:0e0631af0305 905
RyoheiHagimoto 0:0e0631af0305 906 @note
RyoheiHagimoto 0:0e0631af0305 907 Do keep in mind that the unity measure 'mm' stands for whatever unit of measure one chooses for
RyoheiHagimoto 0:0e0631af0305 908 the chessboard pitch (it can thus be any value).
RyoheiHagimoto 0:0e0631af0305 909 */
RyoheiHagimoto 0:0e0631af0305 910 CV_EXPORTS_W void calibrationMatrixValues( InputArray cameraMatrix, Size imageSize,
RyoheiHagimoto 0:0e0631af0305 911 double apertureWidth, double apertureHeight,
RyoheiHagimoto 0:0e0631af0305 912 CV_OUT double& fovx, CV_OUT double& fovy,
RyoheiHagimoto 0:0e0631af0305 913 CV_OUT double& focalLength, CV_OUT Point2d& principalPoint,
RyoheiHagimoto 0:0e0631af0305 914 CV_OUT double& aspectRatio );
RyoheiHagimoto 0:0e0631af0305 915
RyoheiHagimoto 0:0e0631af0305 916 /** @brief Calibrates the stereo camera.
RyoheiHagimoto 0:0e0631af0305 917
RyoheiHagimoto 0:0e0631af0305 918 @param objectPoints Vector of vectors of the calibration pattern points.
RyoheiHagimoto 0:0e0631af0305 919 @param imagePoints1 Vector of vectors of the projections of the calibration pattern points,
RyoheiHagimoto 0:0e0631af0305 920 observed by the first camera.
RyoheiHagimoto 0:0e0631af0305 921 @param imagePoints2 Vector of vectors of the projections of the calibration pattern points,
RyoheiHagimoto 0:0e0631af0305 922 observed by the second camera.
RyoheiHagimoto 0:0e0631af0305 923 @param cameraMatrix1 Input/output first camera matrix:
RyoheiHagimoto 0:0e0631af0305 924 \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
RyoheiHagimoto 0:0e0631af0305 925 any of CV_CALIB_USE_INTRINSIC_GUESS , CV_CALIB_FIX_ASPECT_RATIO ,
RyoheiHagimoto 0:0e0631af0305 926 CV_CALIB_FIX_INTRINSIC , or CV_CALIB_FIX_FOCAL_LENGTH are specified, some or all of the
RyoheiHagimoto 0:0e0631af0305 927 matrix components must be initialized. See the flags description for details.
RyoheiHagimoto 0:0e0631af0305 928 @param distCoeffs1 Input/output vector of distortion coefficients
RyoheiHagimoto 0:0e0631af0305 929 \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
RyoheiHagimoto 0:0e0631af0305 930 4, 5, 8, 12 or 14 elements. The output vector length depends on the flags.
RyoheiHagimoto 0:0e0631af0305 931 @param cameraMatrix2 Input/output second camera matrix. The parameter is similar to cameraMatrix1
RyoheiHagimoto 0:0e0631af0305 932 @param distCoeffs2 Input/output lens distortion coefficients for the second camera. The parameter
RyoheiHagimoto 0:0e0631af0305 933 is similar to distCoeffs1 .
RyoheiHagimoto 0:0e0631af0305 934 @param imageSize Size of the image used only to initialize intrinsic camera matrix.
RyoheiHagimoto 0:0e0631af0305 935 @param R Output rotation matrix between the 1st and the 2nd camera coordinate systems.
RyoheiHagimoto 0:0e0631af0305 936 @param T Output translation vector between the coordinate systems of the cameras.
RyoheiHagimoto 0:0e0631af0305 937 @param E Output essential matrix.
RyoheiHagimoto 0:0e0631af0305 938 @param F Output fundamental matrix.
RyoheiHagimoto 0:0e0631af0305 939 @param flags Different flags that may be zero or a combination of the following values:
RyoheiHagimoto 0:0e0631af0305 940 - **CV_CALIB_FIX_INTRINSIC** Fix cameraMatrix? and distCoeffs? so that only R, T, E , and F
RyoheiHagimoto 0:0e0631af0305 941 matrices are estimated.
RyoheiHagimoto 0:0e0631af0305 942 - **CV_CALIB_USE_INTRINSIC_GUESS** Optimize some or all of the intrinsic parameters
RyoheiHagimoto 0:0e0631af0305 943 according to the specified flags. Initial values are provided by the user.
RyoheiHagimoto 0:0e0631af0305 944 - **CV_CALIB_FIX_PRINCIPAL_POINT** Fix the principal points during the optimization.
RyoheiHagimoto 0:0e0631af0305 945 - **CV_CALIB_FIX_FOCAL_LENGTH** Fix \f$f^{(j)}_x\f$ and \f$f^{(j)}_y\f$ .
RyoheiHagimoto 0:0e0631af0305 946 - **CV_CALIB_FIX_ASPECT_RATIO** Optimize \f$f^{(j)}_y\f$ . Fix the ratio \f$f^{(j)}_x/f^{(j)}_y\f$
RyoheiHagimoto 0:0e0631af0305 947 .
RyoheiHagimoto 0:0e0631af0305 948 - **CV_CALIB_SAME_FOCAL_LENGTH** Enforce \f$f^{(0)}_x=f^{(1)}_x\f$ and \f$f^{(0)}_y=f^{(1)}_y\f$ .
RyoheiHagimoto 0:0e0631af0305 949 - **CV_CALIB_ZERO_TANGENT_DIST** Set tangential distortion coefficients for each camera to
RyoheiHagimoto 0:0e0631af0305 950 zeros and fix there.
RyoheiHagimoto 0:0e0631af0305 951 - **CV_CALIB_FIX_K1,...,CV_CALIB_FIX_K6** Do not change the corresponding radial
RyoheiHagimoto 0:0e0631af0305 952 distortion coefficient during the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is set,
RyoheiHagimoto 0:0e0631af0305 953 the coefficient from the supplied distCoeffs matrix is used. Otherwise, it is set to 0.
RyoheiHagimoto 0:0e0631af0305 954 - **CV_CALIB_RATIONAL_MODEL** Enable coefficients k4, k5, and k6. To provide the backward
RyoheiHagimoto 0:0e0631af0305 955 compatibility, this extra flag should be explicitly specified to make the calibration
RyoheiHagimoto 0:0e0631af0305 956 function use the rational model and return 8 coefficients. If the flag is not set, the
RyoheiHagimoto 0:0e0631af0305 957 function computes and returns only 5 distortion coefficients.
RyoheiHagimoto 0:0e0631af0305 958 - **CALIB_THIN_PRISM_MODEL** Coefficients s1, s2, s3 and s4 are enabled. To provide the
RyoheiHagimoto 0:0e0631af0305 959 backward compatibility, this extra flag should be explicitly specified to make the
RyoheiHagimoto 0:0e0631af0305 960 calibration function use the thin prism model and return 12 coefficients. If the flag is not
RyoheiHagimoto 0:0e0631af0305 961 set, the function computes and returns only 5 distortion coefficients.
RyoheiHagimoto 0:0e0631af0305 962 - **CALIB_FIX_S1_S2_S3_S4** The thin prism distortion coefficients are not changed during
RyoheiHagimoto 0:0e0631af0305 963 the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the
RyoheiHagimoto 0:0e0631af0305 964 supplied distCoeffs matrix is used. Otherwise, it is set to 0.
RyoheiHagimoto 0:0e0631af0305 965 - **CALIB_TILTED_MODEL** Coefficients tauX and tauY are enabled. To provide the
RyoheiHagimoto 0:0e0631af0305 966 backward compatibility, this extra flag should be explicitly specified to make the
RyoheiHagimoto 0:0e0631af0305 967 calibration function use the tilted sensor model and return 14 coefficients. If the flag is not
RyoheiHagimoto 0:0e0631af0305 968 set, the function computes and returns only 5 distortion coefficients.
RyoheiHagimoto 0:0e0631af0305 969 - **CALIB_FIX_TAUX_TAUY** The coefficients of the tilted sensor model are not changed during
RyoheiHagimoto 0:0e0631af0305 970 the optimization. If CV_CALIB_USE_INTRINSIC_GUESS is set, the coefficient from the
RyoheiHagimoto 0:0e0631af0305 971 supplied distCoeffs matrix is used. Otherwise, it is set to 0.
RyoheiHagimoto 0:0e0631af0305 972 @param criteria Termination criteria for the iterative optimization algorithm.
RyoheiHagimoto 0:0e0631af0305 973
RyoheiHagimoto 0:0e0631af0305 974 The function estimates transformation between two cameras making a stereo pair. If you have a stereo
RyoheiHagimoto 0:0e0631af0305 975 camera where the relative position and orientation of two cameras is fixed, and if you computed
RyoheiHagimoto 0:0e0631af0305 976 poses of an object relative to the first camera and to the second camera, (R1, T1) and (R2, T2),
RyoheiHagimoto 0:0e0631af0305 977 respectively (this can be done with solvePnP ), then those poses definitely relate to each other.
RyoheiHagimoto 0:0e0631af0305 978 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
RyoheiHagimoto 0:0e0631af0305 979 need to know the position and orientation of the second camera relative to the first camera. This is
RyoheiHagimoto 0:0e0631af0305 980 what the described function does. It computes ( \f$R\f$,\f$T\f$ ) so that:
RyoheiHagimoto 0:0e0631af0305 981
RyoheiHagimoto 0:0e0631af0305 982 \f[R_2=R*R_1
RyoheiHagimoto 0:0e0631af0305 983 T_2=R*T_1 + T,\f]
RyoheiHagimoto 0:0e0631af0305 984
RyoheiHagimoto 0:0e0631af0305 985 Optionally, it computes the essential matrix E:
RyoheiHagimoto 0:0e0631af0305 986
RyoheiHagimoto 0:0e0631af0305 987 \f[E= \vecthreethree{0}{-T_2}{T_1}{T_2}{0}{-T_0}{-T_1}{T_0}{0} *R\f]
RyoheiHagimoto 0:0e0631af0305 988
RyoheiHagimoto 0:0e0631af0305 989 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
RyoheiHagimoto 0:0e0631af0305 990 can also compute the fundamental matrix F:
RyoheiHagimoto 0:0e0631af0305 991
RyoheiHagimoto 0:0e0631af0305 992 \f[F = cameraMatrix2^{-T} E cameraMatrix1^{-1}\f]
RyoheiHagimoto 0:0e0631af0305 993
RyoheiHagimoto 0:0e0631af0305 994 Besides the stereo-related information, the function can also perform a full calibration of each of
RyoheiHagimoto 0:0e0631af0305 995 two cameras. However, due to the high dimensionality of the parameter space and noise in the input
RyoheiHagimoto 0:0e0631af0305 996 data, the function can diverge from the correct solution. If the intrinsic parameters can be
RyoheiHagimoto 0:0e0631af0305 997 estimated with high accuracy for each of the cameras individually (for example, using
RyoheiHagimoto 0:0e0631af0305 998 calibrateCamera ), you are recommended to do so and then pass CV_CALIB_FIX_INTRINSIC flag to the
RyoheiHagimoto 0:0e0631af0305 999 function along with the computed intrinsic parameters. Otherwise, if all the parameters are
RyoheiHagimoto 0:0e0631af0305 1000 estimated at once, it makes sense to restrict some parameters, for example, pass
RyoheiHagimoto 0:0e0631af0305 1001 CV_CALIB_SAME_FOCAL_LENGTH and CV_CALIB_ZERO_TANGENT_DIST flags, which is usually a
RyoheiHagimoto 0:0e0631af0305 1002 reasonable assumption.
RyoheiHagimoto 0:0e0631af0305 1003
RyoheiHagimoto 0:0e0631af0305 1004 Similarly to calibrateCamera , the function minimizes the total re-projection error for all the
RyoheiHagimoto 0:0e0631af0305 1005 points in all the available views from both cameras. The function returns the final value of the
RyoheiHagimoto 0:0e0631af0305 1006 re-projection error.
RyoheiHagimoto 0:0e0631af0305 1007 */
RyoheiHagimoto 0:0e0631af0305 1008 CV_EXPORTS_W double stereoCalibrate( InputArrayOfArrays objectPoints,
RyoheiHagimoto 0:0e0631af0305 1009 InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2,
RyoheiHagimoto 0:0e0631af0305 1010 InputOutputArray cameraMatrix1, InputOutputArray distCoeffs1,
RyoheiHagimoto 0:0e0631af0305 1011 InputOutputArray cameraMatrix2, InputOutputArray distCoeffs2,
RyoheiHagimoto 0:0e0631af0305 1012 Size imageSize, OutputArray R,OutputArray T, OutputArray E, OutputArray F,
RyoheiHagimoto 0:0e0631af0305 1013 int flags = CALIB_FIX_INTRINSIC,
RyoheiHagimoto 0:0e0631af0305 1014 TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6) );
RyoheiHagimoto 0:0e0631af0305 1015
RyoheiHagimoto 0:0e0631af0305 1016
RyoheiHagimoto 0:0e0631af0305 1017 /** @brief Computes rectification transforms for each head of a calibrated stereo camera.
RyoheiHagimoto 0:0e0631af0305 1018
RyoheiHagimoto 0:0e0631af0305 1019 @param cameraMatrix1 First camera matrix.
RyoheiHagimoto 0:0e0631af0305 1020 @param distCoeffs1 First camera distortion parameters.
RyoheiHagimoto 0:0e0631af0305 1021 @param cameraMatrix2 Second camera matrix.
RyoheiHagimoto 0:0e0631af0305 1022 @param distCoeffs2 Second camera distortion parameters.
RyoheiHagimoto 0:0e0631af0305 1023 @param imageSize Size of the image used for stereo calibration.
RyoheiHagimoto 0:0e0631af0305 1024 @param R Rotation matrix between the coordinate systems of the first and the second cameras.
RyoheiHagimoto 0:0e0631af0305 1025 @param T Translation vector between coordinate systems of the cameras.
RyoheiHagimoto 0:0e0631af0305 1026 @param R1 Output 3x3 rectification transform (rotation matrix) for the first camera.
RyoheiHagimoto 0:0e0631af0305 1027 @param R2 Output 3x3 rectification transform (rotation matrix) for the second camera.
RyoheiHagimoto 0:0e0631af0305 1028 @param P1 Output 3x4 projection matrix in the new (rectified) coordinate systems for the first
RyoheiHagimoto 0:0e0631af0305 1029 camera.
RyoheiHagimoto 0:0e0631af0305 1030 @param P2 Output 3x4 projection matrix in the new (rectified) coordinate systems for the second
RyoheiHagimoto 0:0e0631af0305 1031 camera.
RyoheiHagimoto 0:0e0631af0305 1032 @param Q Output \f$4 \times 4\f$ disparity-to-depth mapping matrix (see reprojectImageTo3D ).
RyoheiHagimoto 0:0e0631af0305 1033 @param flags Operation flags that may be zero or CV_CALIB_ZERO_DISPARITY . If the flag is set,
RyoheiHagimoto 0:0e0631af0305 1034 the function makes the principal points of each camera have the same pixel coordinates in the
RyoheiHagimoto 0:0e0631af0305 1035 rectified views. And if the flag is not set, the function may still shift the images in the
RyoheiHagimoto 0:0e0631af0305 1036 horizontal or vertical direction (depending on the orientation of epipolar lines) to maximize the
RyoheiHagimoto 0:0e0631af0305 1037 useful image area.
RyoheiHagimoto 0:0e0631af0305 1038 @param alpha Free scaling parameter. If it is -1 or absent, the function performs the default
RyoheiHagimoto 0:0e0631af0305 1039 scaling. Otherwise, the parameter should be between 0 and 1. alpha=0 means that the rectified
RyoheiHagimoto 0:0e0631af0305 1040 images are zoomed and shifted so that only valid pixels are visible (no black areas after
RyoheiHagimoto 0:0e0631af0305 1041 rectification). alpha=1 means that the rectified image is decimated and shifted so that all the
RyoheiHagimoto 0:0e0631af0305 1042 pixels from the original images from the cameras are retained in the rectified images (no source
RyoheiHagimoto 0:0e0631af0305 1043 image pixels are lost). Obviously, any intermediate value yields an intermediate result between
RyoheiHagimoto 0:0e0631af0305 1044 those two extreme cases.
RyoheiHagimoto 0:0e0631af0305 1045 @param newImageSize New image resolution after rectification. The same size should be passed to
RyoheiHagimoto 0:0e0631af0305 1046 initUndistortRectifyMap (see the stereo_calib.cpp sample in OpenCV samples directory). When (0,0)
RyoheiHagimoto 0:0e0631af0305 1047 is passed (default), it is set to the original imageSize . Setting it to larger value can help you
RyoheiHagimoto 0:0e0631af0305 1048 preserve details in the original image, especially when there is a big radial distortion.
RyoheiHagimoto 0:0e0631af0305 1049 @param validPixROI1 Optional output rectangles inside the rectified images where all the pixels
RyoheiHagimoto 0:0e0631af0305 1050 are valid. If alpha=0 , the ROIs cover the whole images. Otherwise, they are likely to be smaller
RyoheiHagimoto 0:0e0631af0305 1051 (see the picture below).
RyoheiHagimoto 0:0e0631af0305 1052 @param validPixROI2 Optional output rectangles inside the rectified images where all the pixels
RyoheiHagimoto 0:0e0631af0305 1053 are valid. If alpha=0 , the ROIs cover the whole images. Otherwise, they are likely to be smaller
RyoheiHagimoto 0:0e0631af0305 1054 (see the picture below).
RyoheiHagimoto 0:0e0631af0305 1055
RyoheiHagimoto 0:0e0631af0305 1056 The function computes the rotation matrices for each camera that (virtually) make both camera image
RyoheiHagimoto 0:0e0631af0305 1057 planes the same plane. Consequently, this makes all the epipolar lines parallel and thus simplifies
RyoheiHagimoto 0:0e0631af0305 1058 the dense stereo correspondence problem. The function takes the matrices computed by stereoCalibrate
RyoheiHagimoto 0:0e0631af0305 1059 as input. As output, it provides two rotation matrices and also two projection matrices in the new
RyoheiHagimoto 0:0e0631af0305 1060 coordinates. The function distinguishes the following two cases:
RyoheiHagimoto 0:0e0631af0305 1061
RyoheiHagimoto 0:0e0631af0305 1062 - **Horizontal stereo**: the first and the second camera views are shifted relative to each other
RyoheiHagimoto 0:0e0631af0305 1063 mainly along the x axis (with possible small vertical shift). In the rectified images, the
RyoheiHagimoto 0:0e0631af0305 1064 corresponding epipolar lines in the left and right cameras are horizontal and have the same
RyoheiHagimoto 0:0e0631af0305 1065 y-coordinate. P1 and P2 look like:
RyoheiHagimoto 0:0e0631af0305 1066
RyoheiHagimoto 0:0e0631af0305 1067 \f[\texttt{P1} = \begin{bmatrix} f & 0 & cx_1 & 0 \\ 0 & f & cy & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix}\f]
RyoheiHagimoto 0:0e0631af0305 1068
RyoheiHagimoto 0:0e0631af0305 1069 \f[\texttt{P2} = \begin{bmatrix} f & 0 & cx_2 & T_x*f \\ 0 & f & cy & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix} ,\f]
RyoheiHagimoto 0:0e0631af0305 1070
RyoheiHagimoto 0:0e0631af0305 1071 where \f$T_x\f$ is a horizontal shift between the cameras and \f$cx_1=cx_2\f$ if
RyoheiHagimoto 0:0e0631af0305 1072 CV_CALIB_ZERO_DISPARITY is set.
RyoheiHagimoto 0:0e0631af0305 1073
RyoheiHagimoto 0:0e0631af0305 1074 - **Vertical stereo**: the first and the second camera views are shifted relative to each other
RyoheiHagimoto 0:0e0631af0305 1075 mainly in vertical direction (and probably a bit in the horizontal direction too). The epipolar
RyoheiHagimoto 0:0e0631af0305 1076 lines in the rectified images are vertical and have the same x-coordinate. P1 and P2 look like:
RyoheiHagimoto 0:0e0631af0305 1077
RyoheiHagimoto 0:0e0631af0305 1078 \f[\texttt{P1} = \begin{bmatrix} f & 0 & cx & 0 \\ 0 & f & cy_1 & 0 \\ 0 & 0 & 1 & 0 \end{bmatrix}\f]
RyoheiHagimoto 0:0e0631af0305 1079
RyoheiHagimoto 0:0e0631af0305 1080 \f[\texttt{P2} = \begin{bmatrix} f & 0 & cx & 0 \\ 0 & f & cy_2 & T_y*f \\ 0 & 0 & 1 & 0 \end{bmatrix} ,\f]
RyoheiHagimoto 0:0e0631af0305 1081
RyoheiHagimoto 0:0e0631af0305 1082 where \f$T_y\f$ is a vertical shift between the cameras and \f$cy_1=cy_2\f$ if CALIB_ZERO_DISPARITY is
RyoheiHagimoto 0:0e0631af0305 1083 set.
RyoheiHagimoto 0:0e0631af0305 1084
RyoheiHagimoto 0:0e0631af0305 1085 As you can see, the first three columns of P1 and P2 will effectively be the new "rectified" camera
RyoheiHagimoto 0:0e0631af0305 1086 matrices. The matrices, together with R1 and R2 , can then be passed to initUndistortRectifyMap to
RyoheiHagimoto 0:0e0631af0305 1087 initialize the rectification map for each camera.
RyoheiHagimoto 0:0e0631af0305 1088
RyoheiHagimoto 0:0e0631af0305 1089 See below the screenshot from the stereo_calib.cpp sample. Some red horizontal lines pass through
RyoheiHagimoto 0:0e0631af0305 1090 the corresponding image regions. This means that the images are well rectified, which is what most
RyoheiHagimoto 0:0e0631af0305 1091 stereo correspondence algorithms rely on. The green rectangles are roi1 and roi2 . You see that
RyoheiHagimoto 0:0e0631af0305 1092 their interiors are all valid pixels.
RyoheiHagimoto 0:0e0631af0305 1093
RyoheiHagimoto 0:0e0631af0305 1094 ![image](pics/stereo_undistort.jpg)
RyoheiHagimoto 0:0e0631af0305 1095 */
RyoheiHagimoto 0:0e0631af0305 1096 CV_EXPORTS_W void stereoRectify( InputArray cameraMatrix1, InputArray distCoeffs1,
RyoheiHagimoto 0:0e0631af0305 1097 InputArray cameraMatrix2, InputArray distCoeffs2,
RyoheiHagimoto 0:0e0631af0305 1098 Size imageSize, InputArray R, InputArray T,
RyoheiHagimoto 0:0e0631af0305 1099 OutputArray R1, OutputArray R2,
RyoheiHagimoto 0:0e0631af0305 1100 OutputArray P1, OutputArray P2,
RyoheiHagimoto 0:0e0631af0305 1101 OutputArray Q, int flags = CALIB_ZERO_DISPARITY,
RyoheiHagimoto 0:0e0631af0305 1102 double alpha = -1, Size newImageSize = Size(),
RyoheiHagimoto 0:0e0631af0305 1103 CV_OUT Rect* validPixROI1 = 0, CV_OUT Rect* validPixROI2 = 0 );
RyoheiHagimoto 0:0e0631af0305 1104
RyoheiHagimoto 0:0e0631af0305 1105 /** @brief Computes a rectification transform for an uncalibrated stereo camera.
RyoheiHagimoto 0:0e0631af0305 1106
RyoheiHagimoto 0:0e0631af0305 1107 @param points1 Array of feature points in the first image.
RyoheiHagimoto 0:0e0631af0305 1108 @param points2 The corresponding points in the second image. The same formats as in
RyoheiHagimoto 0:0e0631af0305 1109 findFundamentalMat are supported.
RyoheiHagimoto 0:0e0631af0305 1110 @param F Input fundamental matrix. It can be computed from the same set of point pairs using
RyoheiHagimoto 0:0e0631af0305 1111 findFundamentalMat .
RyoheiHagimoto 0:0e0631af0305 1112 @param imgSize Size of the image.
RyoheiHagimoto 0:0e0631af0305 1113 @param H1 Output rectification homography matrix for the first image.
RyoheiHagimoto 0:0e0631af0305 1114 @param H2 Output rectification homography matrix for the second image.
RyoheiHagimoto 0:0e0631af0305 1115 @param threshold Optional threshold used to filter out the outliers. If the parameter is greater
RyoheiHagimoto 0:0e0631af0305 1116 than zero, all the point pairs that do not comply with the epipolar geometry (that is, the points
RyoheiHagimoto 0:0e0631af0305 1117 for which \f$|\texttt{points2[i]}^T*\texttt{F}*\texttt{points1[i]}|>\texttt{threshold}\f$ ) are
RyoheiHagimoto 0:0e0631af0305 1118 rejected prior to computing the homographies. Otherwise,all the points are considered inliers.
RyoheiHagimoto 0:0e0631af0305 1119
RyoheiHagimoto 0:0e0631af0305 1120 The function computes the rectification transformations without knowing intrinsic parameters of the
RyoheiHagimoto 0:0e0631af0305 1121 cameras and their relative position in the space, which explains the suffix "uncalibrated". Another
RyoheiHagimoto 0:0e0631af0305 1122 related difference from stereoRectify is that the function outputs not the rectification
RyoheiHagimoto 0:0e0631af0305 1123 transformations in the object (3D) space, but the planar perspective transformations encoded by the
RyoheiHagimoto 0:0e0631af0305 1124 homography matrices H1 and H2 . The function implements the algorithm @cite Hartley99 .
RyoheiHagimoto 0:0e0631af0305 1125
RyoheiHagimoto 0:0e0631af0305 1126 @note
RyoheiHagimoto 0:0e0631af0305 1127 While the algorithm does not need to know the intrinsic parameters of the cameras, it heavily
RyoheiHagimoto 0:0e0631af0305 1128 depends on the epipolar geometry. Therefore, if the camera lenses have a significant distortion,
RyoheiHagimoto 0:0e0631af0305 1129 it would be better to correct it before computing the fundamental matrix and calling this
RyoheiHagimoto 0:0e0631af0305 1130 function. For example, distortion coefficients can be estimated for each head of stereo camera
RyoheiHagimoto 0:0e0631af0305 1131 separately by using calibrateCamera . Then, the images can be corrected using undistort , or
RyoheiHagimoto 0:0e0631af0305 1132 just the point coordinates can be corrected with undistortPoints .
RyoheiHagimoto 0:0e0631af0305 1133 */
RyoheiHagimoto 0:0e0631af0305 1134 CV_EXPORTS_W bool stereoRectifyUncalibrated( InputArray points1, InputArray points2,
RyoheiHagimoto 0:0e0631af0305 1135 InputArray F, Size imgSize,
RyoheiHagimoto 0:0e0631af0305 1136 OutputArray H1, OutputArray H2,
RyoheiHagimoto 0:0e0631af0305 1137 double threshold = 5 );
RyoheiHagimoto 0:0e0631af0305 1138
RyoheiHagimoto 0:0e0631af0305 1139 //! computes the rectification transformations for 3-head camera, where all the heads are on the same line.
RyoheiHagimoto 0:0e0631af0305 1140 CV_EXPORTS_W float rectify3Collinear( InputArray cameraMatrix1, InputArray distCoeffs1,
RyoheiHagimoto 0:0e0631af0305 1141 InputArray cameraMatrix2, InputArray distCoeffs2,
RyoheiHagimoto 0:0e0631af0305 1142 InputArray cameraMatrix3, InputArray distCoeffs3,
RyoheiHagimoto 0:0e0631af0305 1143 InputArrayOfArrays imgpt1, InputArrayOfArrays imgpt3,
RyoheiHagimoto 0:0e0631af0305 1144 Size imageSize, InputArray R12, InputArray T12,
RyoheiHagimoto 0:0e0631af0305 1145 InputArray R13, InputArray T13,
RyoheiHagimoto 0:0e0631af0305 1146 OutputArray R1, OutputArray R2, OutputArray R3,
RyoheiHagimoto 0:0e0631af0305 1147 OutputArray P1, OutputArray P2, OutputArray P3,
RyoheiHagimoto 0:0e0631af0305 1148 OutputArray Q, double alpha, Size newImgSize,
RyoheiHagimoto 0:0e0631af0305 1149 CV_OUT Rect* roi1, CV_OUT Rect* roi2, int flags );
RyoheiHagimoto 0:0e0631af0305 1150
RyoheiHagimoto 0:0e0631af0305 1151 /** @brief Returns the new camera matrix based on the free scaling parameter.
RyoheiHagimoto 0:0e0631af0305 1152
RyoheiHagimoto 0:0e0631af0305 1153 @param cameraMatrix Input camera matrix.
RyoheiHagimoto 0:0e0631af0305 1154 @param distCoeffs Input vector of distortion coefficients
RyoheiHagimoto 0:0e0631af0305 1155 \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
RyoheiHagimoto 0:0e0631af0305 1156 4, 5, 8, 12 or 14 elements. If the vector is NULL/empty, the zero distortion coefficients are
RyoheiHagimoto 0:0e0631af0305 1157 assumed.
RyoheiHagimoto 0:0e0631af0305 1158 @param imageSize Original image size.
RyoheiHagimoto 0:0e0631af0305 1159 @param alpha Free scaling parameter between 0 (when all the pixels in the undistorted image are
RyoheiHagimoto 0:0e0631af0305 1160 valid) and 1 (when all the source image pixels are retained in the undistorted image). See
RyoheiHagimoto 0:0e0631af0305 1161 stereoRectify for details.
RyoheiHagimoto 0:0e0631af0305 1162 @param newImgSize Image size after rectification. By default,it is set to imageSize .
RyoheiHagimoto 0:0e0631af0305 1163 @param validPixROI Optional output rectangle that outlines all-good-pixels region in the
RyoheiHagimoto 0:0e0631af0305 1164 undistorted image. See roi1, roi2 description in stereoRectify .
RyoheiHagimoto 0:0e0631af0305 1165 @param centerPrincipalPoint Optional flag that indicates whether in the new camera matrix the
RyoheiHagimoto 0:0e0631af0305 1166 principal point should be at the image center or not. By default, the principal point is chosen to
RyoheiHagimoto 0:0e0631af0305 1167 best fit a subset of the source image (determined by alpha) to the corrected image.
RyoheiHagimoto 0:0e0631af0305 1168 @return new_camera_matrix Output new camera matrix.
RyoheiHagimoto 0:0e0631af0305 1169
RyoheiHagimoto 0:0e0631af0305 1170 The function computes and returns the optimal new camera matrix based on the free scaling parameter.
RyoheiHagimoto 0:0e0631af0305 1171 By varying this parameter, you may retrieve only sensible pixels alpha=0 , keep all the original
RyoheiHagimoto 0:0e0631af0305 1172 image pixels if there is valuable information in the corners alpha=1 , or get something in between.
RyoheiHagimoto 0:0e0631af0305 1173 When alpha\>0 , the undistortion result is likely to have some black pixels corresponding to
RyoheiHagimoto 0:0e0631af0305 1174 "virtual" pixels outside of the captured distorted image. The original camera matrix, distortion
RyoheiHagimoto 0:0e0631af0305 1175 coefficients, the computed new camera matrix, and newImageSize should be passed to
RyoheiHagimoto 0:0e0631af0305 1176 initUndistortRectifyMap to produce the maps for remap .
RyoheiHagimoto 0:0e0631af0305 1177 */
RyoheiHagimoto 0:0e0631af0305 1178 CV_EXPORTS_W Mat getOptimalNewCameraMatrix( InputArray cameraMatrix, InputArray distCoeffs,
RyoheiHagimoto 0:0e0631af0305 1179 Size imageSize, double alpha, Size newImgSize = Size(),
RyoheiHagimoto 0:0e0631af0305 1180 CV_OUT Rect* validPixROI = 0,
RyoheiHagimoto 0:0e0631af0305 1181 bool centerPrincipalPoint = false);
RyoheiHagimoto 0:0e0631af0305 1182
RyoheiHagimoto 0:0e0631af0305 1183 /** @brief Converts points from Euclidean to homogeneous space.
RyoheiHagimoto 0:0e0631af0305 1184
RyoheiHagimoto 0:0e0631af0305 1185 @param src Input vector of N-dimensional points.
RyoheiHagimoto 0:0e0631af0305 1186 @param dst Output vector of N+1-dimensional points.
RyoheiHagimoto 0:0e0631af0305 1187
RyoheiHagimoto 0:0e0631af0305 1188 The function converts points from Euclidean to homogeneous space by appending 1's to the tuple of
RyoheiHagimoto 0:0e0631af0305 1189 point coordinates. That is, each point (x1, x2, ..., xn) is converted to (x1, x2, ..., xn, 1).
RyoheiHagimoto 0:0e0631af0305 1190 */
RyoheiHagimoto 0:0e0631af0305 1191 CV_EXPORTS_W void convertPointsToHomogeneous( InputArray src, OutputArray dst );
RyoheiHagimoto 0:0e0631af0305 1192
RyoheiHagimoto 0:0e0631af0305 1193 /** @brief Converts points from homogeneous to Euclidean space.
RyoheiHagimoto 0:0e0631af0305 1194
RyoheiHagimoto 0:0e0631af0305 1195 @param src Input vector of N-dimensional points.
RyoheiHagimoto 0:0e0631af0305 1196 @param dst Output vector of N-1-dimensional points.
RyoheiHagimoto 0:0e0631af0305 1197
RyoheiHagimoto 0:0e0631af0305 1198 The function converts points homogeneous to Euclidean space using perspective projection. That is,
RyoheiHagimoto 0:0e0631af0305 1199 each point (x1, x2, ... x(n-1), xn) is converted to (x1/xn, x2/xn, ..., x(n-1)/xn). When xn=0, the
RyoheiHagimoto 0:0e0631af0305 1200 output point coordinates will be (0,0,0,...).
RyoheiHagimoto 0:0e0631af0305 1201 */
RyoheiHagimoto 0:0e0631af0305 1202 CV_EXPORTS_W void convertPointsFromHomogeneous( InputArray src, OutputArray dst );
RyoheiHagimoto 0:0e0631af0305 1203
RyoheiHagimoto 0:0e0631af0305 1204 /** @brief Converts points to/from homogeneous coordinates.
RyoheiHagimoto 0:0e0631af0305 1205
RyoheiHagimoto 0:0e0631af0305 1206 @param src Input array or vector of 2D, 3D, or 4D points.
RyoheiHagimoto 0:0e0631af0305 1207 @param dst Output vector of 2D, 3D, or 4D points.
RyoheiHagimoto 0:0e0631af0305 1208
RyoheiHagimoto 0:0e0631af0305 1209 The function converts 2D or 3D points from/to homogeneous coordinates by calling either
RyoheiHagimoto 0:0e0631af0305 1210 convertPointsToHomogeneous or convertPointsFromHomogeneous.
RyoheiHagimoto 0:0e0631af0305 1211
RyoheiHagimoto 0:0e0631af0305 1212 @note The function is obsolete. Use one of the previous two functions instead.
RyoheiHagimoto 0:0e0631af0305 1213 */
RyoheiHagimoto 0:0e0631af0305 1214 CV_EXPORTS void convertPointsHomogeneous( InputArray src, OutputArray dst );
RyoheiHagimoto 0:0e0631af0305 1215
RyoheiHagimoto 0:0e0631af0305 1216 /** @brief Calculates a fundamental matrix from the corresponding points in two images.
RyoheiHagimoto 0:0e0631af0305 1217
RyoheiHagimoto 0:0e0631af0305 1218 @param points1 Array of N points from the first image. The point coordinates should be
RyoheiHagimoto 0:0e0631af0305 1219 floating-point (single or double precision).
RyoheiHagimoto 0:0e0631af0305 1220 @param points2 Array of the second image points of the same size and format as points1 .
RyoheiHagimoto 0:0e0631af0305 1221 @param method Method for computing a fundamental matrix.
RyoheiHagimoto 0:0e0631af0305 1222 - **CV_FM_7POINT** for a 7-point algorithm. \f$N = 7\f$
RyoheiHagimoto 0:0e0631af0305 1223 - **CV_FM_8POINT** for an 8-point algorithm. \f$N \ge 8\f$
RyoheiHagimoto 0:0e0631af0305 1224 - **CV_FM_RANSAC** for the RANSAC algorithm. \f$N \ge 8\f$
RyoheiHagimoto 0:0e0631af0305 1225 - **CV_FM_LMEDS** for the LMedS algorithm. \f$N \ge 8\f$
RyoheiHagimoto 0:0e0631af0305 1226 @param param1 Parameter used for RANSAC. It is the maximum distance from a point to an epipolar
RyoheiHagimoto 0:0e0631af0305 1227 line in pixels, beyond which the point is considered an outlier and is not used for computing the
RyoheiHagimoto 0:0e0631af0305 1228 final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the
RyoheiHagimoto 0:0e0631af0305 1229 point localization, image resolution, and the image noise.
RyoheiHagimoto 0:0e0631af0305 1230 @param param2 Parameter used for the RANSAC or LMedS methods only. It specifies a desirable level
RyoheiHagimoto 0:0e0631af0305 1231 of confidence (probability) that the estimated matrix is correct.
RyoheiHagimoto 0:0e0631af0305 1232 @param mask
RyoheiHagimoto 0:0e0631af0305 1233
RyoheiHagimoto 0:0e0631af0305 1234 The epipolar geometry is described by the following equation:
RyoheiHagimoto 0:0e0631af0305 1235
RyoheiHagimoto 0:0e0631af0305 1236 \f[[p_2; 1]^T F [p_1; 1] = 0\f]
RyoheiHagimoto 0:0e0631af0305 1237
RyoheiHagimoto 0:0e0631af0305 1238 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
RyoheiHagimoto 0:0e0631af0305 1239 second images, respectively.
RyoheiHagimoto 0:0e0631af0305 1240
RyoheiHagimoto 0:0e0631af0305 1241 The function calculates the fundamental matrix using one of four methods listed above and returns
RyoheiHagimoto 0:0e0631af0305 1242 the found fundamental matrix. Normally just one matrix is found. But in case of the 7-point
RyoheiHagimoto 0:0e0631af0305 1243 algorithm, the function may return up to 3 solutions ( \f$9 \times 3\f$ matrix that stores all 3
RyoheiHagimoto 0:0e0631af0305 1244 matrices sequentially).
RyoheiHagimoto 0:0e0631af0305 1245
RyoheiHagimoto 0:0e0631af0305 1246 The calculated fundamental matrix may be passed further to computeCorrespondEpilines that finds the
RyoheiHagimoto 0:0e0631af0305 1247 epipolar lines corresponding to the specified points. It can also be passed to
RyoheiHagimoto 0:0e0631af0305 1248 stereoRectifyUncalibrated to compute the rectification transformation. :
RyoheiHagimoto 0:0e0631af0305 1249 @code
RyoheiHagimoto 0:0e0631af0305 1250 // Example. Estimation of fundamental matrix using the RANSAC algorithm
RyoheiHagimoto 0:0e0631af0305 1251 int point_count = 100;
RyoheiHagimoto 0:0e0631af0305 1252 vector<Point2f> points1(point_count);
RyoheiHagimoto 0:0e0631af0305 1253 vector<Point2f> points2(point_count);
RyoheiHagimoto 0:0e0631af0305 1254
RyoheiHagimoto 0:0e0631af0305 1255 // initialize the points here ...
RyoheiHagimoto 0:0e0631af0305 1256 for( int i = 0; i < point_count; i++ )
RyoheiHagimoto 0:0e0631af0305 1257 {
RyoheiHagimoto 0:0e0631af0305 1258 points1[i] = ...;
RyoheiHagimoto 0:0e0631af0305 1259 points2[i] = ...;
RyoheiHagimoto 0:0e0631af0305 1260 }
RyoheiHagimoto 0:0e0631af0305 1261
RyoheiHagimoto 0:0e0631af0305 1262 Mat fundamental_matrix =
RyoheiHagimoto 0:0e0631af0305 1263 findFundamentalMat(points1, points2, FM_RANSAC, 3, 0.99);
RyoheiHagimoto 0:0e0631af0305 1264 @endcode
RyoheiHagimoto 0:0e0631af0305 1265 */
RyoheiHagimoto 0:0e0631af0305 1266 CV_EXPORTS_W Mat findFundamentalMat( InputArray points1, InputArray points2,
RyoheiHagimoto 0:0e0631af0305 1267 int method = FM_RANSAC,
RyoheiHagimoto 0:0e0631af0305 1268 double param1 = 3., double param2 = 0.99,
RyoheiHagimoto 0:0e0631af0305 1269 OutputArray mask = noArray() );
RyoheiHagimoto 0:0e0631af0305 1270
RyoheiHagimoto 0:0e0631af0305 1271 /** @overload */
RyoheiHagimoto 0:0e0631af0305 1272 CV_EXPORTS Mat findFundamentalMat( InputArray points1, InputArray points2,
RyoheiHagimoto 0:0e0631af0305 1273 OutputArray mask, int method = FM_RANSAC,
RyoheiHagimoto 0:0e0631af0305 1274 double param1 = 3., double param2 = 0.99 );
RyoheiHagimoto 0:0e0631af0305 1275
RyoheiHagimoto 0:0e0631af0305 1276 /** @brief Calculates an essential matrix from the corresponding points in two images.
RyoheiHagimoto 0:0e0631af0305 1277
RyoheiHagimoto 0:0e0631af0305 1278 @param points1 Array of N (N \>= 5) 2D points from the first image. The point coordinates should
RyoheiHagimoto 0:0e0631af0305 1279 be floating-point (single or double precision).
RyoheiHagimoto 0:0e0631af0305 1280 @param points2 Array of the second image points of the same size and format as points1 .
RyoheiHagimoto 0:0e0631af0305 1281 @param cameraMatrix Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ .
RyoheiHagimoto 0:0e0631af0305 1282 Note that this function assumes that points1 and points2 are feature points from cameras with the
RyoheiHagimoto 0:0e0631af0305 1283 same camera matrix.
RyoheiHagimoto 0:0e0631af0305 1284 @param method Method for computing a fundamental matrix.
RyoheiHagimoto 0:0e0631af0305 1285 - **RANSAC** for the RANSAC algorithm.
RyoheiHagimoto 0:0e0631af0305 1286 - **MEDS** for the LMedS algorithm.
RyoheiHagimoto 0:0e0631af0305 1287 @param prob Parameter used for the RANSAC or LMedS methods only. It specifies a desirable level of
RyoheiHagimoto 0:0e0631af0305 1288 confidence (probability) that the estimated matrix is correct.
RyoheiHagimoto 0:0e0631af0305 1289 @param threshold Parameter used for RANSAC. It is the maximum distance from a point to an epipolar
RyoheiHagimoto 0:0e0631af0305 1290 line in pixels, beyond which the point is considered an outlier and is not used for computing the
RyoheiHagimoto 0:0e0631af0305 1291 final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the
RyoheiHagimoto 0:0e0631af0305 1292 point localization, image resolution, and the image noise.
RyoheiHagimoto 0:0e0631af0305 1293 @param mask Output array of N elements, every element of which is set to 0 for outliers and to 1
RyoheiHagimoto 0:0e0631af0305 1294 for the other points. The array is computed only in the RANSAC and LMedS methods.
RyoheiHagimoto 0:0e0631af0305 1295
RyoheiHagimoto 0:0e0631af0305 1296 This function estimates essential matrix based on the five-point algorithm solver in @cite Nister03 .
RyoheiHagimoto 0:0e0631af0305 1297 @cite SteweniusCFS is also a related. The epipolar geometry is described by the following equation:
RyoheiHagimoto 0:0e0631af0305 1298
RyoheiHagimoto 0:0e0631af0305 1299 \f[[p_2; 1]^T K^{-T} E K^{-1} [p_1; 1] = 0\f]
RyoheiHagimoto 0:0e0631af0305 1300
RyoheiHagimoto 0:0e0631af0305 1301 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
RyoheiHagimoto 0:0e0631af0305 1302 second images, respectively. The result of this function may be passed further to
RyoheiHagimoto 0:0e0631af0305 1303 decomposeEssentialMat or recoverPose to recover the relative pose between cameras.
RyoheiHagimoto 0:0e0631af0305 1304 */
RyoheiHagimoto 0:0e0631af0305 1305 CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2,
RyoheiHagimoto 0:0e0631af0305 1306 InputArray cameraMatrix, int method = RANSAC,
RyoheiHagimoto 0:0e0631af0305 1307 double prob = 0.999, double threshold = 1.0,
RyoheiHagimoto 0:0e0631af0305 1308 OutputArray mask = noArray() );
RyoheiHagimoto 0:0e0631af0305 1309
RyoheiHagimoto 0:0e0631af0305 1310 /** @overload
RyoheiHagimoto 0:0e0631af0305 1311 @param points1 Array of N (N \>= 5) 2D points from the first image. The point coordinates should
RyoheiHagimoto 0:0e0631af0305 1312 be floating-point (single or double precision).
RyoheiHagimoto 0:0e0631af0305 1313 @param points2 Array of the second image points of the same size and format as points1 .
RyoheiHagimoto 0:0e0631af0305 1314 @param focal focal length of the camera. Note that this function assumes that points1 and points2
RyoheiHagimoto 0:0e0631af0305 1315 are feature points from cameras with same focal length and principal point.
RyoheiHagimoto 0:0e0631af0305 1316 @param pp principal point of the camera.
RyoheiHagimoto 0:0e0631af0305 1317 @param method Method for computing a fundamental matrix.
RyoheiHagimoto 0:0e0631af0305 1318 - **RANSAC** for the RANSAC algorithm.
RyoheiHagimoto 0:0e0631af0305 1319 - **LMEDS** for the LMedS algorithm.
RyoheiHagimoto 0:0e0631af0305 1320 @param threshold Parameter used for RANSAC. It is the maximum distance from a point to an epipolar
RyoheiHagimoto 0:0e0631af0305 1321 line in pixels, beyond which the point is considered an outlier and is not used for computing the
RyoheiHagimoto 0:0e0631af0305 1322 final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the
RyoheiHagimoto 0:0e0631af0305 1323 point localization, image resolution, and the image noise.
RyoheiHagimoto 0:0e0631af0305 1324 @param prob Parameter used for the RANSAC or LMedS methods only. It specifies a desirable level of
RyoheiHagimoto 0:0e0631af0305 1325 confidence (probability) that the estimated matrix is correct.
RyoheiHagimoto 0:0e0631af0305 1326 @param mask Output array of N elements, every element of which is set to 0 for outliers and to 1
RyoheiHagimoto 0:0e0631af0305 1327 for the other points. The array is computed only in the RANSAC and LMedS methods.
RyoheiHagimoto 0:0e0631af0305 1328
RyoheiHagimoto 0:0e0631af0305 1329 This function differs from the one above that it computes camera matrix from focal length and
RyoheiHagimoto 0:0e0631af0305 1330 principal point:
RyoheiHagimoto 0:0e0631af0305 1331
RyoheiHagimoto 0:0e0631af0305 1332 \f[K =
RyoheiHagimoto 0:0e0631af0305 1333 \begin{bmatrix}
RyoheiHagimoto 0:0e0631af0305 1334 f & 0 & x_{pp} \\
RyoheiHagimoto 0:0e0631af0305 1335 0 & f & y_{pp} \\
RyoheiHagimoto 0:0e0631af0305 1336 0 & 0 & 1
RyoheiHagimoto 0:0e0631af0305 1337 \end{bmatrix}\f]
RyoheiHagimoto 0:0e0631af0305 1338 */
RyoheiHagimoto 0:0e0631af0305 1339 CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2,
RyoheiHagimoto 0:0e0631af0305 1340 double focal = 1.0, Point2d pp = Point2d(0, 0),
RyoheiHagimoto 0:0e0631af0305 1341 int method = RANSAC, double prob = 0.999,
RyoheiHagimoto 0:0e0631af0305 1342 double threshold = 1.0, OutputArray mask = noArray() );
RyoheiHagimoto 0:0e0631af0305 1343
RyoheiHagimoto 0:0e0631af0305 1344 /** @brief Decompose an essential matrix to possible rotations and translation.
RyoheiHagimoto 0:0e0631af0305 1345
RyoheiHagimoto 0:0e0631af0305 1346 @param E The input essential matrix.
RyoheiHagimoto 0:0e0631af0305 1347 @param R1 One possible rotation matrix.
RyoheiHagimoto 0:0e0631af0305 1348 @param R2 Another possible rotation matrix.
RyoheiHagimoto 0:0e0631af0305 1349 @param t One possible translation.
RyoheiHagimoto 0:0e0631af0305 1350
RyoheiHagimoto 0:0e0631af0305 1351 This function decompose an essential matrix E using svd decomposition @cite HartleyZ00 . Generally 4
RyoheiHagimoto 0:0e0631af0305 1352 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
RyoheiHagimoto 0:0e0631af0305 1353 decomposing E, you can only get the direction of the translation, so the function returns unit t.
RyoheiHagimoto 0:0e0631af0305 1354 */
RyoheiHagimoto 0:0e0631af0305 1355 CV_EXPORTS_W void decomposeEssentialMat( InputArray E, OutputArray R1, OutputArray R2, OutputArray t );
RyoheiHagimoto 0:0e0631af0305 1356
RyoheiHagimoto 0:0e0631af0305 1357 /** @brief Recover relative camera rotation and translation from an estimated essential matrix and the
RyoheiHagimoto 0:0e0631af0305 1358 corresponding points in two images, using cheirality check. Returns the number of inliers which pass
RyoheiHagimoto 0:0e0631af0305 1359 the check.
RyoheiHagimoto 0:0e0631af0305 1360
RyoheiHagimoto 0:0e0631af0305 1361 @param E The input essential matrix.
RyoheiHagimoto 0:0e0631af0305 1362 @param points1 Array of N 2D points from the first image. The point coordinates should be
RyoheiHagimoto 0:0e0631af0305 1363 floating-point (single or double precision).
RyoheiHagimoto 0:0e0631af0305 1364 @param points2 Array of the second image points of the same size and format as points1 .
RyoheiHagimoto 0:0e0631af0305 1365 @param cameraMatrix Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ .
RyoheiHagimoto 0:0e0631af0305 1366 Note that this function assumes that points1 and points2 are feature points from cameras with the
RyoheiHagimoto 0:0e0631af0305 1367 same camera matrix.
RyoheiHagimoto 0:0e0631af0305 1368 @param R Recovered relative rotation.
RyoheiHagimoto 0:0e0631af0305 1369 @param t Recoverd relative translation.
RyoheiHagimoto 0:0e0631af0305 1370 @param mask Input/output mask for inliers in points1 and points2.
RyoheiHagimoto 0:0e0631af0305 1371 : If it is not empty, then it marks inliers in points1 and points2 for then given essential
RyoheiHagimoto 0:0e0631af0305 1372 matrix E. Only these inliers will be used to recover pose. In the output mask only inliers
RyoheiHagimoto 0:0e0631af0305 1373 which pass the cheirality check.
RyoheiHagimoto 0:0e0631af0305 1374 This function decomposes an essential matrix using decomposeEssentialMat and then verifies possible
RyoheiHagimoto 0:0e0631af0305 1375 pose hypotheses by doing cheirality check. The cheirality check basically means that the
RyoheiHagimoto 0:0e0631af0305 1376 triangulated 3D points should have positive depth. Some details can be found in @cite Nister03 .
RyoheiHagimoto 0:0e0631af0305 1377
RyoheiHagimoto 0:0e0631af0305 1378 This function can be used to process output E and mask from findEssentialMat. In this scenario,
RyoheiHagimoto 0:0e0631af0305 1379 points1 and points2 are the same input for findEssentialMat. :
RyoheiHagimoto 0:0e0631af0305 1380 @code
RyoheiHagimoto 0:0e0631af0305 1381 // Example. Estimation of fundamental matrix using the RANSAC algorithm
RyoheiHagimoto 0:0e0631af0305 1382 int point_count = 100;
RyoheiHagimoto 0:0e0631af0305 1383 vector<Point2f> points1(point_count);
RyoheiHagimoto 0:0e0631af0305 1384 vector<Point2f> points2(point_count);
RyoheiHagimoto 0:0e0631af0305 1385
RyoheiHagimoto 0:0e0631af0305 1386 // initialize the points here ...
RyoheiHagimoto 0:0e0631af0305 1387 for( int i = 0; i < point_count; i++ )
RyoheiHagimoto 0:0e0631af0305 1388 {
RyoheiHagimoto 0:0e0631af0305 1389 points1[i] = ...;
RyoheiHagimoto 0:0e0631af0305 1390 points2[i] = ...;
RyoheiHagimoto 0:0e0631af0305 1391 }
RyoheiHagimoto 0:0e0631af0305 1392
RyoheiHagimoto 0:0e0631af0305 1393 // cametra matrix with both focal lengths = 1, and principal point = (0, 0)
RyoheiHagimoto 0:0e0631af0305 1394 Mat cameraMatrix = Mat::eye(3, 3, CV_64F);
RyoheiHagimoto 0:0e0631af0305 1395
RyoheiHagimoto 0:0e0631af0305 1396 Mat E, R, t, mask;
RyoheiHagimoto 0:0e0631af0305 1397
RyoheiHagimoto 0:0e0631af0305 1398 E = findEssentialMat(points1, points2, cameraMatrix, RANSAC, 0.999, 1.0, mask);
RyoheiHagimoto 0:0e0631af0305 1399 recoverPose(E, points1, points2, cameraMatrix, R, t, mask);
RyoheiHagimoto 0:0e0631af0305 1400 @endcode
RyoheiHagimoto 0:0e0631af0305 1401 */
RyoheiHagimoto 0:0e0631af0305 1402 CV_EXPORTS_W int recoverPose( InputArray E, InputArray points1, InputArray points2,
RyoheiHagimoto 0:0e0631af0305 1403 InputArray cameraMatrix, OutputArray R, OutputArray t,
RyoheiHagimoto 0:0e0631af0305 1404 InputOutputArray mask = noArray() );
RyoheiHagimoto 0:0e0631af0305 1405
RyoheiHagimoto 0:0e0631af0305 1406 /** @overload
RyoheiHagimoto 0:0e0631af0305 1407 @param E The input essential matrix.
RyoheiHagimoto 0:0e0631af0305 1408 @param points1 Array of N 2D points from the first image. The point coordinates should be
RyoheiHagimoto 0:0e0631af0305 1409 floating-point (single or double precision).
RyoheiHagimoto 0:0e0631af0305 1410 @param points2 Array of the second image points of the same size and format as points1 .
RyoheiHagimoto 0:0e0631af0305 1411 @param R Recovered relative rotation.
RyoheiHagimoto 0:0e0631af0305 1412 @param t Recoverd relative translation.
RyoheiHagimoto 0:0e0631af0305 1413 @param focal Focal length of the camera. Note that this function assumes that points1 and points2
RyoheiHagimoto 0:0e0631af0305 1414 are feature points from cameras with same focal length and principal point.
RyoheiHagimoto 0:0e0631af0305 1415 @param pp principal point of the camera.
RyoheiHagimoto 0:0e0631af0305 1416 @param mask Input/output mask for inliers in points1 and points2.
RyoheiHagimoto 0:0e0631af0305 1417 : If it is not empty, then it marks inliers in points1 and points2 for then given essential
RyoheiHagimoto 0:0e0631af0305 1418 matrix E. Only these inliers will be used to recover pose. In the output mask only inliers
RyoheiHagimoto 0:0e0631af0305 1419 which pass the cheirality check.
RyoheiHagimoto 0:0e0631af0305 1420
RyoheiHagimoto 0:0e0631af0305 1421 This function differs from the one above that it computes camera matrix from focal length and
RyoheiHagimoto 0:0e0631af0305 1422 principal point:
RyoheiHagimoto 0:0e0631af0305 1423
RyoheiHagimoto 0:0e0631af0305 1424 \f[K =
RyoheiHagimoto 0:0e0631af0305 1425 \begin{bmatrix}
RyoheiHagimoto 0:0e0631af0305 1426 f & 0 & x_{pp} \\
RyoheiHagimoto 0:0e0631af0305 1427 0 & f & y_{pp} \\
RyoheiHagimoto 0:0e0631af0305 1428 0 & 0 & 1
RyoheiHagimoto 0:0e0631af0305 1429 \end{bmatrix}\f]
RyoheiHagimoto 0:0e0631af0305 1430 */
RyoheiHagimoto 0:0e0631af0305 1431 CV_EXPORTS_W int recoverPose( InputArray E, InputArray points1, InputArray points2,
RyoheiHagimoto 0:0e0631af0305 1432 OutputArray R, OutputArray t,
RyoheiHagimoto 0:0e0631af0305 1433 double focal = 1.0, Point2d pp = Point2d(0, 0),
RyoheiHagimoto 0:0e0631af0305 1434 InputOutputArray mask = noArray() );
RyoheiHagimoto 0:0e0631af0305 1435
RyoheiHagimoto 0:0e0631af0305 1436 /** @brief For points in an image of a stereo pair, computes the corresponding epilines in the other image.
RyoheiHagimoto 0:0e0631af0305 1437
RyoheiHagimoto 0:0e0631af0305 1438 @param points Input points. \f$N \times 1\f$ or \f$1 \times N\f$ matrix of type CV_32FC2 or
RyoheiHagimoto 0:0e0631af0305 1439 vector\<Point2f\> .
RyoheiHagimoto 0:0e0631af0305 1440 @param whichImage Index of the image (1 or 2) that contains the points .
RyoheiHagimoto 0:0e0631af0305 1441 @param F Fundamental matrix that can be estimated using findFundamentalMat or stereoRectify .
RyoheiHagimoto 0:0e0631af0305 1442 @param lines Output vector of the epipolar lines corresponding to the points in the other image.
RyoheiHagimoto 0:0e0631af0305 1443 Each line \f$ax + by + c=0\f$ is encoded by 3 numbers \f$(a, b, c)\f$ .
RyoheiHagimoto 0:0e0631af0305 1444
RyoheiHagimoto 0:0e0631af0305 1445 For every point in one of the two images of a stereo pair, the function finds the equation of the
RyoheiHagimoto 0:0e0631af0305 1446 corresponding epipolar line in the other image.
RyoheiHagimoto 0:0e0631af0305 1447
RyoheiHagimoto 0:0e0631af0305 1448 From the fundamental matrix definition (see findFundamentalMat ), line \f$l^{(2)}_i\f$ in the second
RyoheiHagimoto 0:0e0631af0305 1449 image for the point \f$p^{(1)}_i\f$ in the first image (when whichImage=1 ) is computed as:
RyoheiHagimoto 0:0e0631af0305 1450
RyoheiHagimoto 0:0e0631af0305 1451 \f[l^{(2)}_i = F p^{(1)}_i\f]
RyoheiHagimoto 0:0e0631af0305 1452
RyoheiHagimoto 0:0e0631af0305 1453 And vice versa, when whichImage=2, \f$l^{(1)}_i\f$ is computed from \f$p^{(2)}_i\f$ as:
RyoheiHagimoto 0:0e0631af0305 1454
RyoheiHagimoto 0:0e0631af0305 1455 \f[l^{(1)}_i = F^T p^{(2)}_i\f]
RyoheiHagimoto 0:0e0631af0305 1456
RyoheiHagimoto 0:0e0631af0305 1457 Line coefficients are defined up to a scale. They are normalized so that \f$a_i^2+b_i^2=1\f$ .
RyoheiHagimoto 0:0e0631af0305 1458 */
RyoheiHagimoto 0:0e0631af0305 1459 CV_EXPORTS_W void computeCorrespondEpilines( InputArray points, int whichImage,
RyoheiHagimoto 0:0e0631af0305 1460 InputArray F, OutputArray lines );
RyoheiHagimoto 0:0e0631af0305 1461
RyoheiHagimoto 0:0e0631af0305 1462 /** @brief Reconstructs points by triangulation.
RyoheiHagimoto 0:0e0631af0305 1463
RyoheiHagimoto 0:0e0631af0305 1464 @param projMatr1 3x4 projection matrix of the first camera.
RyoheiHagimoto 0:0e0631af0305 1465 @param projMatr2 3x4 projection matrix of the second camera.
RyoheiHagimoto 0:0e0631af0305 1466 @param projPoints1 2xN array of feature points in the first image. In case of c++ version it can
RyoheiHagimoto 0:0e0631af0305 1467 be also a vector of feature points or two-channel matrix of size 1xN or Nx1.
RyoheiHagimoto 0:0e0631af0305 1468 @param projPoints2 2xN array of corresponding points in the second image. In case of c++ version
RyoheiHagimoto 0:0e0631af0305 1469 it can be also a vector of feature points or two-channel matrix of size 1xN or Nx1.
RyoheiHagimoto 0:0e0631af0305 1470 @param points4D 4xN array of reconstructed points in homogeneous coordinates.
RyoheiHagimoto 0:0e0631af0305 1471
RyoheiHagimoto 0:0e0631af0305 1472 The function reconstructs 3-dimensional points (in homogeneous coordinates) by using their
RyoheiHagimoto 0:0e0631af0305 1473 observations with a stereo camera. Projections matrices can be obtained from stereoRectify.
RyoheiHagimoto 0:0e0631af0305 1474
RyoheiHagimoto 0:0e0631af0305 1475 @note
RyoheiHagimoto 0:0e0631af0305 1476 Keep in mind that all input data should be of float type in order for this function to work.
RyoheiHagimoto 0:0e0631af0305 1477
RyoheiHagimoto 0:0e0631af0305 1478 @sa
RyoheiHagimoto 0:0e0631af0305 1479 reprojectImageTo3D
RyoheiHagimoto 0:0e0631af0305 1480 */
RyoheiHagimoto 0:0e0631af0305 1481 CV_EXPORTS_W void triangulatePoints( InputArray projMatr1, InputArray projMatr2,
RyoheiHagimoto 0:0e0631af0305 1482 InputArray projPoints1, InputArray projPoints2,
RyoheiHagimoto 0:0e0631af0305 1483 OutputArray points4D );
RyoheiHagimoto 0:0e0631af0305 1484
RyoheiHagimoto 0:0e0631af0305 1485 /** @brief Refines coordinates of corresponding points.
RyoheiHagimoto 0:0e0631af0305 1486
RyoheiHagimoto 0:0e0631af0305 1487 @param F 3x3 fundamental matrix.
RyoheiHagimoto 0:0e0631af0305 1488 @param points1 1xN array containing the first set of points.
RyoheiHagimoto 0:0e0631af0305 1489 @param points2 1xN array containing the second set of points.
RyoheiHagimoto 0:0e0631af0305 1490 @param newPoints1 The optimized points1.
RyoheiHagimoto 0:0e0631af0305 1491 @param newPoints2 The optimized points2.
RyoheiHagimoto 0:0e0631af0305 1492
RyoheiHagimoto 0:0e0631af0305 1493 The function implements the Optimal Triangulation Method (see Multiple View Geometry for details).
RyoheiHagimoto 0:0e0631af0305 1494 For each given point correspondence points1[i] \<-\> points2[i], and a fundamental matrix F, it
RyoheiHagimoto 0:0e0631af0305 1495 computes the corrected correspondences newPoints1[i] \<-\> newPoints2[i] that minimize the geometric
RyoheiHagimoto 0:0e0631af0305 1496 error \f$d(points1[i], newPoints1[i])^2 + d(points2[i],newPoints2[i])^2\f$ (where \f$d(a,b)\f$ is the
RyoheiHagimoto 0:0e0631af0305 1497 geometric distance between points \f$a\f$ and \f$b\f$ ) subject to the epipolar constraint
RyoheiHagimoto 0:0e0631af0305 1498 \f$newPoints2^T * F * newPoints1 = 0\f$ .
RyoheiHagimoto 0:0e0631af0305 1499 */
RyoheiHagimoto 0:0e0631af0305 1500 CV_EXPORTS_W void correctMatches( InputArray F, InputArray points1, InputArray points2,
RyoheiHagimoto 0:0e0631af0305 1501 OutputArray newPoints1, OutputArray newPoints2 );
RyoheiHagimoto 0:0e0631af0305 1502
RyoheiHagimoto 0:0e0631af0305 1503 /** @brief Filters off small noise blobs (speckles) in the disparity map
RyoheiHagimoto 0:0e0631af0305 1504
RyoheiHagimoto 0:0e0631af0305 1505 @param img The input 16-bit signed disparity image
RyoheiHagimoto 0:0e0631af0305 1506 @param newVal The disparity value used to paint-off the speckles
RyoheiHagimoto 0:0e0631af0305 1507 @param maxSpeckleSize The maximum speckle size to consider it a speckle. Larger blobs are not
RyoheiHagimoto 0:0e0631af0305 1508 affected by the algorithm
RyoheiHagimoto 0:0e0631af0305 1509 @param maxDiff Maximum difference between neighbor disparity pixels to put them into the same
RyoheiHagimoto 0:0e0631af0305 1510 blob. Note that since StereoBM, StereoSGBM and may be other algorithms return a fixed-point
RyoheiHagimoto 0:0e0631af0305 1511 disparity map, where disparity values are multiplied by 16, this scale factor should be taken into
RyoheiHagimoto 0:0e0631af0305 1512 account when specifying this parameter value.
RyoheiHagimoto 0:0e0631af0305 1513 @param buf The optional temporary buffer to avoid memory allocation within the function.
RyoheiHagimoto 0:0e0631af0305 1514 */
RyoheiHagimoto 0:0e0631af0305 1515 CV_EXPORTS_W void filterSpeckles( InputOutputArray img, double newVal,
RyoheiHagimoto 0:0e0631af0305 1516 int maxSpeckleSize, double maxDiff,
RyoheiHagimoto 0:0e0631af0305 1517 InputOutputArray buf = noArray() );
RyoheiHagimoto 0:0e0631af0305 1518
RyoheiHagimoto 0:0e0631af0305 1519 //! computes valid disparity ROI from the valid ROIs of the rectified images (that are returned by cv::stereoRectify())
RyoheiHagimoto 0:0e0631af0305 1520 CV_EXPORTS_W Rect getValidDisparityROI( Rect roi1, Rect roi2,
RyoheiHagimoto 0:0e0631af0305 1521 int minDisparity, int numberOfDisparities,
RyoheiHagimoto 0:0e0631af0305 1522 int SADWindowSize );
RyoheiHagimoto 0:0e0631af0305 1523
RyoheiHagimoto 0:0e0631af0305 1524 //! validates disparity using the left-right check. The matrix "cost" should be computed by the stereo correspondence algorithm
RyoheiHagimoto 0:0e0631af0305 1525 CV_EXPORTS_W void validateDisparity( InputOutputArray disparity, InputArray cost,
RyoheiHagimoto 0:0e0631af0305 1526 int minDisparity, int numberOfDisparities,
RyoheiHagimoto 0:0e0631af0305 1527 int disp12MaxDisp = 1 );
RyoheiHagimoto 0:0e0631af0305 1528
RyoheiHagimoto 0:0e0631af0305 1529 /** @brief Reprojects a disparity image to 3D space.
RyoheiHagimoto 0:0e0631af0305 1530
RyoheiHagimoto 0:0e0631af0305 1531 @param disparity Input single-channel 8-bit unsigned, 16-bit signed, 32-bit signed or 32-bit
RyoheiHagimoto 0:0e0631af0305 1532 floating-point disparity image. If 16-bit signed format is used, the values are assumed to have no
RyoheiHagimoto 0:0e0631af0305 1533 fractional bits.
RyoheiHagimoto 0:0e0631af0305 1534 @param _3dImage Output 3-channel floating-point image of the same size as disparity . Each
RyoheiHagimoto 0:0e0631af0305 1535 element of _3dImage(x,y) contains 3D coordinates of the point (x,y) computed from the disparity
RyoheiHagimoto 0:0e0631af0305 1536 map.
RyoheiHagimoto 0:0e0631af0305 1537 @param Q \f$4 \times 4\f$ perspective transformation matrix that can be obtained with stereoRectify.
RyoheiHagimoto 0:0e0631af0305 1538 @param handleMissingValues Indicates, whether the function should handle missing values (i.e.
RyoheiHagimoto 0:0e0631af0305 1539 points where the disparity was not computed). If handleMissingValues=true, then pixels with the
RyoheiHagimoto 0:0e0631af0305 1540 minimal disparity that corresponds to the outliers (see StereoMatcher::compute ) are transformed
RyoheiHagimoto 0:0e0631af0305 1541 to 3D points with a very large Z value (currently set to 10000).
RyoheiHagimoto 0:0e0631af0305 1542 @param ddepth The optional output array depth. If it is -1, the output image will have CV_32F
RyoheiHagimoto 0:0e0631af0305 1543 depth. ddepth can also be set to CV_16S, CV_32S or CV_32F.
RyoheiHagimoto 0:0e0631af0305 1544
RyoheiHagimoto 0:0e0631af0305 1545 The function transforms a single-channel disparity map to a 3-channel image representing a 3D
RyoheiHagimoto 0:0e0631af0305 1546 surface. That is, for each pixel (x,y) andthe corresponding disparity d=disparity(x,y) , it
RyoheiHagimoto 0:0e0631af0305 1547 computes:
RyoheiHagimoto 0:0e0631af0305 1548
RyoheiHagimoto 0:0e0631af0305 1549 \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]
RyoheiHagimoto 0:0e0631af0305 1550
RyoheiHagimoto 0:0e0631af0305 1551 The matrix Q can be an arbitrary \f$4 \times 4\f$ matrix (for example, the one computed by
RyoheiHagimoto 0:0e0631af0305 1552 stereoRectify). To reproject a sparse set of points {(x,y,d),...} to 3D space, use
RyoheiHagimoto 0:0e0631af0305 1553 perspectiveTransform .
RyoheiHagimoto 0:0e0631af0305 1554 */
RyoheiHagimoto 0:0e0631af0305 1555 CV_EXPORTS_W void reprojectImageTo3D( InputArray disparity,
RyoheiHagimoto 0:0e0631af0305 1556 OutputArray _3dImage, InputArray Q,
RyoheiHagimoto 0:0e0631af0305 1557 bool handleMissingValues = false,
RyoheiHagimoto 0:0e0631af0305 1558 int ddepth = -1 );
RyoheiHagimoto 0:0e0631af0305 1559
RyoheiHagimoto 0:0e0631af0305 1560 /** @brief Calculates the Sampson Distance between two points.
RyoheiHagimoto 0:0e0631af0305 1561
RyoheiHagimoto 0:0e0631af0305 1562 The function sampsonDistance calculates and returns the first order approximation of the geometric error as:
RyoheiHagimoto 0:0e0631af0305 1563 \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]
RyoheiHagimoto 0:0e0631af0305 1564 The fundamental matrix may be calculated using the cv::findFundamentalMat function. See HZ 11.4.3 for details.
RyoheiHagimoto 0:0e0631af0305 1565 @param pt1 first homogeneous 2d point
RyoheiHagimoto 0:0e0631af0305 1566 @param pt2 second homogeneous 2d point
RyoheiHagimoto 0:0e0631af0305 1567 @param F fundamental matrix
RyoheiHagimoto 0:0e0631af0305 1568 */
RyoheiHagimoto 0:0e0631af0305 1569 CV_EXPORTS_W double sampsonDistance(InputArray pt1, InputArray pt2, InputArray F);
RyoheiHagimoto 0:0e0631af0305 1570
RyoheiHagimoto 0:0e0631af0305 1571 /** @brief Computes an optimal affine transformation between two 3D point sets.
RyoheiHagimoto 0:0e0631af0305 1572
RyoheiHagimoto 0:0e0631af0305 1573 @param src First input 3D point set.
RyoheiHagimoto 0:0e0631af0305 1574 @param dst Second input 3D point set.
RyoheiHagimoto 0:0e0631af0305 1575 @param out Output 3D affine transformation matrix \f$3 \times 4\f$ .
RyoheiHagimoto 0:0e0631af0305 1576 @param inliers Output vector indicating which points are inliers.
RyoheiHagimoto 0:0e0631af0305 1577 @param ransacThreshold Maximum reprojection error in the RANSAC algorithm to consider a point as
RyoheiHagimoto 0:0e0631af0305 1578 an inlier.
RyoheiHagimoto 0:0e0631af0305 1579 @param confidence Confidence level, between 0 and 1, for the estimated transformation. Anything
RyoheiHagimoto 0:0e0631af0305 1580 between 0.95 and 0.99 is usually good enough. Values too close to 1 can slow down the estimation
RyoheiHagimoto 0:0e0631af0305 1581 significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation.
RyoheiHagimoto 0:0e0631af0305 1582
RyoheiHagimoto 0:0e0631af0305 1583 The function estimates an optimal 3D affine transformation between two 3D point sets using the
RyoheiHagimoto 0:0e0631af0305 1584 RANSAC algorithm.
RyoheiHagimoto 0:0e0631af0305 1585 */
RyoheiHagimoto 0:0e0631af0305 1586 CV_EXPORTS_W int estimateAffine3D(InputArray src, InputArray dst,
RyoheiHagimoto 0:0e0631af0305 1587 OutputArray out, OutputArray inliers,
RyoheiHagimoto 0:0e0631af0305 1588 double ransacThreshold = 3, double confidence = 0.99);
RyoheiHagimoto 0:0e0631af0305 1589
RyoheiHagimoto 0:0e0631af0305 1590 /** @brief Computes an optimal affine transformation between two 2D point sets.
RyoheiHagimoto 0:0e0631af0305 1591
RyoheiHagimoto 0:0e0631af0305 1592 @param from First input 2D point set.
RyoheiHagimoto 0:0e0631af0305 1593 @param to Second input 2D point set.
RyoheiHagimoto 0:0e0631af0305 1594 @param inliers Output vector indicating which points are inliers.
RyoheiHagimoto 0:0e0631af0305 1595 @param method Robust method used to compute tranformation. The following methods are possible:
RyoheiHagimoto 0:0e0631af0305 1596 - cv::RANSAC - RANSAC-based robust method
RyoheiHagimoto 0:0e0631af0305 1597 - cv::LMEDS - Least-Median robust method
RyoheiHagimoto 0:0e0631af0305 1598 RANSAC is the default method.
RyoheiHagimoto 0:0e0631af0305 1599 @param ransacReprojThreshold Maximum reprojection error in the RANSAC algorithm to consider
RyoheiHagimoto 0:0e0631af0305 1600 a point as an inlier. Applies only to RANSAC.
RyoheiHagimoto 0:0e0631af0305 1601 @param maxIters The maximum number of robust method iterations, 2000 is the maximum it can be.
RyoheiHagimoto 0:0e0631af0305 1602 @param confidence Confidence level, between 0 and 1, for the estimated transformation. Anything
RyoheiHagimoto 0:0e0631af0305 1603 between 0.95 and 0.99 is usually good enough. Values too close to 1 can slow down the estimation
RyoheiHagimoto 0:0e0631af0305 1604 significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation.
RyoheiHagimoto 0:0e0631af0305 1605 @param refineIters Maximum number of iterations of refining algorithm (Levenberg-Marquardt).
RyoheiHagimoto 0:0e0631af0305 1606 Passing 0 will disable refining, so the output matrix will be output of robust method.
RyoheiHagimoto 0:0e0631af0305 1607
RyoheiHagimoto 0:0e0631af0305 1608 @return Output 2D affine transformation matrix \f$2 \times 3\f$ or empty matrix if transformation
RyoheiHagimoto 0:0e0631af0305 1609 could not be estimated.
RyoheiHagimoto 0:0e0631af0305 1610
RyoheiHagimoto 0:0e0631af0305 1611 The function estimates an optimal 2D affine transformation between two 2D point sets using the
RyoheiHagimoto 0:0e0631af0305 1612 selected robust algorithm.
RyoheiHagimoto 0:0e0631af0305 1613
RyoheiHagimoto 0:0e0631af0305 1614 The computed transformation is then refined further (using only inliers) with the
RyoheiHagimoto 0:0e0631af0305 1615 Levenberg-Marquardt method to reduce the re-projection error even more.
RyoheiHagimoto 0:0e0631af0305 1616
RyoheiHagimoto 0:0e0631af0305 1617 @note
RyoheiHagimoto 0:0e0631af0305 1618 The RANSAC method can handle practically any ratio of outliers but need a threshold to
RyoheiHagimoto 0:0e0631af0305 1619 distinguish inliers from outliers. The method LMeDS does not need any threshold but it works
RyoheiHagimoto 0:0e0631af0305 1620 correctly only when there are more than 50% of inliers.
RyoheiHagimoto 0:0e0631af0305 1621
RyoheiHagimoto 0:0e0631af0305 1622 @sa estimateAffinePartial2D, getAffineTransform
RyoheiHagimoto 0:0e0631af0305 1623 */
RyoheiHagimoto 0:0e0631af0305 1624 CV_EXPORTS_W cv::Mat estimateAffine2D(InputArray from, InputArray to, OutputArray inliers = noArray(),
RyoheiHagimoto 0:0e0631af0305 1625 int method = RANSAC, double ransacReprojThreshold = 3,
RyoheiHagimoto 0:0e0631af0305 1626 size_t maxIters = 2000, double confidence = 0.99,
RyoheiHagimoto 0:0e0631af0305 1627 size_t refineIters = 10);
RyoheiHagimoto 0:0e0631af0305 1628
RyoheiHagimoto 0:0e0631af0305 1629 /** @brief Computes an optimal limited affine transformation with 4 degrees of freedom between
RyoheiHagimoto 0:0e0631af0305 1630 two 2D point sets.
RyoheiHagimoto 0:0e0631af0305 1631
RyoheiHagimoto 0:0e0631af0305 1632 @param from First input 2D point set.
RyoheiHagimoto 0:0e0631af0305 1633 @param to Second input 2D point set.
RyoheiHagimoto 0:0e0631af0305 1634 @param inliers Output vector indicating which points are inliers.
RyoheiHagimoto 0:0e0631af0305 1635 @param method Robust method used to compute tranformation. The following methods are possible:
RyoheiHagimoto 0:0e0631af0305 1636 - cv::RANSAC - RANSAC-based robust method
RyoheiHagimoto 0:0e0631af0305 1637 - cv::LMEDS - Least-Median robust method
RyoheiHagimoto 0:0e0631af0305 1638 RANSAC is the default method.
RyoheiHagimoto 0:0e0631af0305 1639 @param ransacReprojThreshold Maximum reprojection error in the RANSAC algorithm to consider
RyoheiHagimoto 0:0e0631af0305 1640 a point as an inlier. Applies only to RANSAC.
RyoheiHagimoto 0:0e0631af0305 1641 @param maxIters The maximum number of robust method iterations, 2000 is the maximum it can be.
RyoheiHagimoto 0:0e0631af0305 1642 @param confidence Confidence level, between 0 and 1, for the estimated transformation. Anything
RyoheiHagimoto 0:0e0631af0305 1643 between 0.95 and 0.99 is usually good enough. Values too close to 1 can slow down the estimation
RyoheiHagimoto 0:0e0631af0305 1644 significantly. Values lower than 0.8-0.9 can result in an incorrectly estimated transformation.
RyoheiHagimoto 0:0e0631af0305 1645 @param refineIters Maximum number of iterations of refining algorithm (Levenberg-Marquardt).
RyoheiHagimoto 0:0e0631af0305 1646 Passing 0 will disable refining, so the output matrix will be output of robust method.
RyoheiHagimoto 0:0e0631af0305 1647
RyoheiHagimoto 0:0e0631af0305 1648 @return Output 2D affine transformation (4 degrees of freedom) matrix \f$2 \times 3\f$ or
RyoheiHagimoto 0:0e0631af0305 1649 empty matrix if transformation could not be estimated.
RyoheiHagimoto 0:0e0631af0305 1650
RyoheiHagimoto 0:0e0631af0305 1651 The function estimates an optimal 2D affine transformation with 4 degrees of freedom limited to
RyoheiHagimoto 0:0e0631af0305 1652 combinations of translation, rotation, and uniform scaling. Uses the selected algorithm for robust
RyoheiHagimoto 0:0e0631af0305 1653 estimation.
RyoheiHagimoto 0:0e0631af0305 1654
RyoheiHagimoto 0:0e0631af0305 1655 The computed transformation is then refined further (using only inliers) with the
RyoheiHagimoto 0:0e0631af0305 1656 Levenberg-Marquardt method to reduce the re-projection error even more.
RyoheiHagimoto 0:0e0631af0305 1657
RyoheiHagimoto 0:0e0631af0305 1658 Estimated transformation matrix is:
RyoheiHagimoto 0:0e0631af0305 1659 \f[ \begin{bmatrix} \cos(\theta)s & -\sin(\theta)s & tx \\
RyoheiHagimoto 0:0e0631af0305 1660 \sin(\theta)s & \cos(\theta)s & ty
RyoheiHagimoto 0:0e0631af0305 1661 \end{bmatrix} \f]
RyoheiHagimoto 0:0e0631af0305 1662 Where \f$ \theta \f$ is the rotation angle, \f$ s \f$ the scaling factor and \f$ tx, ty \f$ are
RyoheiHagimoto 0:0e0631af0305 1663 translations in \f$ x, y \f$ axes respectively.
RyoheiHagimoto 0:0e0631af0305 1664
RyoheiHagimoto 0:0e0631af0305 1665 @note
RyoheiHagimoto 0:0e0631af0305 1666 The RANSAC method can handle practically any ratio of outliers but need a threshold to
RyoheiHagimoto 0:0e0631af0305 1667 distinguish inliers from outliers. The method LMeDS does not need any threshold but it works
RyoheiHagimoto 0:0e0631af0305 1668 correctly only when there are more than 50% of inliers.
RyoheiHagimoto 0:0e0631af0305 1669
RyoheiHagimoto 0:0e0631af0305 1670 @sa estimateAffine2D, getAffineTransform
RyoheiHagimoto 0:0e0631af0305 1671 */
RyoheiHagimoto 0:0e0631af0305 1672 CV_EXPORTS_W cv::Mat estimateAffinePartial2D(InputArray from, InputArray to, OutputArray inliers = noArray(),
RyoheiHagimoto 0:0e0631af0305 1673 int method = RANSAC, double ransacReprojThreshold = 3,
RyoheiHagimoto 0:0e0631af0305 1674 size_t maxIters = 2000, double confidence = 0.99,
RyoheiHagimoto 0:0e0631af0305 1675 size_t refineIters = 10);
RyoheiHagimoto 0:0e0631af0305 1676
RyoheiHagimoto 0:0e0631af0305 1677 /** @brief Decompose a homography matrix to rotation(s), translation(s) and plane normal(s).
RyoheiHagimoto 0:0e0631af0305 1678
RyoheiHagimoto 0:0e0631af0305 1679 @param H The input homography matrix between two images.
RyoheiHagimoto 0:0e0631af0305 1680 @param K The input intrinsic camera calibration matrix.
RyoheiHagimoto 0:0e0631af0305 1681 @param rotations Array of rotation matrices.
RyoheiHagimoto 0:0e0631af0305 1682 @param translations Array of translation matrices.
RyoheiHagimoto 0:0e0631af0305 1683 @param normals Array of plane normal matrices.
RyoheiHagimoto 0:0e0631af0305 1684
RyoheiHagimoto 0:0e0631af0305 1685 This function extracts relative camera motion between two views observing a planar object from the
RyoheiHagimoto 0:0e0631af0305 1686 homography H induced by the plane. The intrinsic camera matrix K must also be provided. The function
RyoheiHagimoto 0:0e0631af0305 1687 may return up to four mathematical solution sets. At least two of the solutions may further be
RyoheiHagimoto 0:0e0631af0305 1688 invalidated if point correspondences are available by applying positive depth constraint (all points
RyoheiHagimoto 0:0e0631af0305 1689 must be in front of the camera). The decomposition method is described in detail in @cite Malis .
RyoheiHagimoto 0:0e0631af0305 1690 */
RyoheiHagimoto 0:0e0631af0305 1691 CV_EXPORTS_W int decomposeHomographyMat(InputArray H,
RyoheiHagimoto 0:0e0631af0305 1692 InputArray K,
RyoheiHagimoto 0:0e0631af0305 1693 OutputArrayOfArrays rotations,
RyoheiHagimoto 0:0e0631af0305 1694 OutputArrayOfArrays translations,
RyoheiHagimoto 0:0e0631af0305 1695 OutputArrayOfArrays normals);
RyoheiHagimoto 0:0e0631af0305 1696
RyoheiHagimoto 0:0e0631af0305 1697 /** @brief The base class for stereo correspondence algorithms.
RyoheiHagimoto 0:0e0631af0305 1698 */
RyoheiHagimoto 0:0e0631af0305 1699 class CV_EXPORTS_W StereoMatcher : public Algorithm
RyoheiHagimoto 0:0e0631af0305 1700 {
RyoheiHagimoto 0:0e0631af0305 1701 public:
RyoheiHagimoto 0:0e0631af0305 1702 enum { DISP_SHIFT = 4,
RyoheiHagimoto 0:0e0631af0305 1703 DISP_SCALE = (1 << DISP_SHIFT)
RyoheiHagimoto 0:0e0631af0305 1704 };
RyoheiHagimoto 0:0e0631af0305 1705
RyoheiHagimoto 0:0e0631af0305 1706 /** @brief Computes disparity map for the specified stereo pair
RyoheiHagimoto 0:0e0631af0305 1707
RyoheiHagimoto 0:0e0631af0305 1708 @param left Left 8-bit single-channel image.
RyoheiHagimoto 0:0e0631af0305 1709 @param right Right image of the same size and the same type as the left one.
RyoheiHagimoto 0:0e0631af0305 1710 @param disparity Output disparity map. It has the same size as the input images. Some algorithms,
RyoheiHagimoto 0:0e0631af0305 1711 like StereoBM or StereoSGBM compute 16-bit fixed-point disparity map (where each disparity value
RyoheiHagimoto 0:0e0631af0305 1712 has 4 fractional bits), whereas other algorithms output 32-bit floating-point disparity map.
RyoheiHagimoto 0:0e0631af0305 1713 */
RyoheiHagimoto 0:0e0631af0305 1714 CV_WRAP virtual void compute( InputArray left, InputArray right,
RyoheiHagimoto 0:0e0631af0305 1715 OutputArray disparity ) = 0;
RyoheiHagimoto 0:0e0631af0305 1716
RyoheiHagimoto 0:0e0631af0305 1717 CV_WRAP virtual int getMinDisparity() const = 0;
RyoheiHagimoto 0:0e0631af0305 1718 CV_WRAP virtual void setMinDisparity(int minDisparity) = 0;
RyoheiHagimoto 0:0e0631af0305 1719
RyoheiHagimoto 0:0e0631af0305 1720 CV_WRAP virtual int getNumDisparities() const = 0;
RyoheiHagimoto 0:0e0631af0305 1721 CV_WRAP virtual void setNumDisparities(int numDisparities) = 0;
RyoheiHagimoto 0:0e0631af0305 1722
RyoheiHagimoto 0:0e0631af0305 1723 CV_WRAP virtual int getBlockSize() const = 0;
RyoheiHagimoto 0:0e0631af0305 1724 CV_WRAP virtual void setBlockSize(int blockSize) = 0;
RyoheiHagimoto 0:0e0631af0305 1725
RyoheiHagimoto 0:0e0631af0305 1726 CV_WRAP virtual int getSpeckleWindowSize() const = 0;
RyoheiHagimoto 0:0e0631af0305 1727 CV_WRAP virtual void setSpeckleWindowSize(int speckleWindowSize) = 0;
RyoheiHagimoto 0:0e0631af0305 1728
RyoheiHagimoto 0:0e0631af0305 1729 CV_WRAP virtual int getSpeckleRange() const = 0;
RyoheiHagimoto 0:0e0631af0305 1730 CV_WRAP virtual void setSpeckleRange(int speckleRange) = 0;
RyoheiHagimoto 0:0e0631af0305 1731
RyoheiHagimoto 0:0e0631af0305 1732 CV_WRAP virtual int getDisp12MaxDiff() const = 0;
RyoheiHagimoto 0:0e0631af0305 1733 CV_WRAP virtual void setDisp12MaxDiff(int disp12MaxDiff) = 0;
RyoheiHagimoto 0:0e0631af0305 1734 };
RyoheiHagimoto 0:0e0631af0305 1735
RyoheiHagimoto 0:0e0631af0305 1736
RyoheiHagimoto 0:0e0631af0305 1737 /** @brief Class for computing stereo correspondence using the block matching algorithm, introduced and
RyoheiHagimoto 0:0e0631af0305 1738 contributed to OpenCV by K. Konolige.
RyoheiHagimoto 0:0e0631af0305 1739 */
RyoheiHagimoto 0:0e0631af0305 1740 class CV_EXPORTS_W StereoBM : public StereoMatcher
RyoheiHagimoto 0:0e0631af0305 1741 {
RyoheiHagimoto 0:0e0631af0305 1742 public:
RyoheiHagimoto 0:0e0631af0305 1743 enum { PREFILTER_NORMALIZED_RESPONSE = 0,
RyoheiHagimoto 0:0e0631af0305 1744 PREFILTER_XSOBEL = 1
RyoheiHagimoto 0:0e0631af0305 1745 };
RyoheiHagimoto 0:0e0631af0305 1746
RyoheiHagimoto 0:0e0631af0305 1747 CV_WRAP virtual int getPreFilterType() const = 0;
RyoheiHagimoto 0:0e0631af0305 1748 CV_WRAP virtual void setPreFilterType(int preFilterType) = 0;
RyoheiHagimoto 0:0e0631af0305 1749
RyoheiHagimoto 0:0e0631af0305 1750 CV_WRAP virtual int getPreFilterSize() const = 0;
RyoheiHagimoto 0:0e0631af0305 1751 CV_WRAP virtual void setPreFilterSize(int preFilterSize) = 0;
RyoheiHagimoto 0:0e0631af0305 1752
RyoheiHagimoto 0:0e0631af0305 1753 CV_WRAP virtual int getPreFilterCap() const = 0;
RyoheiHagimoto 0:0e0631af0305 1754 CV_WRAP virtual void setPreFilterCap(int preFilterCap) = 0;
RyoheiHagimoto 0:0e0631af0305 1755
RyoheiHagimoto 0:0e0631af0305 1756 CV_WRAP virtual int getTextureThreshold() const = 0;
RyoheiHagimoto 0:0e0631af0305 1757 CV_WRAP virtual void setTextureThreshold(int textureThreshold) = 0;
RyoheiHagimoto 0:0e0631af0305 1758
RyoheiHagimoto 0:0e0631af0305 1759 CV_WRAP virtual int getUniquenessRatio() const = 0;
RyoheiHagimoto 0:0e0631af0305 1760 CV_WRAP virtual void setUniquenessRatio(int uniquenessRatio) = 0;
RyoheiHagimoto 0:0e0631af0305 1761
RyoheiHagimoto 0:0e0631af0305 1762 CV_WRAP virtual int getSmallerBlockSize() const = 0;
RyoheiHagimoto 0:0e0631af0305 1763 CV_WRAP virtual void setSmallerBlockSize(int blockSize) = 0;
RyoheiHagimoto 0:0e0631af0305 1764
RyoheiHagimoto 0:0e0631af0305 1765 CV_WRAP virtual Rect getROI1() const = 0;
RyoheiHagimoto 0:0e0631af0305 1766 CV_WRAP virtual void setROI1(Rect roi1) = 0;
RyoheiHagimoto 0:0e0631af0305 1767
RyoheiHagimoto 0:0e0631af0305 1768 CV_WRAP virtual Rect getROI2() const = 0;
RyoheiHagimoto 0:0e0631af0305 1769 CV_WRAP virtual void setROI2(Rect roi2) = 0;
RyoheiHagimoto 0:0e0631af0305 1770
RyoheiHagimoto 0:0e0631af0305 1771 /** @brief Creates StereoBM object
RyoheiHagimoto 0:0e0631af0305 1772
RyoheiHagimoto 0:0e0631af0305 1773 @param numDisparities the disparity search range. For each pixel algorithm will find the best
RyoheiHagimoto 0:0e0631af0305 1774 disparity from 0 (default minimum disparity) to numDisparities. The search range can then be
RyoheiHagimoto 0:0e0631af0305 1775 shifted by changing the minimum disparity.
RyoheiHagimoto 0:0e0631af0305 1776 @param blockSize the linear size of the blocks compared by the algorithm. The size should be odd
RyoheiHagimoto 0:0e0631af0305 1777 (as the block is centered at the current pixel). Larger block size implies smoother, though less
RyoheiHagimoto 0:0e0631af0305 1778 accurate disparity map. Smaller block size gives more detailed disparity map, but there is higher
RyoheiHagimoto 0:0e0631af0305 1779 chance for algorithm to find a wrong correspondence.
RyoheiHagimoto 0:0e0631af0305 1780
RyoheiHagimoto 0:0e0631af0305 1781 The function create StereoBM object. You can then call StereoBM::compute() to compute disparity for
RyoheiHagimoto 0:0e0631af0305 1782 a specific stereo pair.
RyoheiHagimoto 0:0e0631af0305 1783 */
RyoheiHagimoto 0:0e0631af0305 1784 CV_WRAP static Ptr<StereoBM> create(int numDisparities = 0, int blockSize = 21);
RyoheiHagimoto 0:0e0631af0305 1785 };
RyoheiHagimoto 0:0e0631af0305 1786
RyoheiHagimoto 0:0e0631af0305 1787 /** @brief The class implements the modified H. Hirschmuller algorithm @cite HH08 that differs from the original
RyoheiHagimoto 0:0e0631af0305 1788 one as follows:
RyoheiHagimoto 0:0e0631af0305 1789
RyoheiHagimoto 0:0e0631af0305 1790 - By default, the algorithm is single-pass, which means that you consider only 5 directions
RyoheiHagimoto 0:0e0631af0305 1791 instead of 8. Set mode=StereoSGBM::MODE_HH in createStereoSGBM to run the full variant of the
RyoheiHagimoto 0:0e0631af0305 1792 algorithm but beware that it may consume a lot of memory.
RyoheiHagimoto 0:0e0631af0305 1793 - The algorithm matches blocks, not individual pixels. Though, setting blockSize=1 reduces the
RyoheiHagimoto 0:0e0631af0305 1794 blocks to single pixels.
RyoheiHagimoto 0:0e0631af0305 1795 - Mutual information cost function is not implemented. Instead, a simpler Birchfield-Tomasi
RyoheiHagimoto 0:0e0631af0305 1796 sub-pixel metric from @cite BT98 is used. Though, the color images are supported as well.
RyoheiHagimoto 0:0e0631af0305 1797 - Some pre- and post- processing steps from K. Konolige algorithm StereoBM are included, for
RyoheiHagimoto 0:0e0631af0305 1798 example: pre-filtering (StereoBM::PREFILTER_XSOBEL type) and post-filtering (uniqueness
RyoheiHagimoto 0:0e0631af0305 1799 check, quadratic interpolation and speckle filtering).
RyoheiHagimoto 0:0e0631af0305 1800
RyoheiHagimoto 0:0e0631af0305 1801 @note
RyoheiHagimoto 0:0e0631af0305 1802 - (Python) An example illustrating the use of the StereoSGBM matching algorithm can be found
RyoheiHagimoto 0:0e0631af0305 1803 at opencv_source_code/samples/python/stereo_match.py
RyoheiHagimoto 0:0e0631af0305 1804 */
RyoheiHagimoto 0:0e0631af0305 1805 class CV_EXPORTS_W StereoSGBM : public StereoMatcher
RyoheiHagimoto 0:0e0631af0305 1806 {
RyoheiHagimoto 0:0e0631af0305 1807 public:
RyoheiHagimoto 0:0e0631af0305 1808 enum
RyoheiHagimoto 0:0e0631af0305 1809 {
RyoheiHagimoto 0:0e0631af0305 1810 MODE_SGBM = 0,
RyoheiHagimoto 0:0e0631af0305 1811 MODE_HH = 1,
RyoheiHagimoto 0:0e0631af0305 1812 MODE_SGBM_3WAY = 2
RyoheiHagimoto 0:0e0631af0305 1813 };
RyoheiHagimoto 0:0e0631af0305 1814
RyoheiHagimoto 0:0e0631af0305 1815 CV_WRAP virtual int getPreFilterCap() const = 0;
RyoheiHagimoto 0:0e0631af0305 1816 CV_WRAP virtual void setPreFilterCap(int preFilterCap) = 0;
RyoheiHagimoto 0:0e0631af0305 1817
RyoheiHagimoto 0:0e0631af0305 1818 CV_WRAP virtual int getUniquenessRatio() const = 0;
RyoheiHagimoto 0:0e0631af0305 1819 CV_WRAP virtual void setUniquenessRatio(int uniquenessRatio) = 0;
RyoheiHagimoto 0:0e0631af0305 1820
RyoheiHagimoto 0:0e0631af0305 1821 CV_WRAP virtual int getP1() const = 0;
RyoheiHagimoto 0:0e0631af0305 1822 CV_WRAP virtual void setP1(int P1) = 0;
RyoheiHagimoto 0:0e0631af0305 1823
RyoheiHagimoto 0:0e0631af0305 1824 CV_WRAP virtual int getP2() const = 0;
RyoheiHagimoto 0:0e0631af0305 1825 CV_WRAP virtual void setP2(int P2) = 0;
RyoheiHagimoto 0:0e0631af0305 1826
RyoheiHagimoto 0:0e0631af0305 1827 CV_WRAP virtual int getMode() const = 0;
RyoheiHagimoto 0:0e0631af0305 1828 CV_WRAP virtual void setMode(int mode) = 0;
RyoheiHagimoto 0:0e0631af0305 1829
RyoheiHagimoto 0:0e0631af0305 1830 /** @brief Creates StereoSGBM object
RyoheiHagimoto 0:0e0631af0305 1831
RyoheiHagimoto 0:0e0631af0305 1832 @param minDisparity Minimum possible disparity value. Normally, it is zero but sometimes
RyoheiHagimoto 0:0e0631af0305 1833 rectification algorithms can shift images, so this parameter needs to be adjusted accordingly.
RyoheiHagimoto 0:0e0631af0305 1834 @param numDisparities Maximum disparity minus minimum disparity. The value is always greater than
RyoheiHagimoto 0:0e0631af0305 1835 zero. In the current implementation, this parameter must be divisible by 16.
RyoheiHagimoto 0:0e0631af0305 1836 @param blockSize Matched block size. It must be an odd number \>=1 . Normally, it should be
RyoheiHagimoto 0:0e0631af0305 1837 somewhere in the 3..11 range.
RyoheiHagimoto 0:0e0631af0305 1838 @param P1 The first parameter controlling the disparity smoothness. See below.
RyoheiHagimoto 0:0e0631af0305 1839 @param P2 The second parameter controlling the disparity smoothness. The larger the values are,
RyoheiHagimoto 0:0e0631af0305 1840 the smoother the disparity is. P1 is the penalty on the disparity change by plus or minus 1
RyoheiHagimoto 0:0e0631af0305 1841 between neighbor pixels. P2 is the penalty on the disparity change by more than 1 between neighbor
RyoheiHagimoto 0:0e0631af0305 1842 pixels. The algorithm requires P2 \> P1 . See stereo_match.cpp sample where some reasonably good
RyoheiHagimoto 0:0e0631af0305 1843 P1 and P2 values are shown (like 8\*number_of_image_channels\*SADWindowSize\*SADWindowSize and
RyoheiHagimoto 0:0e0631af0305 1844 32\*number_of_image_channels\*SADWindowSize\*SADWindowSize , respectively).
RyoheiHagimoto 0:0e0631af0305 1845 @param disp12MaxDiff Maximum allowed difference (in integer pixel units) in the left-right
RyoheiHagimoto 0:0e0631af0305 1846 disparity check. Set it to a non-positive value to disable the check.
RyoheiHagimoto 0:0e0631af0305 1847 @param preFilterCap Truncation value for the prefiltered image pixels. The algorithm first
RyoheiHagimoto 0:0e0631af0305 1848 computes x-derivative at each pixel and clips its value by [-preFilterCap, preFilterCap] interval.
RyoheiHagimoto 0:0e0631af0305 1849 The result values are passed to the Birchfield-Tomasi pixel cost function.
RyoheiHagimoto 0:0e0631af0305 1850 @param uniquenessRatio Margin in percentage by which the best (minimum) computed cost function
RyoheiHagimoto 0:0e0631af0305 1851 value should "win" the second best value to consider the found match correct. Normally, a value
RyoheiHagimoto 0:0e0631af0305 1852 within the 5-15 range is good enough.
RyoheiHagimoto 0:0e0631af0305 1853 @param speckleWindowSize Maximum size of smooth disparity regions to consider their noise speckles
RyoheiHagimoto 0:0e0631af0305 1854 and invalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in the
RyoheiHagimoto 0:0e0631af0305 1855 50-200 range.
RyoheiHagimoto 0:0e0631af0305 1856 @param speckleRange Maximum disparity variation within each connected component. If you do speckle
RyoheiHagimoto 0:0e0631af0305 1857 filtering, set the parameter to a positive value, it will be implicitly multiplied by 16.
RyoheiHagimoto 0:0e0631af0305 1858 Normally, 1 or 2 is good enough.
RyoheiHagimoto 0:0e0631af0305 1859 @param mode Set it to StereoSGBM::MODE_HH to run the full-scale two-pass dynamic programming
RyoheiHagimoto 0:0e0631af0305 1860 algorithm. It will consume O(W\*H\*numDisparities) bytes, which is large for 640x480 stereo and
RyoheiHagimoto 0:0e0631af0305 1861 huge for HD-size pictures. By default, it is set to false .
RyoheiHagimoto 0:0e0631af0305 1862
RyoheiHagimoto 0:0e0631af0305 1863 The first constructor initializes StereoSGBM with all the default parameters. So, you only have to
RyoheiHagimoto 0:0e0631af0305 1864 set StereoSGBM::numDisparities at minimum. The second constructor enables you to set each parameter
RyoheiHagimoto 0:0e0631af0305 1865 to a custom value.
RyoheiHagimoto 0:0e0631af0305 1866 */
RyoheiHagimoto 0:0e0631af0305 1867 CV_WRAP static Ptr<StereoSGBM> create(int minDisparity, int numDisparities, int blockSize,
RyoheiHagimoto 0:0e0631af0305 1868 int P1 = 0, int P2 = 0, int disp12MaxDiff = 0,
RyoheiHagimoto 0:0e0631af0305 1869 int preFilterCap = 0, int uniquenessRatio = 0,
RyoheiHagimoto 0:0e0631af0305 1870 int speckleWindowSize = 0, int speckleRange = 0,
RyoheiHagimoto 0:0e0631af0305 1871 int mode = StereoSGBM::MODE_SGBM);
RyoheiHagimoto 0:0e0631af0305 1872 };
RyoheiHagimoto 0:0e0631af0305 1873
RyoheiHagimoto 0:0e0631af0305 1874 //! @} calib3d
RyoheiHagimoto 0:0e0631af0305 1875
RyoheiHagimoto 0:0e0631af0305 1876 /** @brief The methods in this namespace use a so-called fisheye camera model.
RyoheiHagimoto 0:0e0631af0305 1877 @ingroup calib3d_fisheye
RyoheiHagimoto 0:0e0631af0305 1878 */
RyoheiHagimoto 0:0e0631af0305 1879 namespace fisheye
RyoheiHagimoto 0:0e0631af0305 1880 {
RyoheiHagimoto 0:0e0631af0305 1881 //! @addtogroup calib3d_fisheye
RyoheiHagimoto 0:0e0631af0305 1882 //! @{
RyoheiHagimoto 0:0e0631af0305 1883
RyoheiHagimoto 0:0e0631af0305 1884 enum{
RyoheiHagimoto 0:0e0631af0305 1885 CALIB_USE_INTRINSIC_GUESS = 1 << 0,
RyoheiHagimoto 0:0e0631af0305 1886 CALIB_RECOMPUTE_EXTRINSIC = 1 << 1,
RyoheiHagimoto 0:0e0631af0305 1887 CALIB_CHECK_COND = 1 << 2,
RyoheiHagimoto 0:0e0631af0305 1888 CALIB_FIX_SKEW = 1 << 3,
RyoheiHagimoto 0:0e0631af0305 1889 CALIB_FIX_K1 = 1 << 4,
RyoheiHagimoto 0:0e0631af0305 1890 CALIB_FIX_K2 = 1 << 5,
RyoheiHagimoto 0:0e0631af0305 1891 CALIB_FIX_K3 = 1 << 6,
RyoheiHagimoto 0:0e0631af0305 1892 CALIB_FIX_K4 = 1 << 7,
RyoheiHagimoto 0:0e0631af0305 1893 CALIB_FIX_INTRINSIC = 1 << 8,
RyoheiHagimoto 0:0e0631af0305 1894 CALIB_FIX_PRINCIPAL_POINT = 1 << 9
RyoheiHagimoto 0:0e0631af0305 1895 };
RyoheiHagimoto 0:0e0631af0305 1896
RyoheiHagimoto 0:0e0631af0305 1897 /** @brief Projects points using fisheye model
RyoheiHagimoto 0:0e0631af0305 1898
RyoheiHagimoto 0:0e0631af0305 1899 @param objectPoints Array of object points, 1xN/Nx1 3-channel (or vector\<Point3f\> ), where N is
RyoheiHagimoto 0:0e0631af0305 1900 the number of points in the view.
RyoheiHagimoto 0:0e0631af0305 1901 @param imagePoints Output array of image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, or
RyoheiHagimoto 0:0e0631af0305 1902 vector\<Point2f\>.
RyoheiHagimoto 0:0e0631af0305 1903 @param affine
RyoheiHagimoto 0:0e0631af0305 1904 @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$.
RyoheiHagimoto 0:0e0631af0305 1905 @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$.
RyoheiHagimoto 0:0e0631af0305 1906 @param alpha The skew coefficient.
RyoheiHagimoto 0:0e0631af0305 1907 @param jacobian Optional output 2Nx15 jacobian matrix of derivatives of image points with respect
RyoheiHagimoto 0:0e0631af0305 1908 to components of the focal lengths, coordinates of the principal point, distortion coefficients,
RyoheiHagimoto 0:0e0631af0305 1909 rotation vector, translation vector, and the skew. In the old interface different components of
RyoheiHagimoto 0:0e0631af0305 1910 the jacobian are returned via different output parameters.
RyoheiHagimoto 0:0e0631af0305 1911
RyoheiHagimoto 0:0e0631af0305 1912 The function computes projections of 3D points to the image plane given intrinsic and extrinsic
RyoheiHagimoto 0:0e0631af0305 1913 camera parameters. Optionally, the function computes Jacobians - matrices of partial derivatives of
RyoheiHagimoto 0:0e0631af0305 1914 image points coordinates (as functions of all the input parameters) with respect to the particular
RyoheiHagimoto 0:0e0631af0305 1915 parameters, intrinsic and/or extrinsic.
RyoheiHagimoto 0:0e0631af0305 1916 */
RyoheiHagimoto 0:0e0631af0305 1917 CV_EXPORTS void projectPoints(InputArray objectPoints, OutputArray imagePoints, const Affine3d& affine,
RyoheiHagimoto 0:0e0631af0305 1918 InputArray K, InputArray D, double alpha = 0, OutputArray jacobian = noArray());
RyoheiHagimoto 0:0e0631af0305 1919
RyoheiHagimoto 0:0e0631af0305 1920 /** @overload */
RyoheiHagimoto 0:0e0631af0305 1921 CV_EXPORTS_W void projectPoints(InputArray objectPoints, OutputArray imagePoints, InputArray rvec, InputArray tvec,
RyoheiHagimoto 0:0e0631af0305 1922 InputArray K, InputArray D, double alpha = 0, OutputArray jacobian = noArray());
RyoheiHagimoto 0:0e0631af0305 1923
RyoheiHagimoto 0:0e0631af0305 1924 /** @brief Distorts 2D points using fisheye model.
RyoheiHagimoto 0:0e0631af0305 1925
RyoheiHagimoto 0:0e0631af0305 1926 @param undistorted Array of object points, 1xN/Nx1 2-channel (or vector\<Point2f\> ), where N is
RyoheiHagimoto 0:0e0631af0305 1927 the number of points in the view.
RyoheiHagimoto 0:0e0631af0305 1928 @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$.
RyoheiHagimoto 0:0e0631af0305 1929 @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$.
RyoheiHagimoto 0:0e0631af0305 1930 @param alpha The skew coefficient.
RyoheiHagimoto 0:0e0631af0305 1931 @param distorted Output array of image points, 1xN/Nx1 2-channel, or vector\<Point2f\> .
RyoheiHagimoto 0:0e0631af0305 1932
RyoheiHagimoto 0:0e0631af0305 1933 Note that the function assumes the camera matrix of the undistorted points to be indentity.
RyoheiHagimoto 0:0e0631af0305 1934 This means if you want to transform back points undistorted with undistortPoints() you have to
RyoheiHagimoto 0:0e0631af0305 1935 multiply them with \f$P^{-1}\f$.
RyoheiHagimoto 0:0e0631af0305 1936 */
RyoheiHagimoto 0:0e0631af0305 1937 CV_EXPORTS_W void distortPoints(InputArray undistorted, OutputArray distorted, InputArray K, InputArray D, double alpha = 0);
RyoheiHagimoto 0:0e0631af0305 1938
RyoheiHagimoto 0:0e0631af0305 1939 /** @brief Undistorts 2D points using fisheye model
RyoheiHagimoto 0:0e0631af0305 1940
RyoheiHagimoto 0:0e0631af0305 1941 @param distorted Array of object points, 1xN/Nx1 2-channel (or vector\<Point2f\> ), where N is the
RyoheiHagimoto 0:0e0631af0305 1942 number of points in the view.
RyoheiHagimoto 0:0e0631af0305 1943 @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$.
RyoheiHagimoto 0:0e0631af0305 1944 @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$.
RyoheiHagimoto 0:0e0631af0305 1945 @param R Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3
RyoheiHagimoto 0:0e0631af0305 1946 1-channel or 1x1 3-channel
RyoheiHagimoto 0:0e0631af0305 1947 @param P New camera matrix (3x3) or new projection matrix (3x4)
RyoheiHagimoto 0:0e0631af0305 1948 @param undistorted Output array of image points, 1xN/Nx1 2-channel, or vector\<Point2f\> .
RyoheiHagimoto 0:0e0631af0305 1949 */
RyoheiHagimoto 0:0e0631af0305 1950 CV_EXPORTS_W void undistortPoints(InputArray distorted, OutputArray undistorted,
RyoheiHagimoto 0:0e0631af0305 1951 InputArray K, InputArray D, InputArray R = noArray(), InputArray P = noArray());
RyoheiHagimoto 0:0e0631af0305 1952
RyoheiHagimoto 0:0e0631af0305 1953 /** @brief Computes undistortion and rectification maps for image transform by cv::remap(). If D is empty zero
RyoheiHagimoto 0:0e0631af0305 1954 distortion is used, if R or P is empty identity matrixes are used.
RyoheiHagimoto 0:0e0631af0305 1955
RyoheiHagimoto 0:0e0631af0305 1956 @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$.
RyoheiHagimoto 0:0e0631af0305 1957 @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$.
RyoheiHagimoto 0:0e0631af0305 1958 @param R Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3
RyoheiHagimoto 0:0e0631af0305 1959 1-channel or 1x1 3-channel
RyoheiHagimoto 0:0e0631af0305 1960 @param P New camera matrix (3x3) or new projection matrix (3x4)
RyoheiHagimoto 0:0e0631af0305 1961 @param size Undistorted image size.
RyoheiHagimoto 0:0e0631af0305 1962 @param m1type Type of the first output map that can be CV_32FC1 or CV_16SC2 . See convertMaps()
RyoheiHagimoto 0:0e0631af0305 1963 for details.
RyoheiHagimoto 0:0e0631af0305 1964 @param map1 The first output map.
RyoheiHagimoto 0:0e0631af0305 1965 @param map2 The second output map.
RyoheiHagimoto 0:0e0631af0305 1966 */
RyoheiHagimoto 0:0e0631af0305 1967 CV_EXPORTS_W void initUndistortRectifyMap(InputArray K, InputArray D, InputArray R, InputArray P,
RyoheiHagimoto 0:0e0631af0305 1968 const cv::Size& size, int m1type, OutputArray map1, OutputArray map2);
RyoheiHagimoto 0:0e0631af0305 1969
RyoheiHagimoto 0:0e0631af0305 1970 /** @brief Transforms an image to compensate for fisheye lens distortion.
RyoheiHagimoto 0:0e0631af0305 1971
RyoheiHagimoto 0:0e0631af0305 1972 @param distorted image with fisheye lens distortion.
RyoheiHagimoto 0:0e0631af0305 1973 @param undistorted Output image with compensated fisheye lens distortion.
RyoheiHagimoto 0:0e0631af0305 1974 @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$.
RyoheiHagimoto 0:0e0631af0305 1975 @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$.
RyoheiHagimoto 0:0e0631af0305 1976 @param Knew Camera matrix of the distorted image. By default, it is the identity matrix but you
RyoheiHagimoto 0:0e0631af0305 1977 may additionally scale and shift the result by using a different matrix.
RyoheiHagimoto 0:0e0631af0305 1978 @param new_size
RyoheiHagimoto 0:0e0631af0305 1979
RyoheiHagimoto 0:0e0631af0305 1980 The function transforms an image to compensate radial and tangential lens distortion.
RyoheiHagimoto 0:0e0631af0305 1981
RyoheiHagimoto 0:0e0631af0305 1982 The function is simply a combination of fisheye::initUndistortRectifyMap (with unity R ) and remap
RyoheiHagimoto 0:0e0631af0305 1983 (with bilinear interpolation). See the former function for details of the transformation being
RyoheiHagimoto 0:0e0631af0305 1984 performed.
RyoheiHagimoto 0:0e0631af0305 1985
RyoheiHagimoto 0:0e0631af0305 1986 See below the results of undistortImage.
RyoheiHagimoto 0:0e0631af0305 1987 - a\) result of undistort of perspective camera model (all possible coefficients (k_1, k_2, k_3,
RyoheiHagimoto 0:0e0631af0305 1988 k_4, k_5, k_6) of distortion were optimized under calibration)
RyoheiHagimoto 0:0e0631af0305 1989 - b\) result of fisheye::undistortImage of fisheye camera model (all possible coefficients (k_1, k_2,
RyoheiHagimoto 0:0e0631af0305 1990 k_3, k_4) of fisheye distortion were optimized under calibration)
RyoheiHagimoto 0:0e0631af0305 1991 - c\) original image was captured with fisheye lens
RyoheiHagimoto 0:0e0631af0305 1992
RyoheiHagimoto 0:0e0631af0305 1993 Pictures a) and b) almost the same. But if we consider points of image located far from the center
RyoheiHagimoto 0:0e0631af0305 1994 of image, we can notice that on image a) these points are distorted.
RyoheiHagimoto 0:0e0631af0305 1995
RyoheiHagimoto 0:0e0631af0305 1996 ![image](pics/fisheye_undistorted.jpg)
RyoheiHagimoto 0:0e0631af0305 1997 */
RyoheiHagimoto 0:0e0631af0305 1998 CV_EXPORTS_W void undistortImage(InputArray distorted, OutputArray undistorted,
RyoheiHagimoto 0:0e0631af0305 1999 InputArray K, InputArray D, InputArray Knew = cv::noArray(), const Size& new_size = Size());
RyoheiHagimoto 0:0e0631af0305 2000
RyoheiHagimoto 0:0e0631af0305 2001 /** @brief Estimates new camera matrix for undistortion or rectification.
RyoheiHagimoto 0:0e0631af0305 2002
RyoheiHagimoto 0:0e0631af0305 2003 @param K Camera matrix \f$K = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1}\f$.
RyoheiHagimoto 0:0e0631af0305 2004 @param image_size
RyoheiHagimoto 0:0e0631af0305 2005 @param D Input vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$.
RyoheiHagimoto 0:0e0631af0305 2006 @param R Rectification transformation in the object space: 3x3 1-channel, or vector: 3x1/1x3
RyoheiHagimoto 0:0e0631af0305 2007 1-channel or 1x1 3-channel
RyoheiHagimoto 0:0e0631af0305 2008 @param P New camera matrix (3x3) or new projection matrix (3x4)
RyoheiHagimoto 0:0e0631af0305 2009 @param balance Sets the new focal length in range between the min focal length and the max focal
RyoheiHagimoto 0:0e0631af0305 2010 length. Balance is in range of [0, 1].
RyoheiHagimoto 0:0e0631af0305 2011 @param new_size
RyoheiHagimoto 0:0e0631af0305 2012 @param fov_scale Divisor for new focal length.
RyoheiHagimoto 0:0e0631af0305 2013 */
RyoheiHagimoto 0:0e0631af0305 2014 CV_EXPORTS_W void estimateNewCameraMatrixForUndistortRectify(InputArray K, InputArray D, const Size &image_size, InputArray R,
RyoheiHagimoto 0:0e0631af0305 2015 OutputArray P, double balance = 0.0, const Size& new_size = Size(), double fov_scale = 1.0);
RyoheiHagimoto 0:0e0631af0305 2016
RyoheiHagimoto 0:0e0631af0305 2017 /** @brief Performs camera calibaration
RyoheiHagimoto 0:0e0631af0305 2018
RyoheiHagimoto 0:0e0631af0305 2019 @param objectPoints vector of vectors of calibration pattern points in the calibration pattern
RyoheiHagimoto 0:0e0631af0305 2020 coordinate space.
RyoheiHagimoto 0:0e0631af0305 2021 @param imagePoints vector of vectors of the projections of calibration pattern points.
RyoheiHagimoto 0:0e0631af0305 2022 imagePoints.size() and objectPoints.size() and imagePoints[i].size() must be equal to
RyoheiHagimoto 0:0e0631af0305 2023 objectPoints[i].size() for each i.
RyoheiHagimoto 0:0e0631af0305 2024 @param image_size Size of the image used only to initialize the intrinsic camera matrix.
RyoheiHagimoto 0:0e0631af0305 2025 @param K Output 3x3 floating-point camera matrix
RyoheiHagimoto 0:0e0631af0305 2026 \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$ . If
RyoheiHagimoto 0:0e0631af0305 2027 fisheye::CALIB_USE_INTRINSIC_GUESS/ is specified, some or all of fx, fy, cx, cy must be
RyoheiHagimoto 0:0e0631af0305 2028 initialized before calling the function.
RyoheiHagimoto 0:0e0631af0305 2029 @param D Output vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$.
RyoheiHagimoto 0:0e0631af0305 2030 @param rvecs Output vector of rotation vectors (see Rodrigues ) estimated for each pattern view.
RyoheiHagimoto 0:0e0631af0305 2031 That is, each k-th rotation vector together with the corresponding k-th translation vector (see
RyoheiHagimoto 0:0e0631af0305 2032 the next output parameter description) brings the calibration pattern from the model coordinate
RyoheiHagimoto 0:0e0631af0305 2033 space (in which object points are specified) to the world coordinate space, that is, a real
RyoheiHagimoto 0:0e0631af0305 2034 position of the calibration pattern in the k-th pattern view (k=0.. *M* -1).
RyoheiHagimoto 0:0e0631af0305 2035 @param tvecs Output vector of translation vectors estimated for each pattern view.
RyoheiHagimoto 0:0e0631af0305 2036 @param flags Different flags that may be zero or a combination of the following values:
RyoheiHagimoto 0:0e0631af0305 2037 - **fisheye::CALIB_USE_INTRINSIC_GUESS** cameraMatrix contains valid initial values of
RyoheiHagimoto 0:0e0631af0305 2038 fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image
RyoheiHagimoto 0:0e0631af0305 2039 center ( imageSize is used), and focal distances are computed in a least-squares fashion.
RyoheiHagimoto 0:0e0631af0305 2040 - **fisheye::CALIB_RECOMPUTE_EXTRINSIC** Extrinsic will be recomputed after each iteration
RyoheiHagimoto 0:0e0631af0305 2041 of intrinsic optimization.
RyoheiHagimoto 0:0e0631af0305 2042 - **fisheye::CALIB_CHECK_COND** The functions will check validity of condition number.
RyoheiHagimoto 0:0e0631af0305 2043 - **fisheye::CALIB_FIX_SKEW** Skew coefficient (alpha) is set to zero and stay zero.
RyoheiHagimoto 0:0e0631af0305 2044 - **fisheye::CALIB_FIX_K1..fisheye::CALIB_FIX_K4** Selected distortion coefficients
RyoheiHagimoto 0:0e0631af0305 2045 are set to zeros and stay zero.
RyoheiHagimoto 0:0e0631af0305 2046 - **fisheye::CALIB_FIX_PRINCIPAL_POINT** The principal point is not changed during the global
RyoheiHagimoto 0:0e0631af0305 2047 optimization. It stays at the center or at a different location specified when CALIB_USE_INTRINSIC_GUESS is set too.
RyoheiHagimoto 0:0e0631af0305 2048 @param criteria Termination criteria for the iterative optimization algorithm.
RyoheiHagimoto 0:0e0631af0305 2049 */
RyoheiHagimoto 0:0e0631af0305 2050 CV_EXPORTS_W double calibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints, const Size& image_size,
RyoheiHagimoto 0:0e0631af0305 2051 InputOutputArray K, InputOutputArray D, OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs, int flags = 0,
RyoheiHagimoto 0:0e0631af0305 2052 TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 100, DBL_EPSILON));
RyoheiHagimoto 0:0e0631af0305 2053
RyoheiHagimoto 0:0e0631af0305 2054 /** @brief Stereo rectification for fisheye camera model
RyoheiHagimoto 0:0e0631af0305 2055
RyoheiHagimoto 0:0e0631af0305 2056 @param K1 First camera matrix.
RyoheiHagimoto 0:0e0631af0305 2057 @param D1 First camera distortion parameters.
RyoheiHagimoto 0:0e0631af0305 2058 @param K2 Second camera matrix.
RyoheiHagimoto 0:0e0631af0305 2059 @param D2 Second camera distortion parameters.
RyoheiHagimoto 0:0e0631af0305 2060 @param imageSize Size of the image used for stereo calibration.
RyoheiHagimoto 0:0e0631af0305 2061 @param R Rotation matrix between the coordinate systems of the first and the second
RyoheiHagimoto 0:0e0631af0305 2062 cameras.
RyoheiHagimoto 0:0e0631af0305 2063 @param tvec Translation vector between coordinate systems of the cameras.
RyoheiHagimoto 0:0e0631af0305 2064 @param R1 Output 3x3 rectification transform (rotation matrix) for the first camera.
RyoheiHagimoto 0:0e0631af0305 2065 @param R2 Output 3x3 rectification transform (rotation matrix) for the second camera.
RyoheiHagimoto 0:0e0631af0305 2066 @param P1 Output 3x4 projection matrix in the new (rectified) coordinate systems for the first
RyoheiHagimoto 0:0e0631af0305 2067 camera.
RyoheiHagimoto 0:0e0631af0305 2068 @param P2 Output 3x4 projection matrix in the new (rectified) coordinate systems for the second
RyoheiHagimoto 0:0e0631af0305 2069 camera.
RyoheiHagimoto 0:0e0631af0305 2070 @param Q Output \f$4 \times 4\f$ disparity-to-depth mapping matrix (see reprojectImageTo3D ).
RyoheiHagimoto 0:0e0631af0305 2071 @param flags Operation flags that may be zero or CV_CALIB_ZERO_DISPARITY . If the flag is set,
RyoheiHagimoto 0:0e0631af0305 2072 the function makes the principal points of each camera have the same pixel coordinates in the
RyoheiHagimoto 0:0e0631af0305 2073 rectified views. And if the flag is not set, the function may still shift the images in the
RyoheiHagimoto 0:0e0631af0305 2074 horizontal or vertical direction (depending on the orientation of epipolar lines) to maximize the
RyoheiHagimoto 0:0e0631af0305 2075 useful image area.
RyoheiHagimoto 0:0e0631af0305 2076 @param newImageSize New image resolution after rectification. The same size should be passed to
RyoheiHagimoto 0:0e0631af0305 2077 initUndistortRectifyMap (see the stereo_calib.cpp sample in OpenCV samples directory). When (0,0)
RyoheiHagimoto 0:0e0631af0305 2078 is passed (default), it is set to the original imageSize . Setting it to larger value can help you
RyoheiHagimoto 0:0e0631af0305 2079 preserve details in the original image, especially when there is a big radial distortion.
RyoheiHagimoto 0:0e0631af0305 2080 @param balance Sets the new focal length in range between the min focal length and the max focal
RyoheiHagimoto 0:0e0631af0305 2081 length. Balance is in range of [0, 1].
RyoheiHagimoto 0:0e0631af0305 2082 @param fov_scale Divisor for new focal length.
RyoheiHagimoto 0:0e0631af0305 2083 */
RyoheiHagimoto 0:0e0631af0305 2084 CV_EXPORTS_W void stereoRectify(InputArray K1, InputArray D1, InputArray K2, InputArray D2, const Size &imageSize, InputArray R, InputArray tvec,
RyoheiHagimoto 0:0e0631af0305 2085 OutputArray R1, OutputArray R2, OutputArray P1, OutputArray P2, OutputArray Q, int flags, const Size &newImageSize = Size(),
RyoheiHagimoto 0:0e0631af0305 2086 double balance = 0.0, double fov_scale = 1.0);
RyoheiHagimoto 0:0e0631af0305 2087
RyoheiHagimoto 0:0e0631af0305 2088 /** @brief Performs stereo calibration
RyoheiHagimoto 0:0e0631af0305 2089
RyoheiHagimoto 0:0e0631af0305 2090 @param objectPoints Vector of vectors of the calibration pattern points.
RyoheiHagimoto 0:0e0631af0305 2091 @param imagePoints1 Vector of vectors of the projections of the calibration pattern points,
RyoheiHagimoto 0:0e0631af0305 2092 observed by the first camera.
RyoheiHagimoto 0:0e0631af0305 2093 @param imagePoints2 Vector of vectors of the projections of the calibration pattern points,
RyoheiHagimoto 0:0e0631af0305 2094 observed by the second camera.
RyoheiHagimoto 0:0e0631af0305 2095 @param K1 Input/output first camera matrix:
RyoheiHagimoto 0:0e0631af0305 2096 \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
RyoheiHagimoto 0:0e0631af0305 2097 any of fisheye::CALIB_USE_INTRINSIC_GUESS , fisheye::CV_CALIB_FIX_INTRINSIC are specified,
RyoheiHagimoto 0:0e0631af0305 2098 some or all of the matrix components must be initialized.
RyoheiHagimoto 0:0e0631af0305 2099 @param D1 Input/output vector of distortion coefficients \f$(k_1, k_2, k_3, k_4)\f$ of 4 elements.
RyoheiHagimoto 0:0e0631af0305 2100 @param K2 Input/output second camera matrix. The parameter is similar to K1 .
RyoheiHagimoto 0:0e0631af0305 2101 @param D2 Input/output lens distortion coefficients for the second camera. The parameter is
RyoheiHagimoto 0:0e0631af0305 2102 similar to D1 .
RyoheiHagimoto 0:0e0631af0305 2103 @param imageSize Size of the image used only to initialize intrinsic camera matrix.
RyoheiHagimoto 0:0e0631af0305 2104 @param R Output rotation matrix between the 1st and the 2nd camera coordinate systems.
RyoheiHagimoto 0:0e0631af0305 2105 @param T Output translation vector between the coordinate systems of the cameras.
RyoheiHagimoto 0:0e0631af0305 2106 @param flags Different flags that may be zero or a combination of the following values:
RyoheiHagimoto 0:0e0631af0305 2107 - **fisheye::CV_CALIB_FIX_INTRINSIC** Fix K1, K2? and D1, D2? so that only R, T matrices
RyoheiHagimoto 0:0e0631af0305 2108 are estimated.
RyoheiHagimoto 0:0e0631af0305 2109 - **fisheye::CALIB_USE_INTRINSIC_GUESS** K1, K2 contains valid initial values of
RyoheiHagimoto 0:0e0631af0305 2110 fx, fy, cx, cy that are optimized further. Otherwise, (cx, cy) is initially set to the image
RyoheiHagimoto 0:0e0631af0305 2111 center (imageSize is used), and focal distances are computed in a least-squares fashion.
RyoheiHagimoto 0:0e0631af0305 2112 - **fisheye::CALIB_RECOMPUTE_EXTRINSIC** Extrinsic will be recomputed after each iteration
RyoheiHagimoto 0:0e0631af0305 2113 of intrinsic optimization.
RyoheiHagimoto 0:0e0631af0305 2114 - **fisheye::CALIB_CHECK_COND** The functions will check validity of condition number.
RyoheiHagimoto 0:0e0631af0305 2115 - **fisheye::CALIB_FIX_SKEW** Skew coefficient (alpha) is set to zero and stay zero.
RyoheiHagimoto 0:0e0631af0305 2116 - **fisheye::CALIB_FIX_K1..4** Selected distortion coefficients are set to zeros and stay
RyoheiHagimoto 0:0e0631af0305 2117 zero.
RyoheiHagimoto 0:0e0631af0305 2118 @param criteria Termination criteria for the iterative optimization algorithm.
RyoheiHagimoto 0:0e0631af0305 2119 */
RyoheiHagimoto 0:0e0631af0305 2120 CV_EXPORTS_W double stereoCalibrate(InputArrayOfArrays objectPoints, InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2,
RyoheiHagimoto 0:0e0631af0305 2121 InputOutputArray K1, InputOutputArray D1, InputOutputArray K2, InputOutputArray D2, Size imageSize,
RyoheiHagimoto 0:0e0631af0305 2122 OutputArray R, OutputArray T, int flags = fisheye::CALIB_FIX_INTRINSIC,
RyoheiHagimoto 0:0e0631af0305 2123 TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 100, DBL_EPSILON));
RyoheiHagimoto 0:0e0631af0305 2124
RyoheiHagimoto 0:0e0631af0305 2125 //! @} calib3d_fisheye
RyoheiHagimoto 0:0e0631af0305 2126 }
RyoheiHagimoto 0:0e0631af0305 2127
RyoheiHagimoto 0:0e0631af0305 2128 } // cv
RyoheiHagimoto 0:0e0631af0305 2129
RyoheiHagimoto 0:0e0631af0305 2130 #ifndef DISABLE_OPENCV_24_COMPATIBILITY
RyoheiHagimoto 0:0e0631af0305 2131 #include "opencv2/calib3d/calib3d_c.h"
RyoheiHagimoto 0:0e0631af0305 2132 #endif
RyoheiHagimoto 0:0e0631af0305 2133
RyoheiHagimoto 0:0e0631af0305 2134 #endif