]> rtime.felk.cvut.cz Git - opencv.git/blobdiff - opencv/doc/cv_calibration_3d.tex
updated StereoBM description, added StereoSGBM description, partly fixed the table...
[opencv.git] / opencv / doc / cv_calibration_3d.tex
index 3840d28dc4fcc1b00769fe2ab62b3cda0d28a2f4..5a69e14c16a00cef852607777b37984feb80690c 100644 (file)
@@ -12,13 +12,13 @@ or
 
 \[
 s \vecthree{u}{v}{1} = \vecthreethree
-{fx}{0}{cx}
-{0}{fy}{cy}
+{f_x}{0}{c_x}
+{0}{f_y}{c_y}
 {0}{0}{1}
 \begin{bmatrix}
- r_{11} & r_{12} & r{13} & t_1 \\
- r_{21} & r_{22} & r{23} & t_2 \\
- r_{31} & r_{32} & r{33} & t_3
+ r_{11} & r_{12} & r_{13} & t_1 \\
+ r_{21} & r_{22} & r_{23} & t_2 \\
+ r_{31} & r_{32} & r_{33} & t_3
 \end{bmatrix}
 \begin{bmatrix}X\\Y\\Z\\1 \end{bmatrix}
 \]
@@ -52,7 +52,7 @@ v = f_y*y' + c_y
 \]
 
 Real lenses usually have some distortion, mostly
-radial distorion and slight tangential distortion. So, the above model
+radial distortion and slight tangential distortion. So, the above model
 is extended as:
 
 \[
@@ -69,7 +69,8 @@ v = f_y*y'' + c_y
 \]
 
 $k_1$, $k_2$, $k_3$ are radial distortion coefficients, $p_1$, $p_2$ are tangential distortion coefficients.
-Higher-order coefficients are not considered in OpenCV.
+Higher-order coefficients are not considered in OpenCV. In the functions below the coefficients are passed or returned as
+\[ (k_1, k_2, p_1, p_2[, k_3]) \]vector. That is, if the vector contains 4 elements, it means that $k_3=0$.
 The distortion coefficients do not depend on the scene viewed, thus they also belong to the intrinsic camera parameters.
 \emph{And they remain the same regardless of the captured image resolution.}
 That is, if, for example, a camera has been calibrated on images of $320
@@ -82,7 +83,8 @@ The functions below use the above model to
 \begin{itemize}
  \item Project 3D points to the image plane given intrinsic and extrinsic parameters
  \item Compute extrinsic parameters given intrinsic parameters, a few 3D points and their projections.
- \item Estimate intrinsic and extrinsic camera parameters from several views of a known calibration pattern (i.e. every view is described by several 3D-2D point correspodences).
+ \item Estimate intrinsic and extrinsic camera parameters from several views of a known calibration pattern (i.e. every view is described by several 3D-2D point correspondences).
+ \item Estimate the relative position and orientation of the stereo camera "heads" and compute the \emph{rectification} transformation that makes the camera optical axes parallel.
 \end{itemize}
 
 \ifCPy
@@ -92,7 +94,8 @@ Calculates the homography matrix for an oblong planar object (e.g. arm).
 
 \cvdefC{
 void cvCalcImageHomography( \par float* line,\par CvPoint3D32f* center,\par float* intrinsic,\par float* homography );
-}\cvdefPy{CalcImageHomography(line,points)-> intrinsic,homography}
+}
+\cvdefPy{CalcImageHomography(line,center)-> (intrinsic,homography)}
 
 \begin{description}
 \cvarg{line}{the main object axis direction (vector (dx,dy,dz))}
@@ -106,29 +109,45 @@ matrix for the initial image transformation from image plane to the
 plane, defined by a 3D oblong object line (See \_\_Figure 6-10\_\_
 in the OpenCV Guide 3D Reconstruction Chapter).
 
+\fi
 
+\ifCPy
 \cvCPyFunc{CalibrateCamera2}
-Finds the intrinsic and extrinsic camera parameters using a calibration pattern.
-
-\cvdefC{
-void cvCalibrateCamera2( \par const CvMat* object\_points,\par const CvMat* image\_points,\par const CvMat* point\_counts,\par CvSize image\_size,\par CvMat* intrinsic\_matrix,\par CvMat* distortion\_coeffs,\par CvMat* rotation\_vectors=NULL,\par CvMat* translation\_vectors=NULL,\par int flags=0 );
-}\cvdefPy{CalibrateCamera2(object\_points,image\_points,point\_counts,image\_size,intrinsic\_matrix,distortion\_coeffs,rotation\_vectors,translation\_vectors,flags=0)-> None}
+\else
+\cvCppFunc{calibrateCamera}
+\fi
+Finds the camera intrinsic and extrinsic parameters from several views of a calibration pattern.
 
+\cvdefC{double cvCalibrateCamera2( \par const CvMat* objectPoints,\par const CvMat* imagePoints,\par const CvMat* pointCounts,\par CvSize imageSize,\par CvMat* cameraMatrix,\par CvMat* distCoeffs,\par CvMat* rvecs=NULL,\par CvMat* tvecs=NULL,\par int flags=0 );}
+\cvdefPy{CalibrateCamera2(objectPoints,imagePoints,pointCounts,imageSize,cameraMatrix,distCoeffs,rvecs,tvecs,flags=0)-> None}
+\cvdefCpp{double calibrateCamera( const vector<vector<Point3f> >\& objectPoints,\par
+                      const vector<vector<Point2f> >\& imagePoints,\par
+                      Size imageSize,\par
+                      Mat\& cameraMatrix, Mat\& distCoeffs,\par
+                      vector<Mat>\& rvecs, vector<Mat>\& tvecs,\par
+                      int flags=0 );}
 \begin{description}
-\cvarg{object\_points}{The joint matrix of object points, 3xN or Nx3, where N is the total number of points in all views}
-\cvarg{image\_points}{The joint matrix of corresponding image points, 2xN or Nx2, where N is the total number of points in all views}
-\cvarg{point\_counts}{Vector containing the number of points in each particular view, 1xM or Mx1, where M is the number of points in a scene}
-\cvarg{image\_size}{Size of the image, used only to initialize the intrinsic camera matrix}
-\cvarg{intrinsic\_matrix}{The output camera matrix $A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1} $. If \texttt{CV\_CALIB\_USE\_INTRINSIC\_GUESS} and/or \texttt{CV\_CALIB\_FIX\_ASPECT\_RATION} are specified, some or all of \texttt{fx, fy, cx, cy} must be initialized}
-\cvarg{distortion\_coeffs}{The output 4x1 or 1x4 vector of distortion coefficients $k_1, k_2, k_3, k_4$}
-\cvarg{rotation\_vectors}{The output 3xM or Mx3 array of rotation vectors (compact representation of rotation matrices, \cvCPyCross{Rodrigues2})}
-\cvarg{translation\_vectors}{The output 3xM or Mx3 array of translation vectors}
+\ifCPy
+\cvarg{objectPoints}{The joint matrix of object points - calibration pattern features in the model coordinate space. It is floating-point 3xN or Nx3 1-channel, or 1xN or Nx1 3-channel array, where N is the total number of points in all views.}
+\cvarg{imagePoints}{The joint matrix of object points projections in the camera views. It is floating-point 2xN or Nx2 1-channel, or 1xN or Nx1 2-channel array, where N is the total number of points in all views}
+\cvarg{pointCounts}{Integer 1xM or Mx1 vector (where M is the number of calibration pattern views) containing the number of points in each particular view. The sum of vector elements must match the size of \texttt{objectPoints} and \texttt{imagePoints} (=N).}
+\fi
+\ifCpp
+\cvarg{objectPoints}{The vector of vectors of points on the calibration pattern in its coordinate system, one vector per view. If the same calibration pattern is shown in each view and it's fully visible then all the vectors will be the same, although it is possible to use partially occluded patterns, or even different patterns in different views - then the vectors will be different. The points are 3D, but since they are in the pattern coordinate system, then if the rig is planar, it may have sense to put the model to the XY coordinate plane, so that Z-coordinate of each input object point is 0}
+\cvarg{imagePoints}{The vector of vectors of the object point projections on the calibration pattern views, one vector per a view. The projections must be in the same order as the corresponding object points.}
+\fi
+\cvarg{imageSize}{Size of the image, used only to initialize the intrinsic camera matrix}
+\cvarg{cameraMatrix}{The output 3x3 floating-point camera matrix $A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}$.\newline
+If \texttt{CV\_CALIB\_USE\_INTRINSIC\_GUESS} and/or \texttt{CV\_CALIB\_FIX\_ASPECT\_RATIO} are specified, some or all of \texttt{fx, fy, cx, cy} must be initialized before calling the function}
+\cvarg{distCoeffs}{The output \cvCPy{4x1, 1x4,} 5x1 or 1x5 vector of distortion coefficients $(k_1, k_2, p_1, p_2[, k_3])$}.
+\cvarg{rvecs}{The output \cvCPy{3x\emph{M} or \emph{M}x3 1-channel, or 1x\emph{M} or \emph{M}x1 3-channel array}\cvCpp{vector} of rotation vectors (see \cvCross{Rodrigues2}{Rodrigues}), estimated for each pattern view. That is, each k-th rotation vector together with the corresponding k-th translation vector (see the next output parameter description) brings the calibration pattern from the model coordinate space (in which object points are specified) to the world coordinate space, i.e. real position of the calibration pattern in the k-th pattern view (k=0..\emph{M}-1)}
+\cvarg{tvecs}{The output \cvCPy{3x\emph{M} or \emph{M}x3 1-channel, or 1x\emph{M} or \emph{M}x1 3-channel array}\cvCpp{vector} of translation vectors, estimated for each pattern view.}
 \cvarg{flags}{Different flags, may be 0 or combination of the following values:
 \begin{description}
-\cvarg{CV\_CALIB\_USE\_INTRINSIC\_GUESS}{\texttt{intrinsic\_matrix} contains the valid initial values of \texttt{fx, fy, cx, cy} that are optimized further. Otherwise, \texttt{(cx, cy)} is initially set to the image center (\texttt{image\_size} is used here), and focal distances are computed in some least-squares fashion. Note, that if intrinsic parameters are known, there is no need to use this function. Use \cvCPyCross{FindExtrinsicCameraParams2} instead.}
-\cvarg{CV\_CALIB\_FIX\_PRINCIPAL\_POINT}{The principal point is not changed during the global optimization, it stays at the center and at the other location specified (when \texttt{CV\_CALIB\_USE\_INTRINSIC\_GUESS} is set as well)}
-\cvarg{CV\_CALIB\_FIX\_ASPECT\_RATIO}{The optimization procedure considers only one of \texttt{fx} and \texttt{fy} as independent variables and keeps the aspect ratio \texttt{fx/fy} the same as it was set initially in \texttt{intrinsic\_matrix}. In this case the actual initial values of \texttt{(fx, fy)} are either taken from the matrix (when \texttt{CV\_CALIB\_USE\_INTRINSIC\_GUESS} is set) or estimated somehow (in the latter case \texttt{fx, fy} may be set to arbitrary values, only their ratio is used).}
-\cvarg{CV\_CALIB\_ZERO\_TANGENT\_DIST}{Tangential distortion coefficients are set to zeros and do not change during the optimization.}}
+\cvarg{CV\_CALIB\_USE\_INTRINSIC\_GUESS}{\texttt{cameraMatrix} contains the valid initial values of \texttt{fx, fy, cx, cy} that are optimized further. Otherwise, \texttt{(cx, cy)} is initially set to the image center (\texttt{imageSize} is used here), and focal distances are computed in some least-squares fashion. Note, that if intrinsic parameters are known, there is no need to use this function just to estimate the extrinsic parameters. Use \cvCross{FindExtrinsicCameraParams2}{solvePnP} instead.}
+\cvarg{CV\_CALIB\_FIX\_PRINCIPAL\_POINT}{The principal point is not changed during the global optimization, it stays at the center or at the other location specified when \newline \texttt{CV\_CALIB\_USE\_INTRINSIC\_GUESS} is set too.}
+\cvarg{CV\_CALIB\_FIX\_ASPECT\_RATIO}{The functions considers only \texttt{fy} as a free parameter, the ratio \texttt{fx/fy} stays the same as in the input \texttt{cameraMatrix}. \newline When \texttt{CV\_CALIB\_USE\_INTRINSIC\_GUESS} is not set, the actual input values of \texttt{fx} and \texttt{fy} are ignored, only their ratio is computed and used further.}
+\cvarg{CV\_CALIB\_ZERO\_TANGENT\_DIST}{Tangential distortion coefficients $(p_1, p_2)$ will be set to zeros and stay zero.}}
 \end{description}
 \end{description}
 
@@ -139,75 +158,161 @@ in each view must be specified. That may be achieved by using an
 object with known geometry and easily detectable feature points.
 Such an object is called a calibration rig or calibration pattern,
 and OpenCV has built-in support for a chessboard as a calibration
-rig (see \cvCPyCross{FindChessboardCornerGuesses}). Currently, initialization
+rig (see \cvCross{FindChessboardCorners}{findChessboardCorners}). Currently, initialization
 of intrinsic parameters (when \texttt{CV\_CALIB\_USE\_INTRINSIC\_GUESS}
-is not set) is only implemented for planar calibration rigs
-(z-coordinates of object points must be all 0's or all 1's). 3D
-rigs can still be used as long as initial \texttt{intrinsic\_matrix}
-is provided. After the initial values of intrinsic and extrinsic
-parameters are computed, they are optimized to minimize the total
-back-projection error - the sum of squared differences between the
-actual coordinates of image points and the ones computed using
-\cvCPyCross{ProjectPoints2}.
+is not set) is only implemented for planar calibration patterns
+(where z-coordinates of the object points must be all 0's). 3D
+calibration rigs can also be used as long as initial \texttt{cameraMatrix}
+is provided.
+
+The algorithm does the following:
+\begin{enumerate}
+    \item First, it computes the initial intrinsic parameters (the option only available for planar calibration patterns) or reads them from the input parameters. The distortion coefficients are all set to zeros initially (unless some of \texttt{CV\_CALIB\_FIX\_K?} are specified).
+    \item The initial camera pose is estimated as if the intrinsic parameters have been already known. This is done using \cvCross{FindExtrinsicCameraParams2}{solvePnP}
+    \item After that the global Levenberg-Marquardt optimization algorithm is run to minimize the reprojection error, i.e. the total sum of squared distances between the observed feature points \texttt{imagePoints} and the projected (using the current estimates for camera parameters and the poses) object points \texttt{objectPoints}; see \cvCross{ProjectPoints2}{projectPoints}.
+\end{enumerate}
+
+\ifPy
+\else
+The function returns the final re-projection error.
+\fi
 
 Note: if you're using a non-square (=non-NxN) grid and
-\cvCPyCross{FindChessboardCorners} for calibration, and cvCalibrateCamera2 returns
-bad values (i.e. zero distortion coefficients, an image center of
-(w/2-0.5,h/2-0.5), and / or large differences between $fx$ and $fy$ (ratios of
-10:1 or more)), then you've probaby  used pattern\_size=cvSize(rows,cols),
-but should use pattern\_size=cvSize(cols,rows) in \cvCPyCross{FindChessboardCorners}.
+\cvCppCross{findChessboardCorners} for calibration, and \texttt{calibrateCamera} returns
+bad values (i.e. zero distortion coefficients, an image center very far from
+$(w/2-0.5,h/2-0.5)$, and / or large differences between $f_x$ and $f_y$ (ratios of
+10:1 or more)), then you've probably used \texttt{patternSize=cvSize(rows,cols)},
+but should use \texttt{patternSize=cvSize(cols,rows)} in \cvCross{FindChessboardCorners}{findChessboardCorners}.
+
+See also: \cvCross{FindChessboardCorners}{findChessboardCorners}, \cvCross{FindExtrinsicCameraParams2}{solvePnP}, \cvCppCross{initCameraMatrix2D}, \cvCross{StereoCalibrate}{stereoCalibrate}, \cvCross{Undistort2}{undistort}
+
+\ifCpp
+
+\cvCppFunc{calibrationMatrixValues}
+Computes some useful camera characteristics from the camera matrix
+
+\cvdefCpp{void calibrationMatrixValues( const Mat\& cameraMatrix,\par
+                              Size imageSize,\par
+                              double apertureWidth,\par
+                              double apertureHeight,\par
+                              double\& fovx,\par
+                              double\& fovy,\par
+                              double\& focalLength,\par
+                              Point2d\& principalPoint,\par
+                              double\& aspectRatio );}
+\begin{description}
+\cvarg{cameraMatrix}{The input camera matrix that can be estimated by \cvCppCross{calibrateCamera} or \cvCppCross{stereoCalibrate}}
+\cvarg{imageSize}{The input image size in pixels}
+\cvarg{apertureWidth}{Physical width of the sensor}
+\cvarg{apertureHeight}{Physical height of the sensor}
+\cvarg{fovx}{The output field of view in degrees along the horizontal sensor axis}
+\cvarg{fovy}{The output field of view in degrees along the vertical sensor axis}
+\cvarg{focalLength}{The focal length of the lens in mm}
+\cvarg{principalPoint}{The principal point in pixels}
+\cvarg{aspectRatio}{$f_y/f_x$}
+\end{description}
+
+The function computes various useful camera characteristics from the previously estimated camera matrix.
+
+\cvCppFunc{composeRT}
+Combines two rotation-and-shift transformations
+
+\cvdefCpp{void composeRT( const Mat\& rvec1, const Mat\& tvec1,\par
+                const Mat\& rvec2, const Mat\& tvec2,\par
+                Mat\& rvec3, Mat\& tvec3 );\newline
+void composeRT( const Mat\& rvec1, const Mat\& tvec1,\par
+                const Mat\& rvec2, const Mat\& tvec2,\par
+                Mat\& rvec3, Mat\& tvec3,\par
+                Mat\& dr3dr1, Mat\& dr3dt1,\par
+                Mat\& dr3dr2, Mat\& dr3dt2,\par
+                Mat\& dt3dr1, Mat\& dt3dt1,\par
+                Mat\& dt3dr2, Mat\& dt3dt2 );}
+\begin{description}
+\cvarg{rvec1}{The first rotation vector}
+\cvarg{tvec1}{The first translation vector}
+\cvarg{rvec2}{The second rotation vector}
+\cvarg{tvec2}{The second translation vector}
+\cvarg{rvec3}{The output rotation vector of the superposition}
+\cvarg{tvec3}{The output translation vector of the superposition}
+\cvarg{d??d??}{The optional output derivatives of \texttt{rvec3} or \texttt{tvec3} w.r.t. \texttt{rvec?} or \texttt{tvec?}}
+\end{description}
+
+The functions compute:
+
+\[ \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}, \]
+
+where $\mathrm{rodrigues}$ denotes a rotation vector to rotation matrix transformation, and $\mathrm{rodrigues}^{-1}$ denotes the inverse transformation, see \cvCppCross{Rodrigues}.
+
+Also, the functions can compute the derivatives of the output vectors w.r.t the input vectors (see \cvCppCross{matMulDeriv}).
+The functions are used inside \cvCppCross{stereoCalibrate} but can also be used in your own code where Levenberg-Marquardt or another gradient-based solver is used to optimize a function that contains matrix multiplication.
+
+\fi
 
+\ifCPy
 \cvCPyFunc{ComputeCorrespondEpilines}
+\else
+\cvCppFunc{computeCorrespondEpilines}
+\fi
 For points in one image of a stereo pair, computes the corresponding epilines in the other image.
 
-\cvdefC{
-void cvComputeCorrespondEpilines( \par const CvMat* points,\par int which\_image,\par const CvMat* fundamental\_matrix,\par CvMat* correspondent\_lines);
-}\cvdefPy{ComputeCorrespondEpilines(points, which\_image, fundamental\_matrix, correspondent\_lines) -> None}
-
+\cvdefC{void cvComputeCorrespondEpilines( \par const CvMat* points,\par int whichImage,\par const CvMat* F, \par CvMat* lines);}
+\cvdefPy{ComputeCorrespondEpilines(points, whichImage, F, lines) -> None}
+\cvdefCpp{void computeCorrespondEpilines( const Mat\& points,\par
+                                int whichImage, const Mat\& F,\par
+                                vector<Vec3f>\& lines );}
 \begin{description}
-\cvarg{points}{The input points. \texttt{2xN, Nx2, 3xN} or \texttt{Nx3} array (where \texttt{N} number of points). Multi-channel \texttt{1xN} or \texttt{Nx1} array is also acceptable}
-\cvarg{which\_image}{Index of the image (1 or 2) that contains the \texttt{points}}
-\cvarg{fundamental\_matrix}{Fundamental matrix}
-\cvarg{correspondent\_lines}{Computed epilines, a \texttt{3xN} or \texttt{Nx3} array}
+\cvCPy{\cvarg{points}{The input points. \texttt{2xN, Nx2, 3xN} or \texttt{Nx3} array (where \texttt{N} number of points). Multi-channel \texttt{1xN} or \texttt{Nx1} array is also acceptable}}
+\cvCpp{\cvarg{points}{The input points. $N \times 1$ or $1 \times N$ matrix of type \texttt{CV\_32FC2} or \texttt{vector<Point2f>}}}
+\cvarg{whichImage}{Index of the image (1 or 2) that contains the \texttt{points}}
+\cvarg{F}{The fundamental matrix that can be estimated using \cvCross{FindFundamentalMat}{findFundamentalMat}
+or \cvCross{StereoRectify}{stereoRectify}.}
+\cvarg{lines}{\cvCPy{The output epilines, a \texttt{3xN} or \texttt{Nx3} array.}\cvCpp{The output vector of the corresponding to the points epipolar lines in the other image.} Each line $ax + by + c=0$ is encoded by 3 numbers $(a, b, c)$}
 \end{description}
 
-For every point in one of the two images of a stereo-pair the function
-\texttt{ComputeCorrespondEpilines} finds the equation of a line that
-contains the corresponding point (i.e. projection of the same 3D
-point) in the other image. Each line is encoded by a vector of 3
-elements $l = \vecthree{a}{b}{c}$ so that:
+For every point in one of the two images of a stereo-pair the function finds the equation of the
+corresponding epipolar line in the other image.
 
-\[ l^T \vecthree{x}{y}{1} = 0 \]
-or
-\[ a x + b y + c = 0 \]
+From the fundamental matrix definition (see \cvCross{FindFundamentalMat}{findFundamentalMat}),
+line $l^{(2)}_i$ in the second image for the point $p^{(1)}_i$ in the first image (i.e. when \texttt{whichImage=1}) is computed as:
 
-From the fundamental matrix definition (see \cvCPyCross{FindFundamentalMatrix}
-discussion), line $l_1$ for a point $p_1$ in the first image
-$(\texttt{which\_image} =1)$ can be computed as:
+\[ l^{(2)}_i = F p^{(1)}_i \]
 
-\[ l_2 = F p_1 \]
+and, vice versa, when \texttt{whichImage=2}, $l^{(1)}_i$ is computed from $p^{(2)}_i$ as:
 
-and the line $l_1$ for a point $p_2$ in the second image $(\texttt{which\_image} =1)$ can be computed as:
+\[ l^{(1)}_i = F^T p^{(2)}_i \]
 
-\[ l_1 = F^T p_2 \]
+Line coefficients are defined up to a scale. They are normalized, such that $a_i^2+b_i^2=1$.
 
-Line coefficients are defined up to a scale. They are normalized $(a^2+b^2=1)$ are stored into \texttt{correspondent\_lines}.
+\ifCPy
+\cvCPyFunc{ConvertPointsHomogeneous}
+\else
+\cvCppFunc{convertPointsHomogeneous}
+\fi
+Convert points to/from homogeneous coordinates.
 
-\ifC
+\cvdefC{void cvConvertPointsHomogeneous( \par const CvMat* src,\par CvMat* dst );}
 
-\cvCPyFunc{ConvertPointsHomogenious}
-Convert points to/from homogenious coordinates.
+\cvdefPy{ConvertPointsHomogeneous( src, dst ) -> None}
 
-\cvdefC{
-void cvConvertPointsHomogenious( \par const CvMat* src,\par CvMat* dst );
-}
+\cvdefCpp{void convertPointsHomogeneous( const Mat\& src, vector<Point3f>\& dst );
+
+void convertPointsHomogeneous( const Mat\& src, vector<Point2f>\& dst );}
 
 \begin{description}
+\ifC
 \cvarg{src}{The input point array, \texttt{2xN, Nx2, 3xN, Nx3, 4xN or Nx4 (where \texttt{N} is the number of points)}. Multi-channel \texttt{1xN} or \texttt{Nx1} array is also acceptable}
 \cvarg{dst}{The output point array, must contain the same number of points as the input; The dimensionality must be the same, 1 less or 1 more than the input, and also within 2 to 4}
+\else
+\cvarg{src}{The input array or vector of 2D or 3D points}
+\cvarg{dst}{The output vector of 3D or 2D points, respectively}
+\fi
 \end{description}
 
-The function converts 2D or 3D points from/to homogenious coordinates, or simply copies or transposes the array. If the input array dimensionality is larger than the output, each coordinate is divided by the last coordinate:
+The \cvC{function converts}\cvCpp{functions convert} 2D or 3D points from/to homogeneous coordinates, or simply \cvC{copies or transposes}\cvCpp{copy or transpose} the array. If the input array dimensionality is larger than the output, each coordinate is divided by the last coordinate:
 
 \[
 \begin{array}{l}
@@ -219,11 +324,11 @@ z' = z/w \quad \text{(if output is 3D)}
 \end{array}
 \]
 
-If the output array dimensionality is larger, an extra 1 is appended to each point.  Otherwise, the input array is simply copied (with optional tranposition) to the output.
+If the output array dimensionality is larger, an extra 1 is appended to each point.  Otherwise, the input array is simply copied (with optional transposition) to the output.
 
-\textbf{Note} because the function accepts a large variety of array layouts, it may report an error when input/output array dimensionality is ambiguous. It is always safe to use the function with number of points $\texttt{N} \ge 5$, or to use multi-channel \texttt{Nx1} or \texttt{1xN} arrays.
+\cvC{\textbf{Note} because the function accepts a large variety of array layouts, it may report an error when input/output array dimensionality is ambiguous. It is always safe to use the function with number of points $\texttt{N} \ge 5$, or to use multi-channel \texttt{Nx1} or \texttt{1xN} arrays.}
 
-\fi
+\ifCPy
 
 \cvCPyFunc{CreatePOSITObject}
 Initializes a structure containing object information.
@@ -233,8 +338,12 @@ CvPOSITObject* cvCreatePOSITObject( \par CvPoint3D32f* points,\par int point\_co
 }\cvdefPy{CreatePOSITObject(points)-> POSITObject}
 
 \begin{description}
+\ifC
 \cvarg{points}{Pointer to the points of the 3D object model}
 \cvarg{point\_count}{Number of object points}
+\else
+\cvarg{points}{List of 3D points}
+\fi
 \end{description}
 
 The function allocates memory for the object structure and computes the object inverse matrix.
@@ -248,25 +357,28 @@ Once the work with a given object is finished, the function \cvCPyCross{ReleaseP
 \cvCPyFunc{CreateStereoBMState}
 Creates block matching stereo correspondence structure.
 
-\begin{lstlisting}
-#define CV_STEREO_BM_BASIC 0
-#define CV_STEREO_BM_FISH_EYE 1
-#define CV_STEREO_BM_NARROW 2
-\end{lstlisting}
-
 \cvdefC{
 
 CvStereoBMState* cvCreateStereoBMState( int preset=CV\_STEREO\_BM\_BASIC,
                                         int numberOfDisparities=0 );
 
-}\cvdefPy{CreateStereoBMState(preset=CV\_STEREO\_BM\_BASIC,numberOfDisparities=0)-> StereoBMState}
+}
+\cvdefPy{CreateStereoBMState(preset=CV\_STEREO\_BM\_BASIC,numberOfDisparities=0)-> StereoBMState}
 
 \begin{description}
-\cvarg{preset}{ID of one of the pre-defined parameter sets. Any of the parameters can be overridden after creating the structure.}
+\cvarg{preset}{ID of one of the pre-defined parameter sets. Any of the parameters can be overridden after creating the structure.  Values are
+\begin{description}
+\cvarg{CV\_STEREO\_BM\_BASIC}{Parameters suitable for general cameras}
+\cvarg{CV\_STEREO\_BM\_FISH\_EYE}{Parameters suitable for wide-angle cameras}
+\cvarg{CV\_STEREO\_BM\_NARROW}{Parameters suitable for narrow-angle cameras}
+\end{description}
+}
 \cvarg{numberOfDisparities}{The number of disparities. If the parameter is 0, it is taken from the preset, otherwise the supplied value overrides the one from preset.}
 \end{description}
 
-The function creates the stereo correspondence structure and initializes it. It is possible to override any of the parameters at any time between the calls to \cvCPyCross{cvFindStereoCorrespondenceBM}.
+The function creates the stereo correspondence structure and initializes
+it. It is possible to override any of the parameters at any time between
+the calls to \cvCPyCross{FindStereoCorrespondenceBM}.
 
 \cvCPyFunc{CreateStereoGCState}
 Creates the state of graph cut-based stereo correspondence algorithm.
@@ -276,18 +388,20 @@ Creates the state of graph cut-based stereo correspondence algorithm.
 CvStereoGCState* cvCreateStereoGCState( int numberOfDisparities,
                                         int maxIters );
 
-}\cvdefPy{CreateStereoGCState(numberOfDispaities,maxIters)-> StereoGCState}
+}
+\cvdefPy{CreateStereoGCState(numberOfDisparities,maxIters)-> StereoGCState}
 
 \begin{description}
 \cvarg{numberOfDisparities}{The number of disparities. The disparity search range will be $\texttt{state->minDisparity} \le disparity < \texttt{state->minDisparity} + \texttt{state->numberOfDisparities}$}
-\cvarg{maxIters}{Maximum number of iterations. On each iteration all possible (or reasonable) alpha-expansions are tried. The algorithm may terminate earlier if it could not find an alpha-expansion that decreases the overall cost function value. See \href{\#Kolmogorov03}{[Kolmogorov03]}  for details. }
+\cvarg{maxIters}{Maximum number of iterations. On each iteration all possible (or reasonable) alpha-expansions are tried. The algorithm may terminate earlier if it could not find an alpha-expansion that decreases the overall cost function value. See \cite{Kolmogorov03}  for details. }
 \end{description}
 
-The function creates the stereo correspondence structure and initializes it. It is possible to override any of the parameters at any time between the calls to \cvCPyCross{cvFindStereoCorrespondenceGC}.
+The function creates the stereo correspondence structure and initializes it. It is possible to override any of the parameters at any time between the calls to \cvCPyCross{FindStereoCorrespondenceGC}.
 
-\cvCPyFunc{CvStereoBMState}
+\cvclass{CvStereoBMState}
 The structure for block matching stereo correspondence algorithm.
 
+\ifC
 \begin{lstlisting}
 typedef struct CvStereoBMState
 {
@@ -301,25 +415,48 @@ typedef struct CvStereoBMState
     int       numberOfDisparities; // maximum disparity - minimum disparity
     //post filters (knock out bad matches):
     int       textureThreshold; // areas with no texture are ignored
-    float     uniquenessRatio;// filter out pixels if there are other close matches
+    int       uniquenessRatio;// invalidate disparity at pixels where there are other close matches
                               // with different disparity
-    int       speckleWindowSize;// Disparity variation window (not used)
-    int       speckleRange; // Acceptable range of variation in window (not used)
-    // internal buffers, do not modify (!)
-    CvMat* preFilteredImg0;
-    CvMat* preFilteredImg1;
-    CvMat* slidingSumBuf;
+    int       speckleWindowSize; // the maximum area of speckles to remove
+                                 // (set to 0 to disable speckle filtering)
+    int       speckleRange; // acceptable range of disparity variation in each connected component
+    
+    int trySmallerWindows; // not used 
+    CvRect roi1, roi2; // clipping ROIs
+    
+    int disp12MaxDiff; // maximum allowed disparity difference in the left-right check 
+    
+    // internal data
+    ...
 }
 CvStereoBMState;
 \end{lstlisting}
+\fi
+\begin{description}
+\cvarg{preFilterType}{type of the prefilter, \texttt{CV\_STEREO\_BM\_NORMALIZED\_RESPONSE} or the default and the recommended \texttt{CV\_STEREO\_BM\_XSOBEL}, int}
+\cvarg{preFilterSize}{~5x5..21x21, int}
+\cvarg{preFilterCap}{up to ~31, int}
+\cvarg{SADWindowSize}{Could be 5x5..21x21 or higher, but with 21x21 or smaller windows the processing speed is much higher, int}
+\cvarg{minDisparity}{minimum disparity (=0), int}
+\cvarg{numberOfDisparities}{maximum disparity - minimum disparity, int}
+\cvarg{textureThreshold}{the textureness threshold. That is, if the sum of absolute values of x-derivatives computed over \texttt{SADWindowSize} by \texttt{SADWindowSize} pixel neighborhood is smaller than the parameter, no disparity is computed at the pixel, int}
+\cvarg{uniquenessRatio}{the minimum margin in percents between the best (minimum) cost function value and the second best value to accept the computed disparity, int}
+\cvarg{speckleWindowSize}{the maximum area of speckles to remove (set to 0 to disable speckle filtering), int}
+\cvarg{speckleRange}{acceptable range of disparity variation in each connected component, int}
+\cvarg{trySmallerWindows}{not used currently (0), int}
+\cvarg{roi1, roi2}{These are the clipping ROIs for the left and the right images. The function \cvCPyCross{StereoRectify} returns the largest rectangles in the left and right images where after the rectification all the pixels are valid. If you copy those rectangles to the \texttt{CvStereoBMState} structure, the stereo correspondence function will automatically clear out the pixels outside of the "valid" disparity rectangle computed by \cvCPyCross{GetValidDisparityROI}. Thus you will get more "invalid disparity" pixels than usual, but the remaining pixels are more probable to be valid.}
+\cvarg{disp12MaxDiff}{The maximum allowed difference between the explicitly computed left-to-right disparity map and the implicitly (by \cvCPyCross{ValidateDisparity}) computed right-to-left disparity. If for some pixel the difference is larger than the specified threshold, the disparity at the pixel is invalidated. By default this parameter is set to (-1), which means that the left-right check is not performed.}
+\end{description}
+
 
-The block matching stereo correspondence algorithm, by Kurt Konolige, is very fast one-pass stereo matching algorithm that uses sliding sums of absolute differences between pixels in the left image and the pixels in the right image, shifted by some varying amount of pixels (from \texttt{minDisparity} to \texttt{minDisparity+numberOfDisparities}). On a pair of images WxH the algorithm computes disparity in \texttt{O(W*H*numberOfDisparities)} time. In order to improve quality and reability of the disparity map, the algorithm includes pre-filtering and post-filtering procedures.
+The block matching stereo correspondence algorithm, by Kurt Konolige, is very fast single-pass stereo matching algorithm that uses sliding sums of absolute differences between pixels in the left image and the pixels in the right image, shifted by some varying amount of pixels (from \texttt{minDisparity} to \texttt{minDisparity+numberOfDisparities}). On a pair of images WxH the algorithm computes disparity in \texttt{O(W*H*numberOfDisparities)} time. In order to improve quality and readability of the disparity map, the algorithm includes pre-filtering and post-filtering procedures.
 
 Note that the algorithm searches for the corresponding blocks in x direction only. It means that the supplied stereo pair should be rectified. Vertical stereo layout is not directly supported, but in such a case the images could be transposed by user.
 
-\cvCPyFunc{CvStereoGCState}
+\cvclass{CvStereoGCState}
 The structure for graph cuts-based stereo correspondence algorithm
 
+\ifC
 \begin{lstlisting}
 typedef struct CvStereoGCState
 {
@@ -344,21 +481,48 @@ typedef struct CvStereoGCState
 }
 CvStereoGCState;
 \end{lstlisting}
+\else
+\begin{description}
+\cvarg{Ithreshold}{threshold for piece-wise linear data cost function (5 by default)}
+\cvarg{interactionRadius}{radius for smoothness cost function (1 by default; means Potts model)}
+\cvarg{K, lambda, lambda1, lambda2}{parameters for the cost function (usually computed adaptively from the input data)}
+\cvarg{occlusionCost}{10000 by default}
+\cvarg{minDisparity}{0 by default; see \cross{CvStereoBMState}}
+\cvarg{numberOfDisparities}{defined by user; see \cross{CvStereoBMState}}
+\cvarg{maxIters}{number of iterations; defined by user.}
+\end{description}
+\fi
 
-The graph cuts stereo correspondence algorithm, described in \href{\#Kolmogrov03}{[Kolmogorov03]} (as \textbf{KZ1}), is non-realtime stereo correpsondence algorithm that usually gives very accurate depth map with well-defined object boundaries. The algorithm represents stereo problem as a sequence of binary optimization problems, each of those is solved using maximum graph flow algorithm. The state structure above should not be allocated and initialized manually; instead, use \cvCPyCross{cvCreateStereoGCState} and then override necessary parameters if needed.
+The graph cuts stereo correspondence algorithm, described in \cite{Kolmogorov03} (as \textbf{KZ1}), is non-realtime stereo correspondence algorithm that usually gives very accurate depth map with well-defined object boundaries. The algorithm represents stereo problem as a sequence of binary optimization problems, each of those is solved using maximum graph flow algorithm. The state structure above should not be allocated and initialized manually; instead, use \cvCPyCross{CreateStereoGCState} and then override necessary parameters if needed.
 
+\fi
+
+\ifCPy
 \cvCPyFunc{DecomposeProjectionMatrix}
-Computes the `RQ' decomposition of 3x3 matrices.
+\else
+\cvCppFunc{decomposeProjectionMatrix}
+\fi
+Decomposes the projection matrix into a rotation matrix and a camera matrix.
 
 \cvdefC{
-void cvDecomposeProjectionMatrix( \par const CvMat *projMatr,\par CvMat *calibMatr,\par CvMat *rotMatr,\par CvMat *posVect,\par CvMat *rotMatrX=NULL,\par CvMat *rotMatrY=NULL,\par CvMat *rotMatrZ=NULL,\par CvPoint3D64f *eulerAngles=NULL);
-}\cvdefPy{DecomposeProjectionMatrix(projMatr, calibMatr, rotMatr, posVect, rotMatrX = None, rotMatrY = None, rotMatrZ = None) -> eulerAngles}
+void cvDecomposeProjectionMatrix( \par const CvMat *projMatrix,\par CvMat *cameraMatrix,\par CvMat *rotMatrix,\par CvMat *transVect,\par CvMat *rotMatrX=NULL,\par CvMat *rotMatrY=NULL,\par CvMat *rotMatrZ=NULL,\par CvPoint3D64f *eulerAngles=NULL);
+}
+
+\cvdefPy{DecomposeProjectionMatrix(projMatrix, cameraMatrix, rotMatrix, transVect, rotMatrX = None, rotMatrY = None, rotMatrZ = None) -> eulerAngles}
 
+\cvdefCpp{void decomposeProjectionMatrix( const Mat\& projMatrix,\par
+                                Mat\& cameraMatrix,\par
+                                Mat\& rotMatrix, Mat\& transVect );\newline
+void decomposeProjectionMatrix( const Mat\& projMatrix, \par
+                                Mat\& cameraMatrix,\par
+                                Mat\& rotMatrix, Mat\& transVect,\par
+                                Mat\& rotMatrixX, Mat\& rotMatrixY,\par
+                                Mat\& rotMatrixZ, Vec3d\& eulerAngles );}
 \begin{description}
-\cvarg{projMatr}{The 3x4 input projection matrix P}
-\cvarg{calibMatr}{The output 3x3 internal calibration matrix K}
-\cvarg{rotMatr}{The output 3x3 external rotation matrix R}
-\cvarg{posVect}{The output 4x1 external homogenious position vector C}
+\cvarg{projMatrix}{The 3x4 input projection matrix P}
+\cvarg{cameraMatrix}{The output 3x3 camera matrix K}
+\cvarg{rotMatrix}{The output 3x3 external rotation matrix R}
+\cvarg{transVect}{The output 4x1 translation vector T}
 \cvarg{rotMatrX}{Optional 3x3 rotation matrix around x-axis}
 \cvarg{rotMatrY}{Optional 3x3 rotation matrix around y-axis}
 \cvarg{rotMatrZ}{Optional 3x3 rotation matrix around z-axis}
@@ -369,42 +533,54 @@ The function computes a decomposition of a projection matrix into a calibration
 
 It optionally returns three rotation matrices, one for each axis, and the three Euler angles that could be used in OpenGL.
 
+The function is based on \cvCross{RQDecomp3x3}{RQDecomp3x3}.
 
-\cvCPyFunc{DrawChessBoardCorners}
+\ifCPy
+\cvCPyFunc{DrawChessboardCorners}
+\else
+\cvCppFunc{drawChessboardCorners}
+\fi
 Renders the detected chessboard corners.
 
 \cvdefC{
-void cvDrawChessboardCorners( \par CvArr* image,\par CvSize pattern\_size,\par CvPoint2D32f* corners,\par int count,\par int pattern\_was\_found );
-}\cvdefPy{DrawChessboardCorners(image,pattern\_size,corners,pattern\_was\_found)-> None}
-
+void cvDrawChessboardCorners( \par CvArr* image,\par CvSize patternSize,\par CvPoint2D32f* corners,\par int count,\par int patternWasFound );
+}\cvdefPy{DrawChessboardCorners(image,patternSize,corners,patternWasFound)-> None}
+\cvdefCpp{void drawChessboardCorners( Mat\& image, Size patternSize,\par
+                            const Mat\& corners,\par
+                            bool patternWasFound );}
 \begin{description}
 \cvarg{image}{The destination image; it must be an 8-bit color image}
-\cvarg{pattern\_size}{The number of inner corners per chessboard row and column. ( pattern\_size = cvSize(points\_per\_row,points\_per\_colum) = cvSize(columns,rows) )}
+\cvarg{patternSize}{The number of inner corners per chessboard row and column. (patternSize = cvSize(points\_per\_row,points\_per\_colum) = cvSize(columns,rows) )}
 \cvarg{corners}{The array of corners detected}
-\cvarg{count}{The number of corners}
-\cvarg{pattern\_was\_found}{Indicates whether the complete board was found $(\ne 0)$ or not $(=0)$. One may just pass the return value \cvCPyCross{FindChessboardCorners} here}
+\cvC{\cvarg{count}{The number of corners}}
+\cvarg{patternWasFound}{Indicates whether the complete board was found \cvCPy{$(\ne 0)$} or not \cvCPy{$(=0)$}. One may just pass the return value \cvCPyCross{FindChessboardCorners}{findChessboardCorners} here}
 \end{description}
 
-The function draws the individual chessboard corners detected as red circles if the board was not found $(\texttt{pattern\_was\_found} =0)$ or as colored corners connected with lines if the board was found $(\texttt{pattern\_was\_found} \ne 0)$.
-
+The function draws the individual chessboard corners detected as red circles if the board was not found or as colored corners connected with lines if the board was found.
 
+\ifCPy
 \cvCPyFunc{FindChessboardCorners}
+\else
+\cvCppFunc{findChessboardCorners}
+\fi
 Finds the positions of the internal corners of the chessboard.
 
-\cvdefC{
-int cvFindChessboardCorners( \par const void* image,\par CvSize pattern\_size,\par CvPoint2D32f* corners,\par int* corner\_count=NULL,\par int flags=CV\_CALIB\_CB\_ADAPTIVE\_THRESH );
-}\cvdefPy{FindChessboardCorners(image, pattern\_size, flags=CV\_CALIB\_CB\_ADAPTIVE\_THRESH) -> corners}
-
+\cvdefC{int cvFindChessboardCorners( \par const void* image,\par CvSize patternSize,\par CvPoint2D32f* corners,\par int* cornerCount=NULL,\par int flags=CV\_CALIB\_CB\_ADAPTIVE\_THRESH );}
+\cvdefPy{FindChessboardCorners(image, patternSize, flags=CV\_CALIB\_CB\_ADAPTIVE\_THRESH) -> corners}
+\cvdefCpp{bool findChessboardCorners( const Mat\& image, Size patternSize,\par
+                            vector<Point2f>\& corners,\par
+                            int flags=CV\_CALIB\_CB\_ADAPTIVE\_THRESH+\par
+                                 CV\_CALIB\_CB\_NORMALIZE\_IMAGE );}
 \begin{description}
 \cvarg{image}{Source chessboard view; it must be an 8-bit grayscale or color image}
-\cvarg{pattern\_size}{The number of inner corners per chessboard row and column}
-( pattern\_size = cvSize(points\_per\_row,points\_per\_colum) = cvSize(columns,rows) )
+\cvarg{patternSize}{The number of inner corners per chessboard row and column
+( patternSize = cvSize(points\_per\_row,points\_per\_colum) = cvSize(columns,rows) )}
 \cvarg{corners}{The output array of corners detected}
-\cvC{\cvarg{corner\_count}{The output corner counter. If it is not NULL, it stores the number of corners found}}
+\cvC{\cvarg{cornerCount}{The output corner counter. If it is not NULL, it stores the number of corners found}}
 \cvarg{flags}{Various operation flags, can be 0 or a combination of the following values:
 \begin{description}
  \cvarg{CV\_CALIB\_CB\_ADAPTIVE\_THRESH}{use adaptive thresholding to convert the image to black and white, rather than a fixed threshold level (computed from the average image brightness).}
- \cvarg{CV\_CALIB\_CB\_NORMALIZE\_IMAGE}{normalize the image using \cvCPyCross{NormalizeHist} before applying fixed or adaptive thresholding.}
+ \cvarg{CV\_CALIB\_CB\_NORMALIZE\_IMAGE}{normalize the image gamma with \cvCross{EqualizeHist}{equalizeHist} before applying fixed or adaptive thresholding.}
  \cvarg{CV\_CALIB\_CB\_FILTER\_QUADS}{use additional criteria (like contour area, perimeter, square-like shape) to filter out false quads that are extracted at the contour retrieval stage.}
 \end{description}}
 \end{description}
@@ -419,37 +595,58 @@ them, it returns 0. For example, a regular chessboard has 8 x 8
 squares and 7 x 7 internal corners, that is, points, where the black
 squares touch each other. The coordinates detected are approximate,
 and to determine their position more accurately, the user may use
-the function \cvCPyCross{FindCornerSubPix}.
+the function \cvCross{FindCornerSubPix}{cornerSubPix}.
 
-\cvCPyFunc{FindExtrinsicCameraParams2}
-Finds the extrinsic camera parameters for a particular view.
+\textbf{Note:} the function requires some white space (like a square-thick border, the wider the better) around the board to make the detection more robust in various environment (otherwise if there is no border and the background is dark, the outer black squares could not be segmented properly and so the square grouping and ordering algorithm will fail).
 
-\cvdefC{
-void cvFindExtrinsicCameraParams2( \par const CvMat* object\_points,\par const CvMat* image\_points,\par const CvMat* intrinsic\_matrix,\par const CvMat* distortion\_coeffs,\par CvMat* rotation\_vector,\par CvMat* translation\_vector );
-}\cvdefPy{FindExtrinsicCameraParams2(object\_points,image\_points,intrinsic\_matrix,distortion\_coeffs,rotation\_vector,translation\_vector)-> None}
+\ifCPy
+\cvCPyFunc{FindExtrinsicCameraParams2}
+\else
+\cvCppFunc{solvePnP}
+\fi
+Finds the object pose from the 3D-2D point correspondences
 
+\cvdefC{void cvFindExtrinsicCameraParams2( \par const CvMat* objectPoints,\par const CvMat* imagePoints,\par const CvMat* cameraMatrix,\par const CvMat* distCoeffs,\par CvMat* rvec,\par CvMat* tvec );}
+\cvdefPy{FindExtrinsicCameraParams2(objectPoints,imagePoints,cameraMatrix,distCoeffs,rvec,tvec)-> None}
+\cvdefCpp{void solvePnP( const Mat\& objectPoints,\par
+               const Mat\& imagePoints,\par
+               const Mat\& cameraMatrix,\par
+               const Mat\& distCoeffs,\par
+               Mat\& rvec, Mat\& tvec,\par
+               bool useExtrinsicGuess=false );}
 \begin{description}
-\cvarg{object\_points}{The array of object points, 3xN or Nx3, where N is the number of points in the view}
-\cvarg{image\_points}{The array of corresponding image points, 2xN or Nx2, where N is the number of points in the view}
-\cvarg{intrinsic\_matrix}{The input camera matrix $A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1} $}
-\cvarg{distortion\_coeffs}{The input 4x1 or 1x4 vector of distortion coefficients $k_1, k_2, k_3, k_4$. If it is NULL, all of the distortion coefficients are set to 0}
-\cvarg{rotation\_vector}{The output 3x1 or 1x3 rotation vector (compact representation of a rotation matrix, \cvCPyCross{Rodrigues2}}
-\cvarg{translation\_vector}{The output 3x1 or 1x3 translation vector}
+\cvarg{objectPoints}{The array of object points in the object coordinate space, 3xN or Nx3 1-channel, or 1xN or Nx1 3-channel, where N is the number of points. \cvCpp{Can also pass \texttt{vector<Point3f>} here.}}
+\cvarg{imagePoints}{The array of corresponding image points, 2xN or Nx2 1-channel or 1xN or Nx1 2-channel, where N is the number of points. \cvCpp{Can also pass \texttt{vector<Point2f>} here.}}
+\cvarg{cameraMatrix}{The input camera matrix $A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1} $}
+\cvarg{distCoeffs}{The input 4x1, 1x4, 5x1 or 1x5 vector of distortion coefficients $(k_1, k_2, p_1, p_2[, k_3])$. If it is NULL, all of the distortion coefficients are set to 0}
+\cvarg{rvec}{The output rotation vector (see \cvCross{Rodrigues2}{Rodrigues}) that (together with \texttt{tvec}) brings points from the model coordinate system to the camera coordinate system}
+\cvarg{tvec}{The output translation vector}
 \end{description}
 
-The function estimates the extrinsic camera parameters using known intrinsic parameters and extrinsic parameters for each view. The coordinates of 3D object points and their correspondent 2D projections must be specified. This function also minimizes back-projection error.
+The function estimates the object pose given a set of object points, their corresponding image projections, as well as the camera matrix and the distortion coefficients. This function finds such a pose that minimizes reprojection error, i.e. the sum of squared distances between the observed projections \texttt{imagePoints} and the projected (using \cvCross{ProjectPoints2}{projectPoints}) \texttt{objectPoints}.
 
+\ifCPy
 \cvCPyFunc{FindFundamentalMat}
+\else
+\cvCppFunc{findFundamentalMat}
+\fi
+
 Calculates the fundamental matrix from the corresponding points in two images.
 
 \cvdefC{
-int cvFindFundamentalMat( \par const CvMat* points1,\par const CvMat* points2,\par CvMat* fundamental\_matrix,\par int    method=CV\_FM\_RANSAC,\par double param1=1.,\par double param2=0.99,\par CvMat* status=NULL);
-}\cvdefPy{FindFundamentalMat(points1, points2, fundamental\_matrix, method=CV\_FM\_RANSAC, param1=1., double param2=0.99, status = None) -> None}
-
+int cvFindFundamentalMat( \par const CvMat* points1,\par const CvMat* points2,\par CvMat* fundamentalMatrix,\par int    method=CV\_FM\_RANSAC,\par double param1=1.,\par double param2=0.99,\par CvMat* status=NULL);
+}
+\cvdefPy{FindFundamentalMat(points1, points2, fundamentalMatrix, method=CV\_FM\_RANSAC, param1=1., param2=0.99, status = None) -> None}
+\cvdefCpp{Mat findFundamentalMat( const Mat\& points1, const Mat\& points2,\par
+                        vector<uchar>\& status, int method=FM\_RANSAC,\par
+                        double param1=3., double param2=0.99 );\newline
+Mat findFundamentalMat( const Mat\& points1, const Mat\& points2,\par
+                        int method=FM\_RANSAC,\par
+                        double param1=3., double param2=0.99 );}
 \begin{description}
-\cvarg{points1}{Array of the first image points of \texttt{2xN, Nx2, 3xN} or \texttt{Nx3} size (where \texttt{N} is number of points). Multi-channel \texttt{1xN} or \texttt{Nx1} array is also acceptable. The point coordinates should be floating-point (single or double precision)}
+\cvarg{points1}{Array of \texttt{N} points from the first image.\cvCPy{It can be \texttt{2xN, Nx2, 3xN} or \texttt{Nx3} 1-channel array or  \texttt{1xN} or \texttt{Nx1} 2- or 3-channel array}. The point coordinates should be floating-point (single or double precision)}
 \cvarg{points2}{Array of the second image points of the same size and format as \texttt{points1}}
-\cvarg{fundamental\_matrix}{The output fundamental matrix or matrices. The size should be 3x3 or 9x3 (7-point method may return up to 3 matrices)}
+\cvCPy{\cvarg{fundamentalMatrix}{The output fundamental matrix or matrices. The size should be 3x3 or 9x3 (7-point method may return up to 3 matrices)}}
 \cvarg{method}{Method for computing the fundamental matrix
 \begin{description}
   \cvarg{CV\_FM\_7POINT}{for a 7-point algorithm. $N = 7$}
@@ -457,26 +654,25 @@ int cvFindFundamentalMat( \par const CvMat* points1,\par const CvMat* points2,\p
   \cvarg{CV\_FM\_RANSAC}{for the RANSAC algorithm. $N \ge 8$}
   \cvarg{CV\_FM\_LMEDS}{for the LMedS algorithm. $N \ge 8$}
 \end{description}}
-\cvarg{param1}{The parameter is used for RANSAC or LMedS methods only. It is the maximum distance from point to epipolar line in pixels, beyond which the point is considered an outlier and is not used for computing the final fundamental matrix. Usually it is set to 0.5 or 1.0}
-\cvarg{param2}{The parameter is used for RANSAC or LMedS methods only. It denotes the desirable level of confidence that the matrix is correct}
-\cvarg{status}{The optional output array of N elements, every element of which is set to 0 for outliers and to 1 for the other points. The array is computed only in RANSAC and LMedS methods. For other methods it is set to 1}
+\cvarg{param1}{The parameter is used for RANSAC. It is the maximum distance from point to epipolar line in pixels, beyond which the point is considered an outlier and is not used for computing the final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the point localization, image resolution and the image noise}
+\cvarg{param2}{The parameter is used for RANSAC or LMedS methods only. It specifies the desirable level of confidence (probability) that the estimated matrix is correct}
+\cvarg{status}{The \cvCPy{optional} output array of N elements, every element of which is set to 0 for outliers and to 1 for the other points. The array is computed only in RANSAC and LMedS methods. For other methods it is set to all 1's}
 \end{description}
 
 The epipolar geometry is described by the following equation:
 
-\[ p_2^T F p1=0 \]
+\[ [p_2; 1]^T F [p_1; 1] = 0 \]
 
 where $F$ is fundamental matrix, $p_1$ and $p_2$ are corresponding points in the first and the second images, respectively.
 
-The function calculates the fundamental
-matrix using one of four methods listed above and returns the number
-of fundamental matrices found (1 or 3) and 0, if no matrix is found.
+The function calculates the fundamental matrix using one of four methods listed above and returns \cvCpp{the found fundamental matrix}\cvCPy{the number of fundamental matrices found (1 or 3) and 0, if no matrix is found}. Normally just 1 matrix is found, but in the case of 7-point algorithm the function may return up to 3 solutions ($9 \times 3$ matrix that stores all 3 matrices sequentially).
 
 The calculated fundamental matrix may be passed further to
-\texttt{cvComputeCorrespondEpilines} that finds the epipolar lines
-corresponding to the specified points.
+\cvCross{ComputeCorrespondEpilines}{computeCorrespondEpilines} that finds the epipolar lines
+corresponding to the specified points. It can also be passed to \cvCross{StereoRectifyUncalibrated}{stereoRectifyUncalibrated} to compute the rectification transformation.
 
-\cvfunc{Example. Estimation of fundamental matrix using RANSAC algorithm}
+\ifC
+% Example. Estimation of fundamental matrix using RANSAC algorithm
 \begin{lstlisting}
 int point_count = 100;
 CvMat* points1;
@@ -501,36 +697,72 @@ fundamental_matrix = cvCreateMat(3,3,CV_32FC1);
 int fm_count = cvFindFundamentalMat( points1,points2,fundamental_matrix,
                                      CV_FM_RANSAC,1.0,0.99,status );
 \end{lstlisting}
+\fi
+\ifCpp
+\begin{lstlisting}
+// Example. Estimation of fundamental matrix using RANSAC algorithm
+int point_count = 100;
+vector<Point2f> points1(point_count);
+vector<Point2f> points2(point_count);
+
+// initialize the points here ... */
+for( int i = 0; i < point_count; i++ )
+{
+    points1[i] = ...;
+    points2[i] = ...;
+}
+
+Mat fundamental_matrix =
+ findFundamentalMat(points1, points2, FM_RANSAC, 3, 0.99);
+\end{lstlisting}
+\fi
 
+\ifCPy
 \cvCPyFunc{FindHomography}
+\else
+\cvCppFunc{findHomography}
+\fi
 Finds the perspective transformation between two planes.
 
-\cvdefC{
-void cvFindHomography( \par const CvMat* src\_points,\par const CvMat* dst\_points,\par CvMat* homography \par
-int method=0, \par double ransacReprojThreshold=0, \par CvMat* mask=NULL);
-}\cvdefPy{FindHomography(src\_points,dst\_points)-> homography}
+\cvdefC{void cvFindHomography( \par const CvMat* srcPoints,\par const CvMat* dstPoints,\par CvMat* H \par
+int method=0, \par double ransacReprojThreshold=0, \par CvMat* status=NULL);}
+\cvdefPy{FindHomography(srcPoints,dstPoints,H,method,ransacReprojThreshold=0.0, status=None)-> H}
+\cvdefCpp{Mat findHomography( const Mat\& srcPoints, const Mat\& dstPoints,\par
+                    Mat\& status, int method=0,\par
+                    double ransacReprojThreshold=0 );\newline
+Mat findHomography( const Mat\& srcPoints, const Mat\& dstPoints,\par
+                    vector<uchar>\& status, int method=0,\par
+                    double ransacReprojThreshold=0 );\newline
+Mat findHomography( const Mat\& srcPoints, const Mat\& dstPoints,\par
+                    int method=0, double ransacReprojThreshold=0 );}
 
 \begin{description}
-\cvarg{src\_points}{Point coordinates in the original plane, 2xN, Nx2, 3xN or Nx3 array (the latter two are for representation in homogenious coordinates), where N is the number of points}
-\cvarg{dst\_points}{Point coordinates in the destination plane, 2xN, Nx2, 3xN or Nx3 array (the latter two are for representation in homogenious coordinates)}
-\cvarg{homography}{Output 3x3 homography matrix}
+
+\cvCPy{\cvarg{srcPoints}{Coordinates of the points in the original plane, 2xN, Nx2, 3xN or Nx3 1-channel array (the latter two are for representation in homogeneous coordinates), where N is the number of points. 1xN or Nx1 2- or 3-channel array can also be passed.}
+\cvarg{dstPoints}{Point coordinates in the destination plane, 2xN, Nx2, 3xN or Nx3 1-channel, or 1xN or Nx1 2- or 3-channel array.}}
+\cvCpp{\cvarg{srcPoints}{Coordinates of the points in the original plane, a matrix of type \texttt{CV\_32FC2} or a \texttt{vector<Point2f>}.}
+\cvarg{dstPoints}{Coordinates of the points in the target plane, a matrix of type \texttt{CV\_32FC2} or a \texttt{vector<Point2f>}.}}
+
+\cvCPy{\cvarg{H}{The output 3x3 homography matrix}}
 \cvarg{method}{ The method used to computed homography matrix; one of the following:
 \begin{description}
-\cvarg{0}{regular method using all the point pairs}
+\cvarg{0}{a regular method using all the points}
 \cvarg{CV\_RANSAC}{RANSAC-based robust method}
 \cvarg{CV\_LMEDS}{Least-Median robust method}
 \end{description}}
-\cvarg{ransacReprojThreshold}{The maximum allowed reprojection error to treat a point pair as an inlier. The parameter is only used in RANSAC-based homography estimation. E.g. if \texttt{dst\_points} coordinates are measured in pixels with pixel-accurate precision, it makes sense to set this parameter somewhere in the range 1 to 3. }
-\cvarg{mask}{The optional output mask set by a robust method (\texttt{CV\_RANSAC} or \texttt{CV\_LMEDS}).}
+\cvarg{ransacReprojThreshold}{The maximum allowed reprojection error to treat a point pair as an inlier (used in the RANSAC method only). That is, if
+\[\|\texttt{dstPoints}_i - \texttt{convertPointHomogeneous}(\texttt{H} \texttt{srcPoints}_i)\| > \texttt{ransacReprojThreshold}\]
+then the point $i$ is considered an outlier. If \texttt{srcPoints} and \texttt{dstPoints} are measured in pixels, it usually makes sense to set this parameter somewhere in the range 1 to 10.}
+\cvarg{status}{The optional output mask set by a robust method (\texttt{CV\_RANSAC} or \texttt{CV\_LMEDS}). \emph{Note that the input mask values are ignored.}}
 \end{description}
 
-The function finds the perspective transformation $H$ between the source and the destination planes:
+The \cvCPy{function finds}\cvCpp{functions find and return} the perspective transformation $H$ between the source and the destination planes:
 
 \[
 s_i \vecthree{x'_i}{y'_i}{1} \sim H \vecthree{x_i}{y_i}{1}
 \]
 
-So that the back-projection error is minimized:
+So that the back-projection error
 
 \[
 \sum_i
@@ -538,36 +770,41 @@ So that the back-projection error is minimized:
 \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
 \]
 
-If the parameter method is set to the default value 0, the function
-uses all the point pairs and estimates the best suitable homography
-matrix. However, if not all of the point pairs ($src\_points_i$,
-$dst\_points_i$) fit the rigid perspective transformation (i.e. there
-can be outliers), it is still possible to estimate the correct
-transformation using one of the robust methods available. Both
-methods, \texttt{CV\_RANSAC} and \texttt{CV\_LMEDS}, try many different random subsets
-of the corresponding point pairs (of 5 pairs each), estimate
+is minimized. If the parameter \texttt{method} is set to the default value 0, the function
+uses all the point pairs to compute the initial homography estimate with a simple least-squares scheme.
+
+However, if not all of the point pairs ($srcPoints_i$,
+$dstPoints_i$) fit the rigid perspective transformation (i.e. there
+are some outliers), this initial estimate will be poor.
+In this case one can use one of the 2 robust methods. Both methods,
+\texttt{RANSAC} and \texttt{LMeDS}, try many different random subsets
+of the corresponding point pairs (of 4 pairs each), estimate
 the homography matrix using this subset and a simple least-square
 algorithm and then compute the quality/goodness of the computed homography
-(which is the number of inliers for RANSAC or the median reprojection
+(which is the number of inliers for RANSAC or the median re-projection
 error for LMeDs). The best subset is then used to produce the initial
 estimate of the homography matrix and the mask of inliers/outliers.
 
 Regardless of the method, robust or not, the computed homography
 matrix is refined further (using inliers only in the case of a robust
 method) with the Levenberg-Marquardt method in order to reduce the
-reprojection error even more.
+re-projection error even more.
 
-The method \texttt{CV\_RANSAC} can handle practically any ratio of outliers,
+The method \texttt{RANSAC} can handle practically any ratio of outliers,
 but it needs the threshold to distinguish inliers from outliers.
-The method \texttt{CV\_LMEDS} does not need any threshold, but it works
+The method \texttt{LMeDS} does not need any threshold, but it works
 correctly only when there are more than 50\% of inliers. Finally,
-if you are sure in the computed features and there can be only some
-small noise, but no outliers, the default method could be the best
+if you are sure in the computed features, where can be only some
+small noise present, but no outliers, the default method could be the best
 choice.
 
 The function is used to find initial intrinsic and extrinsic matrices.
-Homography matrix is determined up to a scale, thus it is normalized
-to make $h_{33} =1$.
+Homography matrix is determined up to a scale, thus it is normalized so that
+$h_{33}=1$.
+
+See also: \cvCross{GetAffineTransform}{getAffineTransform}, \cvCross{GetPerspectiveTransform}{getPerspectiveTransform}, \cvCross{EstimateRigidMotion}{estimateRigidMotion}, \cvCross{WarpPerspective}{warpPerspective}, \cvCross{PerspectiveTransform}{perspectiveTransform}
+
+\ifCPy
 
 \cvCPyFunc{FindStereoCorrespondenceBM}
 Computes the disparity map using block matching algorithm.
@@ -582,11 +819,11 @@ void cvFindStereoCorrespondenceBM( \par const CvArr* left, \par const CvArr* rig
 \begin{description}
 \cvarg{left}{The left single-channel, 8-bit image.}
 \cvarg{right}{The right image of the same size and the same type.}
-\cvarg{disparity}{The output single-channel 16-bit signed disparity map of the same size as input images. Its elements will be the computed disparities, multiplied by 16 and rounded to integers.}
+\cvarg{disparity}{The output single-channel 16-bit signed, or 32-bit floating-point disparity map of the same size as input images. In the first case the computed disparities are represented as fixed-point numbers with 4 fractional bits (i.e. the computed disparity values are multiplied by 16 and rounded to integers).}
 \cvarg{state}{Stereo correspondence structure.}
 \end{description}
 
-The function cvFindStereoCorrespondenceBM computes disparity map for the input rectified stereo pair.
+The function cvFindStereoCorrespondenceBM computes disparity map for the input rectified stereo pair. Invalid pixels (for which disparity can not be computed) are set to \texttt{state->minDisparity - 1} (or to \texttt{(state->minDisparity-1)*16} in the case of 16-bit fixed-point disparity map)
 
 \cvCPyFunc{FindStereoCorrespondenceGC}
 Computes the disparity map using graph cut-based algorithm.
@@ -598,7 +835,8 @@ void cvFindStereoCorrespondenceGC( \par const CvArr* left, \par const CvArr* rig
                                    \par CvStereoGCState* state,
                                    \par int useDisparityGuess = CV\_DEFAULT(0) );
 
-}\cvdefPy{FindStereoCorrespondenceGC(\par left,\par right,\par dispLeft,\par dispRight,\par state,\par useDisparityGuess=CV\_DEFAULT(0))-> None}
+}
+\cvdefPy{FindStereoCorrespondenceGC( left, right, dispLeft, dispRight, state, useDisparityGuess=(0))-> None}
 
 \begin{description}
 \cvarg{left}{The left single-channel, 8-bit image.}
@@ -638,8 +876,9 @@ that is, the range for the left disparity image will be inversed,
 and the pixels for which no good match has been found, will be marked
 as occlusions.
 
-Here is how the function can be called:
+Here is how the function can be used:
 
+\ifC
 \begin{lstlisting}
 // image_left and image_right are the input 8-bit single-channel images
 // from the left and the right cameras, respectively
@@ -653,739 +892,424 @@ cvReleaseStereoGCState( &state );
 // now process the computed disparity images as you want ...
 \end{lstlisting}
 
-and this is the output left disparity image computed from the well-known Tsukuba stereo pair and multiplied by -16 (because the values in the left disparity images are usually negative): 
+and this is the output left disparity image computed from the well-known
+Tsukuba stereo pair and multiplied by -16 (because the values in the
+left disparity images are usually negative):
 
 \begin{lstlisting}
 CvMat* disparity_left_visual = cvCreateMat( size.height, size.width, CV_8U );
 cvConvertScale( disparity_left, disparity_left_visual, -16 );
-cvSave( "disparity.png", disparity_left_visual );
+cvSave( "disparity.pgm", disparity_left_visual );
 \end{lstlisting}
 
 \includegraphics{pics/disparity.png}
 
-\cvCPyFunc{POSIT}
-Implements the POSIT algorithm.
+\else
 
-\cvdefC{
-void cvPOSIT( \par CvPOSITObject* posit\_object,\par CvPoint2D32f* image\_points,\par double focal\_length,\par CvTermCriteria criteria,\par CvMatr32f rotation\_matrix,\par CvVect32f translation\_vector );
-}\cvdefPy{POSIT(posit\_object,image\_points,focal\_length,criteria)-> rotation\_matrix,translation\_vector}
+\lstinputlisting{python_fragments/findstereocorrespondence.py}
 
-\begin{description}
-\cvarg{posit\_object}{Pointer to the object structure}
-\cvarg{image\_points}{Pointer to the object points projections on the 2D image plane}
-\cvarg{focal\_length}{Focal length of the camera used}
-\cvarg{criteria}{Termination criteria of the iterative POSIT algorithm}
-\cvarg{rotation\_matrix}{Matrix of rotations}
-\cvarg{translation\_vector}{Translation vector}
-\end{description}
+and this is the output left disparity image computed from the well-known
+Tsukuba stereo pair and multiplied by -16 (because the values in the
+left disparity images are usually negative):
 
-The function implements the POSIT algorithm. Image coordinates are given in a camera-related coordinate system. The focal length may be retrieved using the camera calibration functions. At every iteration of the algorithm a new perspective projection of the estimated pose is computed.
+\includegraphics{pics/disparity.png}
 
-Difference norm between two projections is the maximal distance between corresponding points. The parameter \texttt{criteria.epsilon} serves to stop the algorithm if the difference is small.
+\fi
 
-\ifC
-\cvCPyFunc{ProjectPoints2}
-Projects 3D points on to an image plane.
+\fi
 
-\cvdefC{
-void cvProjectPoints2( \par const CvMat* object\_points,\par const CvMat* rotation\_vector,\par const CvMat* translation\_vector,\par const CvMat* intrinsic\_matrix,\par const CvMat* distortion\_coeffs,\par CvMat* image\_points,\par CvMat* dpdrot=NULL,\par CvMat* dpdt=NULL,\par CvMat* dpdf=NULL,\par CvMat* dpdc=NULL,\par CvMat* dpddist=NULL );
-}\cvdefPy{ProjectPoints2(object\_points,rotation\_vector,translation\_vector,intrinsic\_matrix,distortion\_coeffs, image\_points,dpdrot=NULL,dpdt=NULL,dpdf=NULL,dpdc=NULL,dpddist=NULL)-> None}
+\ifCpp
+\cvCppFunc{getDefaultNewCameraMatrix}
+Returns the default new camera matrix
 
+\cvdefCpp{Mat getDefaultNewCameraMatrix(\par
+                               const Mat\& cameraMatrix,\par
+                               Size imgSize=Size(),\par
+                               bool centerPrincipalPoint=false );}
 \begin{description}
-\cvarg{object\_points}{The array of object points, 3xN or Nx3, where N is the number of points in the view}
-\cvarg{rotation\_vector}{The rotation vector, 1x3 or 3x1}
-\cvarg{translation\_vector}{The translation vector, 1x3 or 3x1}
-\cvarg{intrinsic\_matrix}{The camera matrix $A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1} $}
-\cvarg{distortion\_coeffs}{The vector of distortion coefficients, 4x1 or 1x4 $k_1, k_2, k_3, k_4$. If it is \texttt{NULL}, all of the distortion coefficients are considered 0's}
-\cvarg{image\_points}{The output array of image points, 2xN or Nx2, where N is the total number of points in the view}
-\cvarg{dpdrot}{Optional Nx3 matrix of derivatives of image points with respect to components of the rotation vector}
-\cvarg{dpdt}{Optional Nx3 matrix of derivatives of image points with respect to components of the translation vector}
-\cvarg{dpdf}{Optional Nx2 matrix of derivatives of image points with respect to $fx$ and $fy$}
-\cvarg{dpdc}{Optional Nx2 matrix of derivatives of image points with respect to $cx$ and $cy$}
-\cvarg{dpddist}{Optional Nx4 matrix of derivatives of image points with respect to distortion coefficients}
+\cvarg{cameraMatrix}{The input camera matrix}
+\cvarg{imageSize}{The camera view image size in pixels}
+\cvarg{centerPrincipalPoint}{Indicates whether in the new camera matrix the principal point should be at the image center or not}
 \end{description}
 
-The function computes projections of 3D
-points to the image plane given intrinsic and extrinsic camera
-parameters. Optionally, the function computes jacobians - matrices
-of partial derivatives of image points as functions of all the
-input parameters with respect to the particular parameters, intrinsic and/or
-extrinsic. The jacobians are used during the global optimization
-in \cvCPyCross{CalibrateCamera2} and
-\cvCPyCross{FindExtrinsicCameraParams2}. The
-function itself is also used to compute back-projection error for with
-current intrinsic and extrinsic parameters.
-
-Note, that with intrinsic and/or extrinsic parameters set to special
-values, the function can be used to compute just an extrinsic transformation
-or just an intrinsic transformation (i.e. distortion of a sparse set
-of points).
-
-\cvCPyFunc{RQDecomp3x3}
-Computes the `RQ' decomposition of 3x3 matrices.
-
-\cvdefC{
-void cvRQDecomp3x3( \par const CvMat *matrixM,\par CvMat *matrixR,\par CvMat *matrixQ,\par CvMat *matrixQx=NULL,\par CvMat *matrixQy=NULL,\par CvMat *matrixQz=NULL,\par CvPoint3D64f *eulerAngles=NULL);
-}\cvdefPy{RQDecomp3x3(matrixM, matrixR, matrixQ, matrixQx = None, matrixQy = None, matrixQz = None) -> eulerAngles}
-
-\begin{description}
-\cvarg{matrixM}{The 3x3 input matrix M}
-\cvarg{matrixR}{The output 3x3 upper-triangular matrix R}
-\cvarg{matrixQ}{The output 3x3 orthogonal matrix Q}
-\cvarg{matrixQx}{Optional 3x3 rotation matrix around x-axis}
-\cvarg{matrixQy}{Optional 3x3 rotation matrix around y-axis}
-\cvarg{matrixQz}{Optional 3x3 rotation matrix around z-axis}
-\cvarg{eulerAngles}{Optional 3 points containing the three Euler angles of rotation}
-\end{description}
-
-The function computes a RQ decomposition using the given rotations. This function is used in \cvCPyCross{DecomposeProjectionMatrix} to decompose the left 3x3 submatrix of a projection matrix into a calibration and a rotation matrix.
-
-It optionally returns three rotation matrices, one for each axis, and the three Euler angles that could be used in OpenGL.
-
+The function returns the camera matrix that is either an exact copy of the input \texttt{cameraMatrix} (when \texttt{centerPrinicipalPoint=false}), or the modified one (when \texttt{centerPrincipalPoint}=true).
 
-\cvCPyFunc{ReleasePOSITObject}
-Deallocates a 3D object structure.
+In the latter case the new camera matrix will be:
 
-\cvdefC{
-void cvReleasePOSITObject( \par CvPOSITObject** posit\_object );
-}
+\[\begin{bmatrix}
+f_x && 0 && (\texttt{imgSize.width}-1)*0.5 \\
+0 && f_y && (\texttt{imgSize.height}-1)*0.5 \\
+0 && 0 && 1
+\end{bmatrix},\]
 
-\begin{description}
-\cvarg{posit\_object}{Double pointer to \texttt{CvPOSIT} structure}
-\end{description}
+where $f_x$ and $f_y$ are $(0,0)$ and $(1,1)$ elements of \texttt{cameraMatrix}, respectively.
 
-The function releases memory previously allocated by the function \cvCPyCross{CreatePOSITObject}.
+By default, the undistortion functions in OpenCV (see \texttt{initUndistortRectifyMap}, \texttt{undistort}) do not move the principal point. However, when you work with stereo, it's important to move the principal points in both views to the same y-coordinate (which is required by most of stereo correspondence algorithms), and maybe to the same x-coordinate too. So you can form the new camera matrix for each view, where the principal points will be at the center.
 
 \fi
 
-\cvCPyFunc{ReleaseStereoBMState}
-Releases block matching stereo correspondence structure.
-
-\cvdefC{
-
-void cvReleaseStereoBMState( CvStereoBMState** state );
-
-}\cvdefPy{ReleaseStereoBMState(state)-> None}
-
+\ifCPy
+\cvCPyFunc{GetOptimalNewCameraMatrix}
+\else
+\cvCppFunc{getOptimalNewCameraMatrix}
+\fi
+Returns the new camera matrix based on the free scaling parameter
+
+\cvdefC{void cvGetOptimalNewCameraMatrix(
+    \par const CvMat* cameraMatrix, const CvMat* distCoeffs,
+    \par CvSize imageSize, double alpha,
+    \par CvMat* newCameraMatrix,
+    \par CvSize newImageSize=cvSize(0,0),
+    \par CvRect* validPixROI=0 );}
+\cvdefPy{GetOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, alpha, newCameraMatrix, newImageSize=(0,0), validPixROI=0) -> None}
+\cvdefCpp{Mat getOptimalNewCameraMatrix(
+    \par const Mat\& cameraMatrix, const Mat\& distCoeffs,
+    \par Size imageSize, double alpha, Size newImageSize=Size(),
+    \par Rect* validPixROI=0);}
+    
 \begin{description}
-\cvarg{state}{Double pointer to the released structure.}
+\cvarg{cameraMatrix}{The input camera matrix}
+\cvarg{distCoeffs}{The input 4x1, 1x4, 5x1 or 1x5 vector of distortion coefficients $(k_1, k_2, p_1, p_2[, k_3])$}.
+\cvarg{imageSize}{The original image size}
+\cvarg{alpha}{The free scaling parameter between 0 (when all the pixels in the undistorted image will be valid) and 1 (when all the source image pixels will be retained in the undistorted image); see \cvCross{StereoRectify}{stereoRectify}}
+\cvarg{newCameraMatrix}{The output new camera matrix.}
+\cvarg{newImageSize}{The image size after rectification. By default it will be set to \texttt{imageSize}.}
+\cvarg{validPixROI}{The optional output rectangle that will outline all-good-pixels region in the undistorted image. See \texttt{roi1, roi2} description in \cvCross{StereoRectify}{stereoRectify}}
 \end{description}
 
-The function releases the stereo correspondence structure and all the associated internal buffers. 
-
-\cvCPyFunc{ReleaseStereoGCState}
-Releases the state structure of the graph cut-based stereo correspondence algorithm.
-
-\cvdefC{
+The function computes \cvCpp{and returns} the optimal new camera matrix based on the free scaling parameter. By varying  this parameter the user may retrieve only sensible pixels \texttt{alpha=0}, keep all the original image pixels if there is valuable information in the corners \texttt{alpha=1}, or get something in between. When \texttt{alpha>0}, the undistortion result will likely have some black pixels corresponding to "virtual" pixels outside of the captured distorted image. The original camera matrix, distortion coefficients, the computed new camera matrix and the \texttt{newImageSize} should be passed to \cvCross{InitUndistortRectifyMap}{initUndistortRectifyMap} to produce the maps for \cvCross{Remap}{remap}.
 
-void cvReleaseStereoGCState( CvStereoGCState** state );
+\ifCPy
+\cvCPyFunc{InitIntrinsicParams2D}
+\else
+\cvCppFunc{initCameraMatrix2D}
+\fi
 
-}\cvdefPy{ReleaseStereoGCState(state)-> None}
+Finds the initial camera matrix from the 3D-2D point correspondences
 
+\cvdefC{void cvInitIntrinsicParams2D(\par const CvMat* objectPoints,
+                                     \par const CvMat* imagePoints,
+                                     \par const CvMat* npoints, CvSize imageSize,
+                                     \par CvMat* cameraMatrix,
+                                     \par double aspectRatio=1.);}                                     
+\cvdefPy{InitIntrinsicParams2D(objectPoints, imagePoints, npoints, imageSize, cameraMatrix, aspectRatio=1.) -> None}
+\cvdefCpp{Mat initCameraMatrix2D( const vector<vector<Point3f> >\& objectPoints,\par
+                        const vector<vector<Point2f> >\& imagePoints,\par
+                        Size imageSize, double aspectRatio=1.);}
 \begin{description}
-\cvarg{state}{Double pointer to the released structure.}
+\ifCPy
+\cvarg{objectPoints}{The joint array of object points; see \cvCross{CalibrateCamera2}{calibrateCamera}}
+\cvarg{imagePoints}{The joint array of object point projections; see \cvCross{CalibrateCamera2}{calibrateCamera}}
+\cvarg{npoints}{The array of point counts; see \cvCross{CalibrateCamera2}{calibrateCamera}}
+\fi    
+\ifCpp
+\cvarg{objectPoints}{The vector of vectors of the object points. See \cvCppCross{calibrateCamera}}
+\cvarg{imagePoints}{The vector of vectors of the corresponding image points. See \cvCppCross{calibrateCamera}}
+\fi
+\cvarg{imageSize}{The image size in pixels; used to initialize the principal point}
+\cvCPy{\cvarg{cameraMatrix}{The output camera matrix $\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}$}}
+\cvarg{aspectRatio}{If it is zero or negative, both $f_x$ and $f_y$ are estimated independently. Otherwise $f_x = f_y * \texttt{aspectRatio}$}
 \end{description}
 
-The function releases the stereo correspondence structure and all the associated internal buffers. 
-
+The function estimates and returns the initial camera matrix for camera calibration process.
+Currently, the function only supports planar calibration patterns, i.e. patterns where each object point has z-coordinate =0.
 
-\cvCPyFunc{Rodrigues2}
-Converts a rotation matrix to a rotation vector or vice versa.
+\ifCPy
+\cvCPyFunc{InitUndistortMap}
+Computes an undistortion map.
 
-\cvdefC{
-int  cvRodrigues2( \par const CvMat* src,\par CvMat* dst,\par CvMat* jacobian=0 );
-}\cvdefPy{Rodrigues2(src,dst,jacobian=0)-> None}
+\cvdefC{void cvInitUndistortMap( \par const CvMat* cameraMatrix,\par const CvMat* distCoeffs,\par CvArr* map1,\par CvArr* map2 );}
+\cvdefPy{InitUndistortMap(cameraMatrix,distCoeffs,map1,map2)-> None}
 
 \begin{description}
-\cvarg{src}{The input rotation vector (3x1 or 1x3) or rotation matrix (3x3)}
-\cvarg{dst}{The output rotation matrix (3x3) or rotation vector (3x1 or 1x3), respectively}
-\cvarg{jacobian}{Optional output Jacobian matrix, 3x9 or 9x3 - partial derivatives of the output array components with respect to the input array components}
+\cvarg{cameraMatrix}{The input camera matrix $A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1} $}
+\cvarg{distCoeffs}{The input 4x1, 1x4, 5x1 or 1x5 vector of distortion coefficients $(k_1, k_2, p_1, p_2[, k_3])$}.
+\cvarg{map1}{The first output map \cvCPy{of type \texttt{CV\_32FC1} or \texttt{CV\_16SC2} - the second variant is more efficient}}
+\cvarg{map2}{The second output map \cvCPy{of type \texttt{CV\_32FC1} or \texttt{CV\_16UC1} - the second variant is more efficient}}
 \end{description}
 
-The function converts a rotation vector to a rotation matrix or vice versa. A rotation vector is a compact representation of rotation matrix. Direction of the rotation vector is the rotation axis and the length of the vector is the rotation angle around the axis. The rotation matrix $R$, corresponding to the rotation vector $r$, is computed as following:
-
-\[
-\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}
-\]
+The function is a simplified variant of \cvCross{InitUndistortRectifyMap}{initUndistortRectifyMap} where the rectification transformation \texttt{R} is identity matrix and \texttt{newCameraMatrix=cameraMatrix}.
 
-Inverse transformation can also be done easily as
-
-\[
-\sin(\theta)
-\vecthreethree
-{0}{-r_z}{r_y}
-{r_z}{0}{-r_x}
-{-r_y}{r_x}{0}
-=
-\frac{R - R^T}{2}
-\]
-
-A rotation vector is a convenient representation of a rotation matrix
-as a matrix with only 3 degrees of freedom. The representation is
-used in the global optimization procedures inside
-\cvCPyCross{FindExtrinsicCameraParams2}
-and \cvCPyCross{CalibrateCamera2}.
-
-
-\cvCPyFunc{StereoCalibrate}
-Calibrates stereo camera.
-
-\cvdefC{
-
-void cvStereoCalibrate( \par const CvMat* object\_points, \par const CvMat* image\_points1,
-                        \par const CvMat* image\_points2, \par const CvMat* point\_counts,
-                        \par CvMat* camera\_matrix1, \par CvMat* dist\_coeffs1,
-                        \par CvMat* camera\_matrix2, \par CvMat* dist\_coeffs2,
-                       \par CvSize image\_size, \par CvMat* R, \par CvMat* T,
-                        \par CvMat* E=0, \par CvMat* F=0,
-                        \par CvTermCriteria term\_crit=cvTermCriteria(
-                               \par CV\_TERMCRIT\_ITER+CV\_TERMCRIT\_EPS,30,1e-6),
-                        \par int flags=CV\_CALIB\_FIX\_INTRINSIC );
-
-}\cvdefPy{StereoCalibrate(\par object\_points,\par image\_points1,\par image\_points2,\par point\_counts,\par camera\_matrix1,\par dist\_coeffs1,\par camera\_matrix2,\par dist\_coeffs2,\par image\_size,\par R,\par T,\par E=NULL,\par F=NULL,\par term\_crit=cvTermCriteria(CV\_TERMCRIT\_ITER+CV\_TERMCRIT\_EPS,30,1e-6),\par flags=CV\_CALIB\_FIX\_INTRINSIC)-> None}
+\fi
 
+\ifCPy
+\cvCPyFunc{InitUndistortRectifyMap}
+\else
+\cvCppFunc{initUndistortRectifyMap}
+\fi
+Computes the undistortion and rectification transformation map.
+
+\cvdefC{void cvInitUndistortRectifyMap( \par const CvMat* cameraMatrix,
+                                \par const CvMat* distCoeffs,
+                                \par const CvMat* R,
+                                \par const CvMat* newCameraMatrix,
+                                \par CvArr* map1, \par CvArr* map2 );}
+\cvdefPy{InitUndistortRectifyMap(cameraMatrix,distCoeffs,R,newCameraMatrix,map1,map2)-> None}
+\cvdefCpp{void initUndistortRectifyMap( const Mat\& cameraMatrix,\par
+                           const Mat\& distCoeffs, const Mat\& R,\par
+                           const Mat\& newCameraMatrix,\par
+                           Size size, int m1type,\par
+                           Mat\& map1, Mat\& map2 );}
 \begin{description}
-\cvarg{object\_points}{The joint matrix of object points, 3xN or Nx3, where N is the total number of points in all views.}
-\cvarg{image\_points1}{The joint matrix of corresponding image points in the views from the 1st camera, 2xN or Nx2, where N is the total number of points in all views.}
-\cvarg{image\_points2}{The joint matrix of corresponding image points in the views from the 2nd camera, 2xN or Nx2, where N is the total number of points in all views.}
-\cvarg{point\_counts}{Vector containing numbers of points in each view, 1xM or Mx1, where M is the number of views.}
-\cvarg{camera\_matrix1, camera\_matrix2}{The input/output camera matrices [${fx}_k 0 {cx}_k; 0 {fy}_k {cy}_k; 0 0 1$]. If \texttt{CV\_CALIB\_USE\_INTRINSIC\_GUESS} or \texttt{CV\_CALIB\_FIX\_ASPECT\_RATIO} are specified, some or all of the elements of the matrices must be initialized.}
-\cvarg{dist\_coeffs1, dist\_coeffs2}{The input/output vectors of distortion coefficients for each camera, \href{\#Pinhole Camera Model, Distortion}{4x1, 1x4, 5x1 or 1x5.}}
-\cvarg{image\_size}{Size of the image, used only to initialize intrinsic camera matrix.} 
-\cvarg{R}{The rotation matrix between the 1st and the 2nd cameras' coordinate systems.}
-\cvarg{T}{The translation vector between the cameras' coordinate systems.}
-\cvarg{E}{The optional output essential matrix.}
-\cvarg{F}{The optional output fundamental matrix.}
-\cvarg{term\_crit}{Termination criteria for the iterative optimiziation algorithm.}
-\cvarg{flags}{Different flags, may be 0 or combination of the following values:
-\begin{description}
-\cvarg{CV\_CALIB\_FIX\_INTRINSIC}{If it is set, \texttt{camera\_matrix1,2}, as well as \texttt{dist\_coeffs1,2} are fixed, so that only extrinsic parameters are optimized.}
-\cvarg{CV\_CALIB\_USE\_INTRINSIC\_GUESS}{The flag allows the function to optimize some or all of the intrinsic parameters, depending on the other flags, but the initial values are provided by the user.}
-\cvarg{CV\_CALIB\_FIX\_PRINCIPAL\_POINT}{The principal points are fixed during the optimization.}
-\cvarg{CV\_CALIB\_FIX\_FOCAL\_LENGTH}{${fx}_k$ and ${fy}_k$ are fixed.}
-\cvarg{CV\_CALIB\_FIX\_ASPECT\_RATIO}{${fy}_k$ is optimized, but the ratio ${fx}_k/{fy}_k$ is fixed.}
-\cvarg{CV\_CALIB\_SAME\_FOCAL\_LENGTH}{Enforces ${fx}_0={fx}_1$ and ${fy}_0={fy}_1$. \texttt{CV\_CALIB\_ZERO\_TANGENT\_DIST} - Tangential distortion coefficients for each camera are set to zeros and fixed there.}
-\cvarg{CV\_CALIB\_FIX\_K1}{The 0-th distortion coefficients (k1) are fixed.}
-\cvarg{CV\_CALIB\_FIX\_K2}{The 1-st distortion coefficients (k2) are fixed.}
-\cvarg{CV\_CALIB\_FIX\_K3}{The 4-th distortion coefficients (k3) are fixed.}
-\end{description}}
+\cvarg{cameraMatrix}{The input camera matrix $A=\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}$}
+\cvarg{distCoeffs}{The input 4x1, 1x4, 5x1 or 1x5 vector of distortion coefficients $(k_1, k_2, p_1, p_2[, k_3])$}.
+\cvarg{R}{The optional rectification transformation in object space (3x3 matrix). \texttt{R1} or \texttt{R2}, computed by \cvCross{StereoRectify}{stereoRectify} can be passed here. If the matrix is \cvCPy{NULL}\cvCpp{empty}, the identity transformation is assumed}
+\cvarg{newCameraMatrix}{The new camera matrix $A'=\vecthreethree{f_x'}{0}{c_x'}{0}{f_y'}{c_y'}{0}{0}{1}$}
+\cvCpp{\cvarg{size}{The undistorted image size}
+\cvarg{m1type}{The type of the first output map, can be \texttt{CV\_32FC1} or \texttt{CV\_16SC2}. See \cvCppCross{convertMaps}}}
+\cvarg{map1}{The first output map \cvCPy{of type \texttt{CV\_32FC1} or \texttt{CV\_16SC2} - the second variant is more efficient}}
+\cvarg{map2}{The second output map \cvCPy{of type \texttt{CV\_32FC1} or \texttt{CV\_16UC1} - the second variant is more efficient}}
 \end{description}
 
-The function estimates transformation between the 2 cameras making a stereo pair. If we have a stereo camera, where the relative position and orientatation of the 2 cameras is fixed, and if we computed poses of an object relative to the fist camera and to the second camera, (R1, T1) and (R2, T2), respectively (that can be done with \cvCPyCross{cvFindExtrinsicCameraParams2}), obviously, those poses will relate to each other, i.e. given ($R_1$, $T_1$) it should be possible to compute ($R_2$, $T_2$) - we only need to know the position and orientation of the 2nd camera relative to the 1st camera. That's what the described function does. It computes ($R$, $T$) such that:
+The function computes the joint undistortion+rectification transformation and represents the result in the form of maps for \cvCross{Remap}{remap}. The undistorted image will look like the original, as if it was captured with a camera with camera matrix \texttt{=newCameraMatrix} and zero distortion. In the case of monocular camera \texttt{newCameraMatrix} is usually equal to \texttt{cameraMatrix}, or it can be computed by \cvCross{GetOptimalNewCameraMatrix}{getOptimalNewCameraMatrix} for a better control over scaling. In the case of stereo camera \texttt{newCameraMatrix} is normally set to \texttt{P1} or \texttt{P2} computed by \cvCross{StereoRectify}{stereoRectify}.
 
-\[
-R_2=R*R_1
-T_2=R*T_1 + T,
-\]
+Also, this new camera will be oriented differently in the coordinate space, according to \texttt{R}. That, for example, helps to align two heads of a stereo camera so that the epipolar lines on both images become horizontal and have the same y- coordinate (in the case of horizontally aligned stereo camera).
 
-Optionally, it computes the essential matrix E:
+The function actually builds the maps for the inverse mapping algorithm that is used by \cvCross{Remap}{remap}. That is, for each pixel $(u, v)$ in the destination (corrected and rectified) image the function computes the corresponding coordinates in the source image (i.e. in the original image from camera). The process is the following:
 
 \[
-E=
-\vecthreethree
-{0}{-T_2}{T_1}
-{T_2}{0}{-T_0}
-{-T_1}{T_0}{0}
-*R
+\begin{array}{l}
+x \leftarrow (u - {c'}_x)/{f'}_x \\
+y \leftarrow (v - {c'}_y)/{f'}_y \\
+{[X\,Y\,W]}^T \leftarrow R^{-1}*[x\,y\,1]^T \\
+x' \leftarrow X/W \\
+y' \leftarrow Y/W \\
+x" \leftarrow x' (1 + k_1 r^2 + k_2 r^4 + k_3 r^6) + 2p_1 x' y' + p_2(r^2 + 2 x'^2) \\
+y" \leftarrow y' (1 + k_1 r^2 + k_2 r^4 + k_3 r^6) + p_1 (r^2 + 2 y'^2) + 2 p_2 x' y' \\
+map_x(u,v) \leftarrow x" f_x + c_x \\
+map_y(u,v) \leftarrow y" f_y + c_y
+\end{array}
 \]
+where $(k_1, k_2, p_1, p_2[, k_3])$ are the distortion coefficients. 
+In the case of a stereo camera this function is called twice, once for each camera head, after \cvCross{StereoRectify}{stereoRectify}, which in its turn is called after \cvCross{StereoCalibrate}{stereoCalibrate}. But if the stereo camera was not calibrated, it is still possible to compute the rectification transformations directly from the fundamental matrix using \cvCross{StereoRectifyUncalibrated}{stereoRectifyUncalibrated}. For each camera the function computes homography \texttt{H} as the rectification transformation in pixel domain, not a rotation matrix \texttt{R} in 3D space. The \texttt{R} can be computed from \texttt{H} as 
 
-where $T_i$ are components of the translation vector $T$: $T=[T_0, T_1, T_2]^T$. And also the function can compute the fundamental matrix F:
-
-$F = inv(camera\_matrix2)^T*E*inv(camera\_matrix1)$
+\[ \texttt{R} = \texttt{cameraMatrix}^{-1} \cdot \texttt{H} \cdot \texttt{cameraMatrix} \]
 
-Besides the stereo-related information, the function can also perform full calibration of each of the 2 cameras. However, because of the high dimensionality of the parameter space and noise in the input data the function can diverge from the correct solution. Thus, if intrinsic parameters can be estimated with high accuracy for each of the cameras individually (e.g. using \cvCPyCross{cvCalibrateCamera2}), it is recommended to do so and then pass \texttt{CV\_CALIB\_FIX\_INTRINSIC} flag to the function along with the computed intrinsic parameters. Otherwise, if all the parameters are estimated at once, it makes sense to restrict some parameters, e.g. pass \texttt{CV\_CALIB\_SAME\_FOCAL\_LENGTH} and \texttt{CV\_CALIB\_ZERO\_TANGENT\_DIST} flags, which are usually reasonable assumptions. 
+where the \texttt{cameraMatrix} can be chosen arbitrarily.
 
-\cvCPyFunc{StereoRectify}
-Computes rectification transform for stereo camera.
+\ifCpp
 
-\cvdefC{void cvStereoRectify( \par const CvMat* camera\_matrix1, \par const CvMat* camera\_matrix2,
-                      \par const CvMat* dist\_coeffs1, \par const CvMat* dist\_coeffs2,
-                      \par CvSize image\_size, \par const CvMat* R, \par const CvMat* T,
-                      \par CvMat* R1, \par CvMat* R2, \par CvMat* P1, \par CvMat* P2,
-                      \par CvMat* Q=0, \par int flags=CV\_CALIB\_ZERO\_DISPARITY );}
-\cvdefPy{StereoRectify(\par camera\_matrix1,\par camera\_matrix2,\par dist\_coeffs1,\par dist\_coeffs2,\par image\_size,\par R,\par T,\par R1,\par R2,\par P1,\par P2,\par Q=NULL,\par flags=CV\_CALIB\_ZERO\_DISPARITY)-> None}
+\cvCppFunc{matMulDeriv}
+Computes partial derivatives of the matrix product w.r.t each multiplied matrix
 
+\cvdefCpp{void matMulDeriv( const Mat\& A, const Mat\& B, Mat\& dABdA, Mat\& dABdB );}
 \begin{description}
-\cvarg{camera\_matrix1, camera\_matrix2}{The camera matrices [${fx}_k$ 0 ${cx}_k$; 0 ${fy}_k$ ${cy}_k$; 0 0 1].}
-\cvarg{dist\_coeffs1, dist\_coeffs2}{The vectors of distortion coefficients for each camera, \href{\#Pinhole Camera Model, Distortion}{4x1, 1x4, 5x1 or 1x5.}}
-\cvarg{image\_size}{Size of the image used for stereo calibration.}
-\cvarg{R}{The rotation matrix between the 1st and the 2nd cameras' coordinate systems.}
-\cvarg{T}{The translation vector between the cameras' coordinate systems.}
-\cvarg{R1, R2}{3x3 Rectification transforms (rotation matrices) for the first and the second cameras, respectively.}
-\cvarg{P1, P2}{3x4 Projection matrices in the new (rectified) coordinate systems.}
-\cvarg{Q}{The optional output disparity-to-depth mapping matrix, 4x4, see \cvCPyCross{cvReprojectImageTo3D}.}
-\cvarg{flags}{The operation flags; may be 0 or \texttt{CV\_CALIB\_ZERO\_DISPARITY}. If the flag is set, the function makes the principal points of each camera have the same pixel coordinates in the rectified views. And if the flag is not set, the function can shift one of the image in horizontal or vertical direction (depending on the orientation of epipolar lines) in order to maximise the useful image area. }
+\cvarg{A}{The first multiplied matrix}
+\cvarg{B}{The second multiplied matrix}
+\cvarg{dABdA}{The first output derivative matrix \texttt{d(A*B)/dA} of size $\texttt{A.rows*B.cols} \times {A.rows*A.cols}$}
+\cvarg{dABdA}{The second output derivative matrix \texttt{d(A*B)/dB} of size $\texttt{A.rows*B.cols} \times {B.rows*B.cols}$}
 \end{description}
 
-The function computes the rotation matrices for each camera that (virtually) make both camera image planes the same plane. Consequently, that makes all the epipolar lines parallel and thus simplifies the dense stereo correspondence problem. On input the function takes the matrices computed by \cvCPyCross{cvStereoCalibrate} and on output it gives 2 rotation matrices and also 2 projection matrices in the new coordinates. The function is normally called after \cvCPyCross{cvStereoCalibrate} that computes both camera matrices, the distortion coefficients, R and T. The 2 cases are distinguished by the function: 
-
-\begin{enumerate}
-\item Horizontal stereo, when 1st and 2nd camera views are shifted relative to each other mainly along the x axis (with possible small vertical shift). Then in the rectified images the corresponding epipolar lines in left and right cameras will be horizontal and have the same y-coordinate. P1 and P2 will look as: 
-
-\[
-P1=
-\begin{bmatrix}
-f & 0 & cx1 & 0\\
-0 & f & cy & 0\\
-0 & 0 & 1 & 0
-\end{bmatrix}
-\]
-\[
-P2=
-\begin{bmatrix}
-f & 0 & cx2 & Tx*f\\
-0 & f & cy & 0\\
-0 & 0 & 1 & 0
-\end{bmatrix}
-,
-\]
-
-where $T_x$ is horizontal shift between the cameras and cx1=cx2 if \texttt{CV\_CALIB\_ZERO\_DISPARITY} is set.
-\item Vertical stereo, when 1st and 2nd camera views are shifted relative to each other mainly in vertical direction (and probably a bit in the horizontal direction too). Then the epipolar lines in the rectified images will be vertical and have the same x coordinate. P2 and P2 will look as:
-
-\[
-P1=
-\begin{bmatrix}
-f & 0 & cx & 0\\
-0 & f & cy1 & 0\\
-0 & 0 & 1 & 0
-\end{bmatrix}
-\]
-\[
-P2=
-\begin{bmatrix}
-f & 0 & cx & 0\\
-0 & f & cy2 & Ty*f\\
-0 & 0 & 1 & 0
-\end{bmatrix}
-,
-\]
+The function computes the partial derivatives of the elements of the matrix product $A*B$ w.r.t. the elements of each of the two input matrices. The function is used to compute Jacobian matrices in \cvCppCross{stereoCalibrate}, but can also be used in any other similar optimization function.
 
-where $T_y$ is vertical shift between the cameras and cy1=cy2 if \texttt{CV\_CALIB\_ZERO\_DISPARITY} is set.
-\end{enumerate} 
+\fi
 
-As you can see, the first 3 columns of P1 and P2 will effectively be the new "rectified" camera matrices. 
+\ifCPy
 
-\cvCPyFunc{StereoRectifyUncalibrated}
-Computes rectification transform for uncalibrated stereo camera.
+\cvCPyFunc{POSIT}
+Implements the POSIT algorithm.
 
 \cvdefC{
-
-void cvStereoRectifyUncalibrated( \par const CvMat* points1, \par const CvMat* points2,
-                                  \par const CvMat* F, \par CvSize image\_size,
-                                  \par CvMat* H1, \par CvMat* H2,
-                                  \par double threshold=5 );
-
-}\cvdefPy{StereoRectifyUncalibrated(points1,points2,F,image\_size,H1,H2,threshold=5)-> None}
-
-\begin{description}
-\cvarg{points1, points2}{The 2 arrays of corresponding 2D points.}
-\cvarg{F}{Fundamental matrix. It can be computed using the same set of point pairs points1 and points2  using \cvCPyCross{cvFindFundamentalMat}.}
-\cvarg{image\_size}{Size of the image.}
-\cvarg{H1, H2}{The rectification homography matrices for the first and for the second images.}
-\cvarg{threshold}{Optional threshold used to filter out the outliers. If the parameter is greater than zero, then all the point pairs that do not comply the epipolar geometry well enough (that is, the points for which $fabs(points2[i]^T*F*points1[i])>threshold$) are rejected prior to computing the homographies. }
-\end{description}
-
-The function computes the rectification transformations without knowing intrinsic parameters of the cameras and their relative position in space, hence the suffix "Uncalibrated". Another related difference from \cvCPyCross{cvStereoRectify} is that the function outputs not the rectification transformations in the object (3D) space, but the planar perspective transformations, encoded by the homography matrices H1 and H2. The function implements the following algorithm \href{\#Hartly99}{[Hartley99]}. 
-
-Note that while the algorithm does not need to know the intrinsic parameters of the cameras, it heavily depends on the epipolar geometry. Therefore, if the camera lenses have significant distortion, it would better be corrected before computing the fundamental matrix and calling this function. For example, distortion coefficients can be estimated for each head of stereo camera separately by using \cvCPyCross{cvCalibrateCamera2} and then the images can be corrected using \cvCPyCross{cvUndistort2}. 
-
-\cvCPyFunc{UndistortPoints}
-Computes the ideal point coordinates from the observed point coordinates.
-
-\cvdefC{void cvUndistortPoints( \par const CvMat* src, \par CvMat* dst,
-                        \par const CvMat* camera\_matrix,
-                        \par const CvMat* dist\_coeffs,
-                        \par const CvMat* R=NULL,
-                        \par const CvMat* P=NULL);}
-\cvdefPy{UndistortPoints(src,dst,camera\_matrix,dist\_coeffs,R=NULL,P=NULL)-> None}
+void cvPOSIT( \par CvPOSITObject* posit\_object,\par CvPoint2D32f* imagePoints,\par double focal\_length,\par CvTermCriteria criteria,\par CvMatr32f rotationMatrix,\par CvVect32f translation\_vector );
+}
+\cvdefPy{POSIT(posit\_object,imagePoints,focal\_length,criteria)-> (rotationMatrix,translation\_vector)}
 
 \begin{description}
-\cvarg{src}{The observed point coordinates}
-\cvarg{dst}{The ideal point coordinates, after undistortion and reverse perspective transformation}
-\cvarg{camera\_matrix}{The camera matrix $A=[fx 0 cx; 0 fy cy; 0 0 1]$}
-\cvarg{dist\_coeffs}{he vector of distortion coefficients, \cvCPyCross{4x1, 1x4, 5x1 or 1x5}}
-\cvarg{R}{The rectification transformation in object space (3x3 matrix). \texttt{R1} or \texttt{R2}, computed by \cvCPyCross{StereoRectify} can be passed here. If the parameter is NULL, the identity matrix is used}
-\cvarg{P}{The new camera matrix (3x3) or the new projection matrix (3x4). \texttt{P1} or \texttt{P2}, computed by \cvCPyCross{StereoRectify} can be passed here. If the parameter is NULL, the identity matrix is used}
+\cvarg{posit\_object}{Pointer to the object structure}
+\cvarg{imagePoints}{Pointer to the object points projections on the 2D image plane}
+\cvarg{focal\_length}{Focal length of the camera used}
+\cvarg{criteria}{Termination criteria of the iterative POSIT algorithm}
+\cvarg{rotationMatrix}{Matrix of rotations}
+\cvarg{translation\_vector}{Translation vector}
 \end{description}
 
-The function is similar to \cvCPyCross{InitUndistortRectifyMap} and is opposite to it at the same time. The functions are similar in that they both are used to correct lens distortion and to perform the optional perspective (rectification) transformation. They are opposite because the function \cvCPyCross{InitUndistortRectifyMap} does actually perform the reverse transformation in order to initialize the maps properly, while this function does the forward transformation. That is, in pseudo-code it can be expressed as:
-
-\begin{lstlisting}
-// (u,v) is the input point, (u', v') is the output point
-// camera_matrix=[fx 0 cx; 0 fy cy; 0 0 1]
-// P=[fx' 0 cx' tx; 0 fy' cy' ty; 0 0 1 tz]
-x" = (u - cx)/fx
-y" = (v - cy)/fy
-(x',y') = undistort(x",y",dist_coeffs)
-[X,Y,W]T = R*[x' y' 1]T
-x = X/W, y = Y/W
-u' = x*fx' + cx'
-v' = y*fy' + cy',
-\end{lstlisting}
-
-where undistort() is approximate iterative algorithm that estimates the normalized original point coordinates out of the normalized distorted point coordinates ("normalized" means that the coordinates do not depend on the camera matrix).
+The function implements the POSIT algorithm. Image coordinates are given in a camera-related coordinate system. The focal length may be retrieved using the camera calibration functions. At every iteration of the algorithm a new perspective projection of the estimated pose is computed.
 
-The function can be used as for stereo cameras, as well as for individual cameras when R=NULL. 
+Difference norm between two projections is the maximal distance between corresponding points. The parameter \texttt{criteria.epsilon} serves to stop the algorithm if the difference is small.
 
 \fi
 
+\ifCPy
+\cvCPyFunc{ProjectPoints2}
+\else
+\cvCppFunc{projectPoints}
+\fi
+Project 3D points on to an image plane.
 
-\ifCpp
-
-\cvCppFunc{calibrateCamera}
-Finds the camera matrix and the camera poses from several views of the calibration pattern.
-
-\cvdefCpp{void calibrateCamera( const vector<vector<Point3f> >\& objectPoints,\par
-                      const vector<vector<Point2f> >\& imagePoints,\par
-                      Size imageSize,\par
-                      Mat\& cameraMatrix, Mat\& distCoeffs,\par
-                      vector<Mat>\& rvecs, vector<Mat>\& tvecs,\par
-                      int flags=0 );}
-\begin{description}
-\cvarg{objectPoints}{The vector of vectors of points on the calibration rig in its coordinate system, one vector per a view of the rig. If the the same calibration rig is shown in each view and it's fully visible, all the vectors can be the same (though, you may change the numbering from one view to another). The points are 3D, but since they are in the rig coordinate system, then if the rig is planar, it may have sense to put the model to the XY coordinate plane, so that Z-coordinate of each input object point is 0}
-\cvarg{imagePoints}{The vector of vectors of the object point projections on the calibration rig views, one vector per a view. The projections must be in the same order as the corresponding object points.}
-\cvarg{imageSize}{Size of the image, used only to initialize the intrinsic camera matrix}
-\cvarg{cameraMatrix}{The input/output matrix of intrinsic camera parameters $A = \vecthreethree{fx}{0}{cx}{0}{fy}{cy}{0}{0}{1}$. If any of \texttt{CALIB\_USE\_INTRINSIC\_GUESS}, \texttt{CALIB\_FIX\_ASPECT\_RATIO}, \texttt{CALIB\_FIX\_FOCAL\_LENGTH} are specified, some or all of \texttt{fx, fy, cx, cy} must be initialized}
-\cvarg{distCoeffs}{The input/output lens distortion coefficients, 4x1, 5x1, 1x4 or 1x5 floating-point vector $k_1, k_2, p_1, p_2[, k_3]$. If any of \texttt{CALIB\_FIX\_K1}, \texttt{CALIB\_FIX\_K2} or \texttt{CALIB\_FIX\_K3} is specified, then the corresponding elements of \texttt{distCoeffs} must be initialized.}
-\cvarg{rvecs}{The output vector of rotation vectors (see \cvCppCross{Rodrigues}) estimated for each camera view}
-\cvarg{tvecsrans}{The output vector of translation vectors estimated for each camera view}
-\cvarg{flags}{Different flags, may be 0 or a combination of the following values:
-\begin{description}
-\cvarg{CALIB\_USE\_INTRINSIC\_GUESS}{\texttt{cameraMatrix} contains the valid initial values of \texttt{fx, fy, cx, cy} that are optimized further. Otherwise, \texttt{(cx, cy)} is initially set to the image center (computed from the input \texttt{imageSize}), and focal distances are computed in some least-squares fashion. Note, that if the focal distance initialization is currently supported only for planar calibration rigs. That is, if the calibration rig is 3D, then you must initialize \texttt{cameraMatrix} and pass \texttt{CALIB\_USE\_INTRINSIC\_GUESS} flag. Also, note that distortion coefficients are not regulated by this function; use \texttt{CALIB\_ZERO\_TANGENT\_DIST} and \texttt{CALIB\_FIX\_K?} to fix them}
-\cvarg{CALIB\_FIX\_PRINCIPAL\_POINT}{The principal point is not changed during the global optimization, it stays at the center or, when \texttt{CALIB\_USE\_INTRINSIC\_GUESS} is set too, at the other specified location}
-\cvarg{CALIB\_FIX\_ASPECT\_RATIO}{The optimization procedure considers only one of \texttt{fx} and \texttt{fy} as independent variables and keeps the aspect ratio \texttt{fx/fy} the same as it was set initially in the input \texttt{cameraMatrix}. In this case the actual initial values of \texttt{(fx, fy)} are either taken from the matrix (when \texttt{CALIB\_USE\_INTRINSIC\_GUESS} is set) or estimated.}
-\cvarg{CALIB\_ZERO\_TANGENT\_DIST}{Tangential distortion coefficients are set to zeros and do not change during the optimization.}
-\cvarg{CALIB\_FIX\_FOCAL\_LENGTH}{Both \texttt{fx} and \texttt{fy} are fixed (taken from \texttt{cameraMatrix} and do not change during the optimization.}
-\cvarg{CALIB\_FIX\_K1, CALIB\_FIX\_K2, CALIB\_FIX\_K3}{The particular distortion coefficients is read from the input \texttt{distCoeffs} and stays the same during optimization}
-\end{description}}
-\end{description}
-
-The function estimates the intrinsic camera
-parameters and the extrinsic parameters for each of the views. The
-coordinates of 3D object points and their correspondent 2D projections
-in each view must be specified. You can use a calibration rig with a known geometry and easily and precisely detectable feature points, e.g. a checkerboard (see \cvCppCross{findChessboardCorners}).
-
-The algorithm does the following:
-\begin{enumerate}
-    \item First, it computes the initial intrinsic parameters (only for planar calibration rigs) or reads them from the input parameters. The distortion coefficients are all set to zeros initially (unless some of \texttt{CALIB\_FIX\_K?} are specified).
-    \item The the initial camera pose is estimated as if the intrinsic parameters have been already known. This is done using \cvCppCross{solvePnP}
-    \item After that the global Levenberg-Marquardt optimization algorithm is run to minimize the reprojection error, i.e. the total sum of squared distances between the observed feature points \texttt{imagePoints} and the projected (using the current estimates for camera parameters and the poses) object points \texttt{objectPoints}; see \cvCppCross{projectPoints}.
-\end{enumerate}
-
-Note: if you're using a non-square (=non-NxN) grid and
-\cvCppCross{findChessboardCorners} for calibration, and \texttt{calibrateCamera} returns
-bad values (i.e. zero distortion coefficients, an image center very far from
-$(w/2-0.5,h/2-0.5)$, and / or large differences between $f_x$ and $f_y$ (ratios of
-10:1 or more)), then you've probaby used \texttt{patternSize=cvSize(rows,cols)},
-but should use \texttt{patternSize=cvSize(cols,rows)} in \cvCppCross{findChessboardCorners}.
-
-See also: \cvCppCross{findChessboardCorners}, \cvCppCross{solvePnP}, \cvCppCross{initCameraMatrix2D}, \cvCppCross{stereoCalibrate}, \cvCppCross{undistort}
-
-
-\cvCppFunc{calibrationMatrixValues}
-Computes some useful camera characteristics from the camera matrix
-
-\cvdefCpp{void calibrationMatrixValues( const Mat\& cameraMatrix,\par
-                              Size imageSize,\par
-                              double apertureWidth,\par
-                              double apertureHeight,\par
-                              double\& fovx,\par
-                              double\& fovy,\par
-                              double\& focalLength,\par
-                              Point2d\& principalPoint,\par
-                              double\& aspectRatio );}
-\begin{description}
-\cvarg{cameraMatrix}{The input camera matrix that can be estimated by \cvCppCross{calibrateCamera} or \cvCppCross{stereoCalibrate}}
-\cvarg{imageSize}{The input image size in pixels}
-\cvarg{apertureWidth}{Physical width of the sensor}
-\cvarg{apertureHeight}{Physical height of the sensor}
-\cvarg{fovx}{The output field of view in degrees along the horizontal sensor axis}
-\cvarg{fovy}{The output field of view in degrees along the vertical sensor axis}
-\cvarg{focalLength}{The focal length of the lens in mm}
-\cvarg{prinicialPoint}{The principal point in pixels}
-\cvarg{aspectRatio}{$f_y/f_x$}
-\end{description}
-
-The function computes various useful camera characteristics from the previously estimated camera matrix.
-
-\cvCppFunc{composeRT}
-Combines two rotation-and-shift transformations
-
-\cvdefCpp{void composeRT( const Mat\& rvec1, const Mat\& tvec1,\par
-                const Mat\& rvec2, const Mat\& tvec2,\par
-                Mat\& rvec3, Mat\& tvec3 );\newline
-void composeRT( const Mat\& rvec1, const Mat\& tvec1,\par
-                const Mat\& rvec2, const Mat\& tvec2,\par
-                Mat\& rvec3, Mat\& tvec3,\par
-                Mat\& dr3dr1, Mat\& dr3dt1,\par
-                Mat\& dr3dr2, Mat\& dr3dt2,\par
-                Mat\& dt3dr1, Mat\& dt3dt1,\par
-                Mat\& dt3dr2, Mat\& dt3dt2 );}
-\begin{description}
-\cvarg{rvec1}{The first rotation vector}
-\cvarg{tvec1}{The first translation vector}
-\cvarg{rvec2}{The second rotation vector}
-\cvarg{tvec2}{The second translation vector}
-\cvarg{rvec3}{The output rotation vector of the superposition}
-\cvarg{tvec3}{The output translation vector of the superposition}
-\cvarg{d??d??}{The optional output derivatives of \texttt{rvec3} or \texttt{tvec3} w.r.t. \texttt{rvec?} or \texttt{tvec?}}
-\end{description}
-
-The functions compute:
-
-\[ \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}, \]
-
-where $\mathrm{rodrigues}$ denotes a rotation vector to rotation matrix transformation, and $\mathrm{rodrigues}^{-1}$ denotes the inverse transformation, see \cvCppCross{Rodrigues}.
-
-Also, the functions can compute the derivatives of the output vectors w.r.t the input vectors (see \cvCppCross{matMulDeriv}).
-The functions are used inside \cvCppCross{stereoCalibrate} but can also be used in your own code where Levenberg-Marquardt or another gradient-based solver is used to optimize a function that contains matrix multiplication.
-
-
-\cvCppFunc{computeCorrespondEpilines}
-For points in one image of a stereo pair, computes the corresponding epilines in the other image.
-
-\cvdefCpp{void computeCorrespondEpilines( const Mat\& points,\par
-                                int whichImage, const Mat\& F,\par
-                                vector<Vec3f>\& lines );}
-\begin{description}
-\cvarg{points}{The input points. $N \times 1$ or $1 \times N$ matrix of type \texttt{CV\_32FC2} or \texttt{vector<Point2f>}}
-\cvarg{whichImage}{Index of the image (1 or 2) that contains the \texttt{points}}
-\cvarg{F}{The fundamental matrix that can be estimated using \cvCppCross{findFundamentalMat} or \texttt{stereoRectify}}
-\cvarg{lines}{The output vector of the corresponding to the points epipolar lines in the other image. Each line $ax + by + c=0$ is encoded as 3-element vector $(a, b, c)$}
-\end{description}
-
-For every point in one of the two images of a stereo-pair the function
-\texttt{computeCorrespondEpilines} finds the equation of the
-corresponding epipolar line in the other image.
-
-From the fundamental matrix definition (see \cvCppCross{findFundamentalMatrix}),
-line $l^{(2)}_i$ in the second image for the point $p^{(1)}_i$ in the first image (i.e. when \texttt{whichImage=1}) is computed as:
-
-\[ l^{(2)}_i = F p^{(1)}_i \]
-
-and, vice versa, when \texttt{whichImage=2}, $l^{(1)}_i$ is computed from $p^{(2)}_i$ as:
-
-\[ l^{(1)}_i = F^T p^{(2)}_i \]
-
-Line coefficients are defined up to a scale. They are normalized, such that $a_i^2+b_i^2=1$.
-
-\cvCppFunc{convertPointHomogeneous}
-Converts 2D points to/from homogeneous coordinates.
-
-\cvdefCpp{void convertPointsHomogeneous( const Mat\& src, vector<Point3f>\& dst );\newline
-void convertPointsHomogeneous( const Mat\& src, vector<Point2f>\& dst );}
+\cvdefC{void cvProjectPoints2( \par const CvMat* objectPoints,\par const CvMat* rvec,\par const CvMat* tvec,\par const CvMat* cameraMatrix,\par const CvMat* distCoeffs,\par CvMat* imagePoints,\par CvMat* dpdrot=NULL,\par CvMat* dpdt=NULL,\par CvMat* dpdf=NULL,\par CvMat* dpdc=NULL,\par CvMat* dpddist=NULL );}
 
-\begin{description}
-\cvarg{src}{The input array or vector of 2D or 3D points}
-\cvarg{dst}{The output vector of 3D or 2D points, respectively}
-\end{description}
+\cvdefPy{ProjectPoints2(objectPoints,rvec,tvec,cameraMatrix,distCoeffs, imagePoints,dpdrot=NULL,dpdt=NULL,dpdf=NULL,dpdc=NULL,dpddist=NULL)-> None}
 
-The first of the functions converts 2D points to the homogeneous coordinates by adding extra \texttt{1} component to each point. When the input vector already contains 3D points, it is simply copied to \texttt{dst}. The second function converts 3D points to 2D points by dividing 1st and 2nd components by the 3rd one. If the input vector already contains 2D points, it is simply copied to \texttt{dst}.
 
-\cvCppFunc{decomposeProjectionMatrix}
-Decomposes the projection matrix into a rotation matrix and a camera matrix.
+\cvdefCpp{void projectPoints( const Mat\& objectPoints,\par
+                    const Mat\& rvec, const Mat\& tvec,\par
+                    const Mat\& cameraMatrix,\par
+                    const Mat\& distCoeffs,\par
+                    vector<Point2f>\& imagePoints );\newline
+void projectPoints( const Mat\& objectPoints,\par
+                    const Mat\& rvec, const Mat\& tvec,\par
+                    const Mat\& cameraMatrix,\par
+                    const Mat\& distCoeffs,\par
+                    vector<Point2f>\& imagePoints,\par
+                    Mat\& dpdrot, Mat\& dpdt, Mat\& dpdf,\par
+                    Mat\& dpdc, Mat\& dpddist,\par
+                    double aspectRatio=0 );}
 
-\cvdefCpp{void decomposeProjectionMatrix( const Mat\& projMatrix,\par
-                                Mat\& cameraMatrix,\par
-                                Mat\& rotMatrix, Mat\& transVect );\newline
-void decomposeProjectionMatrix( const Mat\& projMatrix, \par
-                                Mat\& cameraMatrix,\par
-                                Mat\& rotMatrix, Mat\& transVect,\par
-                                Mat\& rotMatrixX, Mat\& rotMatrixY,\par
-                                Mat\& rotMatrixZ, Vec3d\& eulerAngles );}
 \begin{description}
-\cvarg{projMatrix}{The input $3 \times 4$ projection matrix}
-\cvarg{cameraMatrix}{The output $3 \times 3$ camera matrix}
-\cvarg{rotMatrix}{The output $3 \times 3$ rotation matrix}
-\cvarg{transVect}{The output $3 \times 1$ translation vector}
-\cvarg{rotMatrixX}{The optional output rotation matrix around x-axis}
-\cvarg{rotMatrixY}{The optional output rotation matrix around y-axis}
-\cvarg{rotMatrixZ}{The optional output rotation matrix around z-axis}
-\cvarg{eulerAngles}{The optional output 3-vector of the Euler rotation angles}
+\cvarg{objectPoints}{The array of object points, 3xN or Nx3 1-channel or 1xN or Nx1 3-channel \cvCpp{(or \texttt{vector<Point3f>})}, where N is the number of points in the view}
+\cvarg{rvec}{The rotation vector, see \cvCross{Rodrigues2}{Rodrigues}}
+\cvarg{tvec}{The translation vector}
+\cvarg{cameraMatrix}{The camera matrix $A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{_1} $}
+\cvarg{distCoeffs}{The input 4x1, 1x4, 5x1 or 1x5 vector of distortion coefficients $(k_1, k_2, p_1, p_2[, k_3])$. If it is \cvC{NULL}\cvCpp{empty}\cvPy{None}, all of the distortion coefficients are considered 0's}
+\cvarg{imagePoints}{The output array of image points, 2xN or Nx2 1-channel or 1xN or Nx1 2-channel \cvCpp{(or \texttt{vector<Point2f>})}}
+\cvarg{dpdrot}{Optional 2Nx3 matrix of derivatives of image points with respect to components of the rotation vector}
+\cvarg{dpdt}{Optional 2Nx3 matrix of derivatives of image points with respect to components of the translation vector}
+\cvarg{dpdf}{Optional 2Nx2 matrix of derivatives of image points with respect to $f_x$ and $f_y$}
+\cvarg{dpdc}{Optional 2Nx2 matrix of derivatives of image points with respect to $c_x$ and $c_y$}
+\cvarg{dpddist}{Optional 2Nx4 matrix of derivatives of image points with respect to distortion coefficients}
 \end{description}
 
-The function computes a decomposition of a projection matrix into a calibration and a rotation matrix and the position of the camera.
-
-It optionally returns three rotation matrices, one for each axis, and the three Euler angles that could be used in OpenGL.
+The function computes projections of 3D
+points to the image plane given intrinsic and extrinsic camera
+parameters. Optionally, the function computes jacobians - matrices
+of partial derivatives of image points coordinates (as functions of all the
+input parameters) with respect to the particular parameters, intrinsic and/or
+extrinsic. The jacobians are used during the global optimization
+in \cvCross{CalibrateCamera2}{calibrateCamera},
+\cvCross{FindExtrinsicCameraParams2}{solvePnP} and \cvCross{StereoCalibrate}{stereoCalibrate}. The
+function itself can also used to compute re-projection error given the
+current intrinsic and extrinsic parameters.
 
-The function is based on \cvCppCross{RQDecomp3x3}.
+Note, that by setting \texttt{rvec=tvec=(0,0,0)}, or by setting \texttt{cameraMatrix} to 3x3 identity matrix, or by passing zero distortion coefficients, you can get various useful partial cases of the function, i.e. you can compute the distorted coordinates for a sparse set of points, or apply a perspective transformation (and also compute the derivatives) in the ideal zero-distortion setup etc.
 
-\cvCppFunc{drawChessboardCorners}
-Draws the detected chessboard corners.
 
-\cvdefCpp{void drawChessboardCorners( Mat\& image, Size patternSize,\par
-                            const Mat\& corners,\par
-                            bool patternWasFound );}
-\begin{description}
-\cvarg{image}{The destination image; it must be an 8-bit color image}
-\cvarg{patternSize}{The number of inner corners per chessboard row and column, i.e. \texttt{Size(<corners per row>, <corners per column>)}}
-\cvarg{corners}{The array of detected corners; \texttt{vector<Point2f>} can be passed here as well}
-\cvarg{patternWasFound}{Indicates whether the complete board was found. Just pass the return value of \cvCppCross{findChessboardCorners} here}
-\end{description}
+\ifCPy
+\cvCPyFunc{ReprojectImageTo3D}
+\else
+\cvCppFunc{reprojectImageTo3D}
+\fi
+Reprojects disparity image to 3D space.
 
-The function draws the detected chessboard corners. If no complete board was found, the detected corners will be marked with small red circles. Otherwise, a colored board (each board row with a different color) will be drawn.
+\cvdefC{void cvReprojectImageTo3D( const CvArr* disparity,\par
+                                   CvArr* \_3dImage, const CvMat* Q,\par
+                                   int handleMissingValues=0);}
 
-\cvCppFunc{findFundamentalMat}
-Calculates the fundamental matrix from the corresponding points in two images.
+\cvdefPy{ReprojectImageTo3D(disparity, \_3dImage, Q, handleMissingValues=0) -> None}
 
-\cvdefCpp{Mat findFundamentalMat( const Mat\& points1, const Mat\& points2,\par
-                        vector<uchar>\& mask, int method=FM\_RANSAC,\par
-                        double param1=3., double param2=0.99 );\newline
-Mat findFundamentalMat( const Mat\& points1, const Mat\& points2,\par
-                        int method=FM\_RANSAC,\par
-                        double param1=3., double param2=0.99 );}
-\begin{description}
-\cvarg{points1}{Array of $N$ points in the first image, a matrix of \texttt{CV\_32FC2} type or \texttt{vector<Point2f>}. The points in homogeneous coordinates can also be passed.}
-\cvarg{points2}{Array of the corresponding points in the second image of the same size and the same type as \texttt{points1}}
-\cvarg{method}{Method for computing the fundamental matrix
+\cvdefCpp{void reprojectImageTo3D( const Mat\& disparity,\par
+                         Mat\& \_3dImage, const Mat\& Q,\par
+                         bool handleMissingValues=false );}
 \begin{description}
-  \cvarg{FM\_7POINT}{for a 7-point algorithm. $N = 7$}
-  \cvarg{FM\_8POINT}{for an 8-point algorithm. $N \ge 8$}
-  \cvarg{FM\_RANSAC}{for the RANSAC algorithm. $N \ge 8$}
-  \cvarg{FM\_LMEDS}{for the LMedS algorithm. $N \ge 8$}
-\end{description}}
-\cvarg{param1}{The parameter is used for RANSAC only. It is the maximum distance in pixels from point to epipolar line in pixels, beyond which the point is considered an outlier and is not used for computing the final fundamental matrix. It can be set to something like 1-3, depending on the accuracy of the point localization, image resolution and the image noise}
-\cvarg{param2}{The parameter is used for RANSAC or LMedS methods only. It denotes the desirable level of confidence (between 0 and 1) that the estimated matrix is correct}
-\cvarg{mask}{The optional output array of $N$ elements, every element of which is set to 0 for outliers and to 1 for the other points. The array is computed only in RANSAC and LMedS methods. Other methods set every element to 1}
+\cvarg{disparity}{The input single-channel 16-bit signed or 32-bit floating-point disparity image}
+\cvarg{\_3dImage}{The output 3-channel floating-point image of the same size as \texttt{disparity}.
+ Each element of \texttt{\_3dImage(x,y)} will contain the 3D coordinates of the point \texttt{(x,y)}, computed from the disparity map.}
+\cvarg{Q}{The $4 \times 4$ perspective transformation matrix that can be obtained with \cvCross{StereoRectify}{stereoRectify}}
+\cvarg{handleMissingValues}{If true, when the pixels with the minimal disparity (that corresponds to the outliers; see \cvCross{FindStereoCorrespondenceBM}{StereoBM}) will be transformed to 3D points with some very large Z value (currently set to 10000)}
 \end{description}
+The function transforms 1-channel disparity map to 3-channel image representing a 3D surface. That is, for each pixel \texttt{(x,y)} and the corresponding disparity \texttt{d=disparity(x,y)} it computes: 
 
-The epipolar geometry is described by the following equation:
-
-\[ [p_2; 1]^T F [p_1; 1] = 0 \]
-
-where $F$ is fundamental matrix, $p_1$ and $p_2$ are corresponding points in the first and the second images, respectively.
-
-The function calculates the fundamental
-matrix using one of four methods listed above and returns the found fundamental matrix. In the case of \texttt{FM\_7POINT} the function may return a $9 \times 3$ matrix. It means that the 3 fundamental matrices are possible and they are all found and stored sequentially.
+\[\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}\]
 
-The calculated fundamental matrix may be passed further to
-\texttt{computeCorrespondEpilines} that finds the epipolar lines
-corresponding to the specified points. It can also be passed to \cvCppCross{stereoRectifyUncalibrated} to compute the rectification transformation.
+The matrix \texttt{Q} can be arbitrary $4 \times 4$ matrix, e.g. the one computed by \cvCross{StereoRectify}{stereoRectify}. To reproject a sparse set of points {(x,y,d),...} to 3D space, use \cvCross{PerspectiveTransform}{perspectiveTransform}.
 
-\begin{lstlisting}
-// Example. Estimation of fundamental matrix using RANSAC algorithm
-int point_count = 100;
-vector<Point2f> points1(point_count);
-vector<Point2f> points2(point_count);
+\ifCPy
+\cvCPyFunc{RQDecomp3x3}
+\else
+\cvCppFunc{RQDecomp3x3}
+\fi
+Computes the 'RQ' decomposition of 3x3 matrices.
 
-// initialize the points here ... */
-for( int i = 0; i < point_count; i++ )
-{
-    points1[i] = ...;
-    points2[i] = ...;
+\cvdefC{
+void cvRQDecomp3x3( \par const CvMat *M,\par CvMat *R,\par CvMat *Q,\par CvMat *Qx=NULL,\par CvMat *Qy=NULL,\par CvMat *Qz=NULL,\par CvPoint3D64f *eulerAngles=NULL);
 }
+\cvdefPy{RQDecomp3x3(M, R, Q, Qx = None, Qy = None, Qz = None) -> eulerAngles}
+\cvdefCpp{void RQDecomp3x3( const Mat\& M, Mat\& R, Mat\& Q );\newline
+Vec3d RQDecomp3x3( const Mat\& M, Mat\& R, Mat\& Q,\par
+                   Mat\& Qx, Mat\& Qy, Mat\& Qz );}
 
-Mat fundamental_matrix =
- findFundamentalMat(points1, points2, FM_RANSAC, 3, 0.99);
-\end{lstlisting}
-
-
-\cvCppFunc{findChessboardCorners}
-Finds the positions of the internal corners of the chessboard.
-
-\cvdefCpp{bool findChessboardCorners( const Mat\& image, Size patternSize,\par
-                            vector<Point2f>\& corners,\par
-                            int flags=CV\_CALIB\_CB\_ADAPTIVE\_THRESH+\par
-                                 CV\_CALIB\_CB\_NORMALIZE\_IMAGE );}
 \begin{description}
-\cvarg{image}{The input chessboard (a.k.a. checkerboard) view; it must be an 8-bit grayscale or color image}
-\cvarg{patternSize}{The number of inner corners per chessboard row and column, i.e.
-\texttt{patternSize = cvSize(<points per row>, <points per column>)}}
-\cvarg{corners}{The output vector of the corners detected. If the board is found (the function returned true), the corners should be properly ordered.}
-\cvarg{flags}{Various operation flags, can be 0 or a combination of the following values:
-\begin{description}
- \cvarg{CALIB\_CB\_ADAPTIVE\_THRESH}{use adaptive thresholding, instead of a fixed-level threshold, to convert the image to black and white rather than a fixed threshold level}
- \cvarg{CALIB\_CB\_NORMALIZE\_IMAGE}{normalize the image brightness and contrast using \cvCppCross{equalizeHist} before applying fixed or adaptive thresholding}
- \cvarg{CALIB\_CB\_FILTER\_QUADS}{use some additional criteria (like contour area, perimeter, square-like shape) to filter out false quads that are extracted at the contour retrieval stage. Since the current corner grouping engine is smart enough, usually this parameter is omitted.}
-\end{description}}
+\cvarg{M}{The 3x3 input matrix}
+\cvarg{R}{The output 3x3 upper-triangular matrix}
+\cvarg{Q}{The output 3x3 orthogonal matrix}
+\cvarg{Qx}{Optional 3x3 rotation matrix around x-axis}
+\cvarg{Qy}{Optional 3x3 rotation matrix around y-axis}
+\cvarg{Qz}{Optional 3x3 rotation matrix around z-axis}
+\cvCPy{\cvarg{eulerAngles}{Optional three Euler angles of rotation}}
 \end{description}
 
-The function attempts to determine
-whether the input image is a view of the chessboard pattern and, if yes,
-locate the internal chessboard corners. The function returns true if all
-of the chessboard corners have been found and they have been placed
-in a certain order (row by row, left to right in every row),
-otherwise, if the function fails to find all the corners or reorder
-them, it returns 0. For example, a regular chessboard has 8 x 8
-squares and 7 x 7 internal corners, that is, points, where the black
-squares touch each other. The coordinates detected are approximate,
-and to determine their position more accurately, the user may use
-the function \cvCppCross{cornerSubPix} or other subpixel adjustment technique.
-
-Sometimes the function fails to find the board because the image is too large or too small. If so, try to resize it and then scale the found corners coordinates back (or even scale the computed \texttt{cameraMatrix} back).
+The function computes a RQ decomposition using the given rotations. This function is used in \cvCross{DecomposeProjectionMatrix}{decomposeProjectionMatrix} to decompose the left 3x3 submatrix of a projection matrix into a camera and a rotation matrix.
 
+It optionally returns three rotation matrices, one for each axis, and the three Euler angles \cvCpp{(as the return value)} that could be used in OpenGL.
 
-\cvCppFunc{getDefaultNewCameraMatrix}
-Returns the default new camera matrix
+\ifC
+
+\cvCPyFunc{ReleasePOSITObject}
+Deallocates a 3D object structure.
+
+\cvdefC{
+void cvReleasePOSITObject( \par CvPOSITObject** posit\_object );
+}
 
-\cvdefCpp{Mat getDefaultNewCameraMatrix(\par
-                               const Mat\& cameraMatrix,\par
-                               Size imgSize=Size(),\par
-                               bool centerPrincipalPoint=false );}
 \begin{description}
-\cvarg{cameraMatrix}{The input camera matrix}
-\cvarg{imageSize}{The camera view image size in pixels}
-\cvarg{centerPrincipalPoint}{Indicates whether in the new camera matrix the principal point should be at the image center or not}
+\cvarg{posit\_object}{Double pointer to \texttt{CvPOSIT} structure}
 \end{description}
 
-The function returns the camera matrix that is either an exact copy of the input \texttt{cameraMatrix} (when \texttt{centerPrinicipalPoint=false}), or the modified one (when \texttt{centerPrincipalPoint}=true).
+The function releases memory previously allocated by the function \cvCPyCross{CreatePOSITObject}.
 
-In the latter case the new camera matrix will be:
+\fi
 
-\[\begin{bmatrix}
-f_x && 0 && (\texttt{imgSize.width}-1)*0.5 \\
-0 && f_y && (\texttt{imgSize.height}-1)*0.5 \\
-0 && 0 && 1
-\end{bmatrix},\]
+\ifC
 
-where $f_x$ and $f_y$ are $(0,0)$ and $(1,1)$ elements of \texttt{cameraMatrix}, respectively.
+\cvCPyFunc{ReleaseStereoBMState}
+Releases block matching stereo correspondence structure.
 
-By default, the undistortion functions in OpenCV (see \texttt{initUndistortRectifyMap}, \texttt{undistort}) do not move the principal point. However, when you work with stereo, it's important to move the principal points in both views to the same y-coordinate (which is required by most of stereo correspondence algorithms), and maybe to the same x-coordinate too. So you can form the new camera matrix for each view, where the principal points will be at the center. 
+\cvdefC{void cvReleaseStereoBMState( CvStereoBMState** state );}
+\cvdefPy{ReleaseStereoBMState(state)-> None}
 
-\cvCppFunc{initCameraMatrix2D}
-Finds the initial camera matrix from the 3D-2D point correspondences
+\begin{description}
+\cvarg{state}{Double pointer to the released structure.}
+\end{description}
+
+The function releases the stereo correspondence structure and all the associated internal buffers. 
+
+\cvCPyFunc{ReleaseStereoGCState}
+Releases the state structure of the graph cut-based stereo correspondence algorithm.
+
+\cvdefC{void cvReleaseStereoGCState( CvStereoGCState** state );}
+\cvdefPy{ReleaseStereoGCState(state)-> None}
 
-\cvdefCpp{Mat initCameraMatrix2D( const vector<vector<Point3f> >\& objectPoints,\par
-                        const vector<vector<Point2f> >\& imagePoints,\par
-                        Size imageSize, double aspectRatio=1. );}
 \begin{description}
-\cvarg{objectPoints}{The vector of vectors of the object points. See \cvCppCross{calibrateCamera}}
-\cvarg{imagePoints}{The vector of vectors of the corresponding image points. See \cvCppCross{calibrateCamera}}
-\cvarg{imageSize}{The image size in pixels; used to initialize the principal point}
-\cvarg{aspectRatio}{If it is zero or negative, both $f_x$ and $f_y$ are estimated independently. Otherwise $f_x = f_y * \texttt{aspectRatio}$}
+\cvarg{state}{Double pointer to the released structure.}
 \end{description}
 
-The function estimates and returns the initial camera matrix for camera calibration process.
-Currently, the function only supports planar calibration rigs, i.e. the rig for which the $3 \times 3$ covariance matrix of object points is singular.
+The function releases the stereo correspondence structure and all the associated internal buffers. 
 
+\fi
 
+\ifCPy
+\cvCPyFunc{Rodrigues2}
+\else
 \cvCppFunc{Rodrigues}
+\fi
 Converts a rotation matrix to a rotation vector or vice versa.
 
+\cvdefC{int cvRodrigues2( \par const CvMat* src,\par CvMat* dst,\par CvMat* jacobian=0 );}
+\cvdefPy{Rodrigues2(src,dst,jacobian=0)-> None}
+
 \cvdefCpp{void Rodrigues(const Mat\& src, Mat\& dst);\newline
 void Rodrigues(const Mat\& src, Mat\& dst, Mat\& jacobian);}
 
 \begin{description}
-\cvarg{src}{The input rotation vector (3x1 or 1x3) or rotation matrix (3x3)}
-\cvarg{dst}{The output rotation matrix (3x3) or rotation vector (3x1 or 1x3), respectively}
-\cvarg{jacobian}{The optional output Jacobian matrix, 3x9 or 9x3 - partial derivatives of the output array components with respect to the input array components}
+\cvarg{src}{The input rotation vector (3x1 or 1x3) or rotation matrix (3x3)}
+\cvarg{dst}{The output rotation matrix (3x3) or rotation vector (3x1 or 1x3), respectively}
+\cvarg{jacobian}{Optional output Jacobian matrix, 3x9 or 9x3 - partial derivatives of the output array components with respect to the input array components}
 \end{description}
 
-The functions convert a rotation vector to a rotation matrix or vice versa. A rotation vector is a compact representation of rotation matrix. Direction of the rotation vector is the rotation axis and the length of the vector is the rotation angle around the axis. The rotation matrix $R$, corresponding to the rotation vector $r$, is computed as following:
-
 \[
 \begin{array}{l}
 \theta \leftarrow norm(r)\\
@@ -1412,175 +1336,199 @@ Inverse transformation can also be done easily, since
 
 A rotation vector is a convenient and most-compact representation of a rotation matrix
 (since any rotation matrix has just 3 degrees of freedom). The representation is
-used in the global 3D geometry optimization procedures like \cvCppCross{calibrateCamera}, \cvCppCross{stereoCalibrate} or \cvCppCross{solvePnP}.
+used in the global 3D geometry optimization procedures like \cvCross{CalibrateCamera2}{calibrateCamera},
+\cvCross{StereoCalibrate}{stereoCalibrate} or \cvCross{FindExtrinsicCameraParams2}{solvePnP}.
 
 
-\cvCppFunc{RQDecomp3x3}
-Computes the 'RQ' decomposition of 3x3 matrices.
+\ifCpp
 
-\cvdefCpp{void RQDecomp3x3( const Mat\& M, Mat\& R, Mat\& Q );\newline
-Vec3d RQDecomp3x3( const Mat\& M, Mat\& R, Mat\& Q,\par
-                   Mat\& Qx, Mat\& Qy, Mat\& Qz );}
-\begin{description}
-\cvarg{M}{The input $3 \times 3$ floating-point matrix}
-\cvarg{R}{The output $3 \times 3$ upper-triangular matrix}
-\cvarg{Q}{The output $3 \times 3$ orthogonal matrix}
-\cvarg{Qx, Qy, Qz}{The optional output matrices that decompose the rotation matrix Q into separate rotation matrices for each coordinate axis}
-\end{description}
+\cvCppFunc{StereoBM}
+The class for computing stereo correspondence using block matching algorithm.
 
-The function implements RQ decomposition of a $3 \times 3$ matrix. The function is by \cvCppCross{decomposeProjectionMatrix}.
+\begin{lstlisting}
+// Block matching stereo correspondence algorithm\par
+class StereoBM
+{
+    enum { NORMALIZED_RESPONSE = CV_STEREO_BM_NORMALIZED_RESPONSE,
+        BASIC_PRESET=CV_STEREO_BM_BASIC,
+        FISH_EYE_PRESET=CV_STEREO_BM_FISH_EYE,
+        NARROW_PRESET=CV_STEREO_BM_NARROW };
 
-\cvCppFunc{matMulDeriv}
-Computes partial derivatives of the matrix product w.r.t each multiplied matrix
+    StereoBM();
+    // the preset is one of ..._PRESET above.
+    // ndisparities is the size of disparity range,
+    // in which the optimal disparity at each pixel is searched for.
+    // SADWindowSize is the size of averaging window used to match pixel blocks
+    //    (larger values mean better robustness to noise, but yield blurry disparity maps)
+    StereoBM(int preset, int ndisparities=0, int SADWindowSize=21);
+    // separate initialization function
+    void init(int preset, int ndisparities=0, int SADWindowSize=21);
+    // computes the disparity for the two rectified 8-bit single-channel images.
+    // the disparity will be 16-bit signed (fixed-point) or 32-bit floating-point image of the same size as left.
+    void operator()( const Mat& left, const Mat& right, Mat& disparity, int disptype=CV_16S );
 
-\cvdefCpp{void matMulDeriv( const Mat\& A, const Mat\& B, Mat\& dABdA, Mat\& dABdB );}
-\begin{description}
-\cvarg{A}{The first multiplied matrix}
-\cvarg{B}{The second multiplied matrix}
-\cvarg{dABdA}{The first output derivative matrix \texttt{d(A*B)/dA} of size $\texttt{A.rows*B.cols} \times {A.rows*A.cols}$}
-\cvarg{dABdA}{The second output derivative matrix \texttt{d(A*B)/dB} of size $\texttt{A.rows*B.cols} \times {B.rows*B.cols}$}
-\end{description}
+    Ptr<CvStereoBMState> state;
+};
+\end{lstlisting}
 
-The function computes the partial derivatives of the elements of the matrix product $A*B$ w.r.t. the elements of each of the two input matrices. The function is used to compute Jacobian matrices in \cvCppCross{stereoCalibrate}, but can also be used in any other similar optimization function.
+The class is a C++ wrapper for \hyperref[CvStereoBMState]{cvStereoBMState} and the associated functions. In particular, \texttt{StereoBM::operator ()} is the wrapper for \cvCPyCross{FindStereoCorrespondceBM}. See the respective descriptions.
 
-\cvCppFunc{projectPoints}
-Projects 3D points on to an image plane.
 
-\cvdefCpp{void projectPoints( const Mat\& objectPoints,\par
-                    const Mat\& rvec, const Mat\& tvec,\par
-                    const Mat\& cameraMatrix,\par
-                    const Mat\& distCoeffs,\par
-                    vector<Point2f>\& imagePoints );\newline
-void projectPoints( const Mat\& objectPoints,\par
-                    const Mat\& rvec, const Mat\& tvec,\par
-                    const Mat\& cameraMatrix,\par
-                    const Mat\& distCoeffs,\par
-                    vector<Point2f>\& imagePoints,\par
-                    Mat\& dpdrot, Mat\& dpdt, Mat\& dpdf,\par
-                    Mat\& dpdc, Mat\& dpddist,\par
-                    double aspectRatio=0 );}
-\begin{description}
-\cvarg{objectPoints}{The input array of 3D object points, a matrix of type \texttt{CV\_32FC3} or \texttt{vector<Point3f>}}
-\cvarg{imagePoints}{The output array of 2D image points}
-\cvarg{rvec}{The rotation vector, 1x3 or 3x1}
-\cvarg{tvec}{The translation vector, 1x3 or 3x1}
-\cvarg{cameraMatrix}{The camera matrix $\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}$}
-\cvarg{distCoeffs}{The array of distortion coefficients, 4x1, 5x1, 1x4 or 1x5 $k_1, k_2, p_1, p_2[, k_3]$. If the matrix is empty, the function uses zero distortion coefficients}
-\cvarg{dpdrot, dpdt, dpdf, dpdc, dpdist}{The optional matrices of the partial derivatives of the computed point projections w.r.t the rotation vector, the translation vector, $f_x$ and $f_y$, $c_x$ and $c_y$ and the distortion coefficients respectively. Each matrix has $2*N$ rows (where $N$ is the number of points) - even rows (0th, 2nd ...) are the derivatives of the x-coordinates w.r.t. the camera parameters and odd rows (1st, 3rd ...) are the derivatives of the y-coordinates.}
-\cvarg{aspectRatio}{If zero or negative, $f_x$ and $f_y$ are treated as independent variables, otherwise they $f_x = f_y*\texttt{aspectRatio}$, so the derivatives are adjusted appropriately}
-\end{description}
+\cvCppFunc{StereoSGBM}
+The class for computing stereo correspondence using semi-global block matching algorithm.
 
-The function computes projections of 3D
-points to the image plane given intrinsic and extrinsic camera
-parameters. Optionally, the function computes jacobians - matrices
-of partial derivatives of image points as functions of all the
-input parameters with respect to the particular camera parameters, intrinsic and/or
-extrinsic. The computed jacobians are used during the global optimization
-in \cvCppCross{calibrateCamera}, \cvCppCross{stereoCalibrate} and \cvCppCross{solvePnP}.
+\begin{lstlisting}
+class StereoSGBM
+{
+    StereoSGBM();
+    StereoSGBM(int minDisparity, int numDisparities, int SADWindowSize,
+               int P1=0, int P2=0, int disp12MaxDiff=0,
+               int preFilterCap=0, int uniquenessRatio=0,
+               int speckleWindowSize=0, int speckleRange=0,
+               bool fullDP=false);
+    virtual ~StereoSGBM();
+    
+    virtual void operator()(const Mat& left, const Mat& right, Mat& disp);
+    
+    int minDisparity;
+    int numberOfDisparities;
+    int SADWindowSize;
+    int preFilterCap;
+    int uniquenessRatio;
+    int P1, P2;
+    int speckleWindowSize;
+    int speckleRange;
+    int disp12MaxDiff;
+    bool fullDP;
+    
+    ...
+};
+\end{lstlisting}
 
-Note, that by setting \texttt{rvec=tvec=(0,0,0)} or by setting \texttt{cameraMatrix=Mat::eye(3,3,CV\_64F)} or by setting \texttt{distCoeffs=Mat()} you can get various useful partial cases of the function, i.e. you can computed the distorted coordinates for a sparse set of points, or apply a perspective transformation (and also compute the derivatives) in the ideal zero-distortion setup etc.
+The class implements modified H. Hirschmuller algorithm \cite{HH08}. The main differences between the implemented algorithm and the original one are:
 
-\cvCppFunc{reprojectImageTo3D}
-Reprojects disparity image to 3D space.
+\begin{itemize}
+    \item by default the algorithm is single-pass, i.e. instead of 8 directions we only consider 5. Set \texttt{fullDP=true} to run the full variant of the algorithm (which could consume \emph{a lot} of memory)
+    \item the algorithm matches blocks, not individual pixels (though, by setting \texttt{SADWindowSize=1} the blocks are reduced to single pixels)
+    \item mutual information cost function is not implemented. Instead, we use a simpler Birchfield-Tomasi sub-pixel metric from \cite{BT96}, though the color images are supported as well.
+    \item we include some pre- and post- processing steps from K. Konolige algorithm \cvCPyCross{FindStereoCorrespondceBM}, such as pre-filtering (\texttt{CV\_STEREO\_BM\_XSOBEL} type) and post-filtering (uniqueness check, quadratic interpolation and speckle filtering)
+\end{itemize}
 
-\cvdefCpp{void reprojectImageTo3D( const Mat\& disparity,\par
-                         Mat\& \_3dImage, const Mat\& Q,\par
-                         bool handleMissingValues=false );}
+\cvCppFunc{StereoSGBM::StereoSGBM}
+StereoSGBM constructors
+
+\cvdefCpp{
+StereoSGBM::StereoSGBM();\newline
+StereoSGBM::StereoSGBM(
+            \par int minDisparity, int numDisparities, int SADWindowSize,
+           \par int P1=0, int P2=0, int disp12MaxDiff=0,
+           \par int preFilterCap=0, int uniquenessRatio=0,
+           \par int speckleWindowSize=0, int speckleRange=0,
+           \par bool fullDP=false);
+}
 \begin{description}
-\cvarg{disparity}{The input single-channel 16-bit signed or 32-bit floating-point disparity image}
-\cvarg{\_3dImage}{The output 3-channel floating-point image of the same size as \texttt{disparity}.
- Each element of \texttt{\_3dImage(x,y)} will contain the 3D coordinates of the point \texttt{(x,y)}, computed from the disparity map.}
-\cvarg{Q}{The $4 \times 4$ perspective transformation matrix that can be obtained with \cvCppCross{stereoRectify}}
-\cvarg{handleMissingValues}{If true, when the pixels with the minimal disparity (that corresponds to the ouliers; see \cvCppCross{StereoBM}) will be transformed to 3D points with some very large Z value (currently set to 10000)}
+\cvarg{minDisparity}{The minimum possible disparity value. Normally it is 0, but sometimes rectification algorithms can shift images, so this parameter needs to be adjusted accordingly}
+\cvarg{numDisparities}{This is maximum disparity minus minimum disparity. Always greater than 0. In the current implementation this parameter must be divisible by 16.}
+\cvarg{SADWindowSize}{The matched block size. Must be an odd number \texttt{>=1}. Normally, it should be somewhere in \texttt{3..11} range}.
+\cvarg{P1, P2}{Parameters that control disparity smoothness. The larger the values, the smoother the disparity. \texttt{P1} is the penalty on the disparity change by plus or minus 1 between neighbor pixels. \texttt{P2} is the penalty on the disparity change by more than 1 between neighbor pixels. The algorithm requires \texttt{P2 > P1}. See \texttt{stereo\_match.cpp} sample where some reasonably good \texttt{P1} and \texttt{P2} values are shown (like \texttt{8*number\_of\_image\_channels*SADWindowSize*SADWindowSize} and \texttt{32*number\_of\_image\_channels*SADWindowSize*SADWindowSize}, respectively).}
+\cvarg{disp12MaxDiff}{Maximum allowed difference (in integer pixel units) in the left-right disparity check. Set it to non-positive value to disable the check.}
+\cvarg{preFilterCap}{Truncation value for the prefiltered image pixels. The algorithm first computes x-derivative at each pixel and clips its value by \texttt{[-preFilterCap, preFilterCap]} interval. The result values are passed to the Birchfield-Tomasi pixel cost function.}
+\cvarg{uniquenessRatio}{The margin in percents by which the best (minimum) computed cost function value should "win" the second best value to consider the found match correct. Normally, some value within 5-15 range is good enough}
+\cvarg{speckleWindowSize}{Maximum size of smooth disparity regions to consider them noise speckles and invdalidate. Set it to 0 to disable speckle filtering. Otherwise, set it somewhere in 50-200 range.}
+\cvarg{speckleRange}{Maximum disparity variation within each connected component. If you do speckle filtering, set it to some positive value, multiple of 16. Normally, 16 or 32 is good enough.}
+\cvarg{fullDP}{Set it to \texttt{true} to run full-scale 2-pass dynamic programming algorithm. It will consume O(W*H*numDisparities) bytes, which is large for 640x480 stereo and huge for HD-size pictures. By default this is \texttt{false}}
 \end{description}
-The function transforms 1-channel disparity map to 3-channel image representing a 3D surface. That is, for each pixel \texttt{(x,y)} and the corresponding disparity \texttt{d=disparity(x,y)} it computes: 
-
-\[\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}\]
-
-The matrix \texttt{Q} can be arbitrary $4 \times 4$ matrix, e.g. the one computed by \cvCppCross{stereoRectify}. To reproject a sparse set of points {(x,y,d),...} to 3D space, use \cvCppCross{perspectiveTransform}.  
 
+The first constructor initializes \texttt{StereoSGBM} with all the default parameters (so actually one will only have to set \texttt{StereoSGBM::numberOfDisparities} at minimum). The second constructor allows you to set each parameter to a custom value.
 
-\cvCppFunc{solvePnP}
-Finds the camera pose from the 3D-2D point correspondences
+\cvCppFunc{StereoSGBM::operator ()}
+Computes disparity using SGBM algorithm for a rectified stereo pair
 
-\cvdefCpp{void solvePnP( const Mat\& objectPoints,\par
-               const Mat\& imagePoints,\par
-               const Mat\& cameraMatrix,\par
-               const Mat\& distCoeffs,\par
-               Mat\& rvec, Mat\& tvec,\par
-               bool useExtrinsicGuess=false );}
+\cvdefCpp{
+void SGBM::operator()(const Mat\& left, const Mat\& right, Mat\& disp);
+}
 \begin{description}
-\cvarg{objectPoints}{The array of object points, a matrix of type \texttt{CV\_32FC3} or \texttt{vector<Point3f>}}
-\cvarg{imagePoints}{The array of the corresponding image points, a matrix of type{CV\_32FC2} or \texttt{vector<Point2f>}}
-\cvarg{cameraMatrix}{The input camera matrix $\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}$}
-\cvarg{distCoeffs}{The input 4x1, 5x1, 1x4 or 1x5 array of distortion coefficients $(k_1, k_2, p_1, p_2[, k3])$. If it is NULL, all of the distortion coefficients are set to 0}
-\cvarg{rvec}{The output camera view rotation vector (compact representation of a rotation matrix, \cvCppCross{Rodrigues} that (together with \texttt{tvec}) brings points from the model coordinate system to the camera coordinate system}
-\cvarg{tvec}{The output camera view translation vector}
+\cvarg{left}{The left image, 8-bit single-channel or 3-channel.}
+\cvarg{right}{The right image of the same size and the same type as the left one.}
+\cvarg{disp}{The output disparity map. It will be 16-bit signed single-channel image of the same size as the input images. It will contain scaled by 16 disparity values, so that to get the floating-point disparity map, you will need to divide each \texttt{disp} element by 16.}
 \end{description}
 
-The function estimates the camera pose given a set of object points, their corresponding image projections, as well as the camera matrix and the distortion coefficients. This function finds such a pose that minimizes back-projection error, i.e. the sum of squared distances between the observed projections \texttt{imagePoints} and the projected with \cvCppCross{projectPoints} \texttt{objectPoints}.
+The method executes SGBM algorithm on a rectified stereo pair. See \texttt{stereo\_match.cpp} OpenCV sample on how to prepare the images and call the method. Note that the method is not constant, thus you should not use the same \texttt{StereoSGBM} instance from within different threads simultaneously.
 
+\fi
+
+\ifCPy
+\cvCPyFunc{StereoCalibrate}
+\else
 \cvCppFunc{stereoCalibrate}
+\fi
 Calibrates stereo camera.
 
-\cvdefCpp{void stereoCalibrate( const vector<vector<Point3f> >\& objectPoints,\par
+\cvdefC{double cvStereoCalibrate( \par const CvMat* objectPoints, \par const CvMat* imagePoints1,
+                        \par const CvMat* imagePoints2, \par const CvMat* pointCounts,
+                        \par CvMat* cameraMatrix1, \par CvMat* distCoeffs1,
+                        \par CvMat* cameraMatrix2, \par CvMat* distCoeffs2,
+                       \par CvSize imageSize, \par CvMat* R, \par CvMat* T,
+                        \par CvMat* E=0, \par CvMat* F=0,
+                        \par CvTermCriteria term\_crit=cvTermCriteria(
+                               \par CV\_TERMCRIT\_ITER+CV\_TERMCRIT\_EPS,30,1e-6),
+                        \par int flags=CV\_CALIB\_FIX\_INTRINSIC );}
+
+\cvdefPy{StereoCalibrate( objectPoints, imagePoints1, imagePoints2, pointCounts, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, imageSize, R, T, E=NULL, F=NULL, term\_crit=(CV\_TERMCRIT\_ITER+CV\_TERMCRIT\_EPS,30,1e-6), flags=CV\_CALIB\_FIX\_INTRINSIC)-> None}
+
+\cvdefCpp{double stereoCalibrate( const vector<vector<Point3f> >\& objectPoints,\par
                       const vector<vector<Point2f> >\& imagePoints1,\par
                       const vector<vector<Point2f> >\& imagePoints2,\par
                       Mat\& cameraMatrix1, Mat\& distCoeffs1,\par
                       Mat\& cameraMatrix2, Mat\& distCoeffs2,\par
                       Size imageSize, Mat\& R, Mat\& T,\par
                       Mat\& E, Mat\& F,\par
-                      TermCriteria criteria = TermCriteria(TermCriteria::COUNT+\par
+                      TermCriteria term\_crit = TermCriteria(TermCriteria::COUNT+\par
                          TermCriteria::EPS, 30, 1e-6),\par
                       int flags=CALIB\_FIX\_INTRINSIC );}
+
 \begin{description}
-\cvarg{objectPoints}{The vector of vectors of points on the calibration rig in its coordinate system, one vector per a view of the rig. See \cvCppCross{calibrateCamera}}
-\cvarg{imagePoints1}{The vector of vectors of the object point projections to the first camera views, one vector per a view. The projections must be in the same order as the corresponding object points.}
-\cvarg{imagePoints2}{The vector of vectors of the object point projections to the second camera views, one vector per a view. The projections must be in the same order as the corresponding object points.}
-\cvarg{imageSize}{Size of the image, used only to initialize the intrinsic camera matrices}
-\cvarg{cameraMatrix1, cameraMatrix2}{The input/output first and second camera matrices, respectively: $ \vecthreethree{f_x^{(j)}}{0}{c_x^{(j)}}{0}{f_y^{(j)}}{c_y^{(j)}}{0}{0}{1}$, $j = 0,\, 1$. If any of \texttt{CALIB\_USE\_INTRINSIC\_GUESS}, \texttt{CALIB\_FIX\_ASPECT\_RATIO},
-\texttt{CALIB\_FIX\_INTRINSIC} or \texttt{CALIB\_FIX\_FOCAL\_LENGTH} are specified, some or all of the matrices' components must be initialized}
-\cvarg{distCoeffs1, distCoeffs2}{The input/output lens distortion coefficients for the first and the second cameras, 4x1, 5x1, 1x4 or 1x5 floating-point vectors $k_1^{(j)}, k_2^{(j)}, p_1^{(j)}, p_2^{(j)}[, k_3^{(j)}]$, $j = 0,\, 1$. If any of \texttt{CALIB\_FIX\_K1}, \texttt{CALIB\_FIX\_K2} or \texttt{CALIB\_FIX\_K3} is specified, then the corresponding elements of the distortion coefficients must be initialized.}
+\ifCPy
+    \cvarg{objectPoints}{The joint matrix of object points - calibration pattern features in the model coordinate space. It is floating-point 3xN or Nx3 1-channel, or 1xN or Nx1 3-channel array, where N is the total number of points in all views.}
+    \cvarg{imagePoints1}{The joint matrix of object points projections in the first camera views. It is floating-point 2xN or Nx2 1-channel, or 1xN or Nx1 2-channel array, where N is the total number of points in all views}
+    \cvarg{imagePoints2}{The joint matrix of object points projections in the second camera views. It is floating-point 2xN or Nx2 1-channel, or 1xN or Nx1 2-channel array, where N is the total number of points in all views}
+    \cvarg{pointCounts}{Integer 1xM or Mx1 vector (where M is the number of calibration pattern views) containing the number of points in each particular view. The sum of vector elements must match the size of \texttt{objectPoints} and \texttt{imagePoints*} (=N).}
+\fi
+\ifCpp
+    \cvarg{objectPoints}{The vector of vectors of points on the calibration pattern in its coordinate system, one vector per view. If the same calibration pattern is shown in each view and it's fully visible then all the vectors will be the same, although it is possible to use partially occluded patterns, or even different patterns in different views - then the vectors will be different. The points are 3D, but since they are in the pattern coordinate system, then if the rig is planar, it may have sense to put the model to the XY coordinate plane, so that Z-coordinate of each input object point is 0}
+    \cvarg{imagePoints1}{The vector of vectors of the object point projections on the calibration pattern views from the 1st camera, one vector per a view. The projections must be in the same order as the corresponding object points.}
+    \cvarg{imagePoints2}{The vector of vectors of the object point projections on the calibration pattern views from the 2nd camera, one vector per a view. The projections must be in the same order as the corresponding object points.}
+\fi
+    \cvarg{cameraMatrix1}{The input/output first camera matrix: $ \vecthreethree{f_x^{(j)}}{0}{c_x^{(j)}}{0}{f_y^{(j)}}{c_y^{(j)}}{0}{0}{1}$, $j = 0,\, 1$. If any of \texttt{CV\_CALIB\_USE\_INTRINSIC\_GUESS}, \newline \texttt{CV\_CALIB\_FIX\_ASPECT\_RATIO}, \texttt{CV\_CALIB\_FIX\_INTRINSIC} or \texttt{CV\_CALIB\_FIX\_FOCAL\_LENGTH} are specified, some or all of the matrices' components must be initialized; see the flags description}
+    \cvarg{distCoeffs1}{The input/output lens distortion coefficients for the first camera, 4x1, 5x1, 1x4 or 1x5 floating-point vectors $(k_1^{(j)}, k_2^{(j)}, p_1^{(j)}, p_2^{(j)}[, k_3^{(j)}])$, $j = 0,\, 1$. If any of \texttt{CV\_CALIB\_FIX\_K1}, \texttt{CV\_CALIB\_FIX\_K2} or \texttt{CV\_CALIB\_FIX\_K3} is specified, then the corresponding elements of the distortion coefficients must be initialized.}    
+    \cvarg{cameraMatrix2}{The input/output second camera matrix, as cameraMatrix1.}
+    \cvarg{distCoeffs2}{The input/output lens distortion coefficients for the second camera, as distCoeffs1.}
+\cvarg{imageSize}{Size of the image, used only to initialize intrinsic camera matrix.} 
 \cvarg{R}{The output rotation matrix between the 1st and the 2nd cameras' coordinate systems.}
 \cvarg{T}{The output translation vector between the cameras' coordinate systems.}
-\cvarg{E}{The output essential matrix.}
-\cvarg{F}{The output fundamental matrix.}
-\cvarg{criteria}{The termination criteria for the iterative optimiziation algorithm.}
+\cvarg{E}{The \cvCPy{optional} output essential matrix.}
+\cvarg{F}{The \cvCPy{optional} output fundamental matrix.}
+\cvarg{term\_crit}{The termination criteria for the iterative optimization algorithm.}
 \cvarg{flags}{Different flags, may be 0 or combination of the following values:
 \begin{description}
-\cvarg{CALIB\_FIX\_INTRINSIC}{If it is set, \texttt{cameraMatrix?}, as well as \texttt{distCoeffs?} are fixed, so that only \texttt{R, T, E} and \texttt{F} are estimated.}
-\cvarg{CALIB\_USE\_INTRINSIC\_GUESS}{The flag allows the function to optimize some or all of the intrinsic parameters, depending on the other flags, but the initial values are provided by the user.}
-\cvarg{CALIB\_FIX\_PRINCIPAL\_POINT}{The principal points are fixed during the optimization.}
-\cvarg{CALIB\_FIX\_FOCAL\_LENGTH}{$f^{(j)}_x$ and $f^{(j)}_y$ are fixed.}
-\cvarg{CALIB\_FIX\_ASPECT\_RATIO}{$f^{(j)}_y$ is optimized, but the ratio $f^{(j)}_x/f^{(j)}_y$ is fixed.}
-\cvarg{CALIB\_SAME\_FOCAL\_LENGTH}{Enforces $f^{(0)}_x=f^{(1)}_x$ and $f^{(0)}_y=f^{(1)}_y$} \cvarg{CALIB\_ZERO\_TANGENT\_DIST}{Tangential distortion coefficients for each camera are set to zeros and fixed there.}
-\cvarg{CALIB\_FIX\_K1, CALIB\_FIX\_K2, CALIB\_FIX\_K3}{Fixes the corresponding radial distortion coefficient (the coefficient must be passed to the function)}
+\cvarg{CV\_CALIB\_FIX\_INTRINSIC}{If it is set, \texttt{cameraMatrix?}, as well as \texttt{distCoeffs?} are fixed, so that only \texttt{R, T, E} and \texttt{F} are estimated.}
+\cvarg{CV\_CALIB\_USE\_INTRINSIC\_GUESS}{The flag allows the function to optimize some or all of the intrinsic parameters, depending on the other flags, but the initial values are provided by the user.}
+\cvarg{CV\_CALIB\_FIX\_PRINCIPAL\_POINT}{The principal points are fixed during the optimization.}
+\cvarg{CV\_CALIB\_FIX\_FOCAL\_LENGTH}{$f^{(j)}_x$ and $f^{(j)}_y$ are fixed.}
+\cvarg{CV\_CALIB\_FIX\_ASPECT\_RATIO}{$f^{(j)}_y$ is optimized, but the ratio $f^{(j)}_x/f^{(j)}_y$ is fixed.}
+\cvarg{CV\_CALIB\_SAME\_FOCAL\_LENGTH}{Enforces $f^{(0)}_x=f^{(1)}_x$ and $f^{(0)}_y=f^{(1)}_y$} \cvarg{CV\_CALIB\_ZERO\_TANGENT\_DIST}{Tangential distortion coefficients for each camera are set to zeros and fixed there.}
+\cvarg{CV\_CALIB\_FIX\_K1, CV\_CALIB\_FIX\_K2, CV\_CALIB\_FIX\_K3}{Fixes the corresponding radial distortion coefficient (the coefficient must be passed to the function)}
 \end{description}}
 \end{description}
 
-The function estimates transformation between the 2 cameras - heads of a stereo pair. If we have a stereo camera, where the relative position and orientatation of the 2 cameras is fixed, and if we computed poses of an object relative to the fist camera and to the second camera, $(R^{(1)}, T^{(1)})$ and $(R^{(2)}, T^{(2)})$, respectively (that can be done with \cvCppCross{solvePnP}), then, obviously, those poses will relate to each other, by knowing only one of $(R^{(j)}, T^{(j)})$ we can compute the other one:
-
-\[\begin{array}{l}
-R^{(2)}=R*R^{(1)} \\
-T^{(2)}=R*T^{(1)} + T,
-\end{array}
-\]
-
-And, vice versa, if we computed both $(R^{(1)}, T^{(1)})$ and $(R^{(2)}, T^{(2)})$, we can compute the relative position and orientation of the 2 cameras as following:
+The function estimates transformation between the 2 cameras making a stereo pair. If we have a stereo camera, where the relative position and orientation of the 2 cameras is fixed, and if we computed poses of an object relative to the fist camera and to the second camera, (R1, T1) and (R2, T2), respectively (that can be done with \cvCross{FindExtrinsicCameraParams2}{solvePnP}), obviously, those poses will relate to each other, i.e. given ($R_1$, $T_1$) it should be possible to compute ($R_2$, $T_2$) - we only need to know the position and orientation of the 2nd camera relative to the 1st camera. That's what the described function does. It computes ($R$, $T$) such that:
 
-\[\begin{array}{l}
-R=R^{(2)} {R^{(1)}}^{-1} \\
-T=T^{(2)} - R^{(2)} {R^{(1)}}^{-1}*T^{(1)}
-\end{array}
+\[
+R_2=R*R_1
+T_2=R*T_1 + T,
 \]
 
-The function uses this idea, but the actual algorithm is more complex to take all the available pairs of the camera views into account.
-
-Also, the function computes the essential matrix \texttt{E}:
+Optionally, it computes the essential matrix E:
 
 \[
 E=
@@ -1588,35 +1536,62 @@ E=
 {0}{-T_2}{T_1}
 {T_2}{0}{-T_0}
 {-T_1}{T_0}{0}
-*R,
+*R
 \]
 
-where $T_i$ are components of the translation vector $T:\,T=[T_0, T_1, T_2]^T$,
-and the fundamental matrix \texttt{F}:
+where $T_i$ are components of the translation vector $T$: $T=[T_0, T_1, T_2]^T$. And also the function can compute the fundamental matrix F:
 
-\[F = cameraMatrix2^{-T} \cdot E \cdot cameraMatrix1^{-1}\]
+\[F = cameraMatrix2^{-T} E cameraMatrix1^{-1}\]
 
-Besides the stereo-related information, the function can also perform full calibration of each of the 2 cameras. However, because of the high dimensionality of the parameter space and noise in the input data the function can diverge from the correct solution. Thus, if the intrinsic parameters can be estimated with high accuracy for each of the cameras individually (e.g. using \cvCppCross{calibrateCamera}), it is recommended to do so and then pass \texttt{CALIB\_FIX\_INTRINSIC} flag to the function along with the computed intrinsic parameters. Otherwise, if all the parameters are needed to be estimated at once, it makes sense to restrict some parameters, e.g. pass \texttt{CALIB\_SAME\_FOCAL\_LENGTH} and \texttt{CALIB\_ZERO\_TANGENT\_DIST} flags, which are usually reasonable assumptions. 
+Besides the stereo-related information, the function can also perform full calibration of each of the 2 cameras. However, because of the high dimensionality of the parameter space and noise in the input data the function can diverge from the correct solution. Thus, if intrinsic parameters can be estimated with high accuracy for each of the cameras individually (e.g. using \cvCross{CalibrateCamera2}{calibrateCamera}), it is recommended to do so and then pass \texttt{CV\_CALIB\_FIX\_INTRINSIC} flag to the function along with the computed intrinsic parameters. Otherwise, if all the parameters are estimated at once, it makes sense to restrict some parameters, e.g. pass \texttt{CV\_CALIB\_SAME\_FOCAL\_LENGTH} and \texttt{CV\_CALIB\_ZERO\_TANGENT\_DIST} flags, which are usually reasonable assumptions.
 
+Similarly to \cvCross{CalibrateCamera2}{calibrateCamera}, the function minimizes the total re-projection error for all the points in all the available views from both cameras.
+\ifPy
+\else
+The function returns the final value of the re-projection error.
+\fi
 
+\ifCPy
+\cvCPyFunc{StereoRectify}
+\else
 \cvCppFunc{stereoRectify}
+\fi
 Computes rectification transforms for each head of a calibrated stereo camera.
 
+\cvdefC{void cvStereoRectify( \par const CvMat* cameraMatrix1, const CvMat* cameraMatrix2,
+                      \par const CvMat* distCoeffs1, const CvMat* distCoeffs2,
+                      \par CvSize imageSize, const CvMat* R, const CvMat* T,
+                      \par CvMat* R1, CvMat* R2, CvMat* P1, CvMat* P2,
+                      \par CvMat* Q=0, int flags=CV\_CALIB\_ZERO\_DISPARITY,
+                      \par double alpha=-1, CvSize newImageSize=cvSize(0,0),
+                      \par CvRect* roi1=0, CvRect* roi2=0);}
+\cvdefPy{StereoRectify( cameraMatrix1, cameraMatrix2, distCoeffs1, distCoeffs2, imageSize, R, T, R1, R2, P1, P2, Q=NULL, flags=CV\_CALIB\_ZERO\_DISPARITY, alpha=-1, newImageSize=(0,0))-> (roi1, roi2)}
+
 \cvdefCpp{void stereoRectify( const Mat\& cameraMatrix1, const Mat\& distCoeffs1,\par
                     const Mat\& cameraMatrix2, const Mat\& distCoeffs2,\par
                     Size imageSize, const Mat\& R, const Mat\& T,\par
                     Mat\& R1, Mat\& R2, Mat\& P1, Mat\& P2, Mat\& Q,\par
+                    int flags=CALIB\_ZERO\_DISPARITY );\newline
+void stereoRectify( const Mat\& cameraMatrix1, const Mat\& distCoeffs1,\par
+                    const Mat\& cameraMatrix2, const Mat\& distCoeffs2,\par
+                    Size imageSize, const Mat\& R, const Mat\& T,\par
+                    Mat\& R1, Mat\& R2, Mat\& P1, Mat\& P2, Mat\& Q,\par
+                    double alpha, Size newImageSize=Size(),\par
+                    Rect* roi1=0, Rect* roi2=0,\par
                     int flags=CALIB\_ZERO\_DISPARITY );}
 \begin{description}
-\cvarg{cameraMatrix1, cameraMatrix2}{The camera matrices $\vecthreethree{f_x^{(j)}}{0}{c_x^{(j)}}{0}{f_y^{(j)}}{c_y^{(j)}}{0}{0}{1}$}
-\cvarg{distCoeffs1, distCoeffs2}{The vectors of distortion coefficients for each camera, \cvCppCross{4x1, 1x4, 5x1 or 1x5}}
+\cvarg{cameraMatrix1, cameraMatrix2}{The camera matrices $\vecthreethree{f_x^{(j)}}{0}{c_x^{(j)}}{0}{f_y^{(j)}}{c_y^{(j)}}{0}{0}{1}$.}
+\cvarg{distCoeffs1, distCoeffs2}{The input distortion coefficients for each camera, ${k_1}^{(j)}, {k_2}^{(j)}, {p_1}^{(j)}, {p_2}^{(j)} [, {k_3}^{(j)}]$}
 \cvarg{imageSize}{Size of the image used for stereo calibration.}
-\cvarg{R}{The input rotation matrix between the 1st and the 2nd cameras' coordinate systems; can be computed with \cvCppCross{stereoCalibrate}.}
-\cvarg{T}{The translation vector between the cameras' coordinate systems; can be computed with \cvCppCross{stereoCalibrate}.}
+\cvarg{R}{The rotation matrix between the 1st and the 2nd cameras' coordinate systems.}
+\cvarg{T}{The translation vector between the cameras' coordinate systems.}
 \cvarg{R1, R2}{The output $3 \times 3$ rectification transforms (rotation matrices) for the first and the second cameras, respectively.}
 \cvarg{P1, P2}{The output $3 \times 4$ projection matrices in the new (rectified) coordinate systems.}
 \cvarg{Q}{The output $4 \times 4$ disparity-to-depth mapping matrix, see \cvCppCross{reprojectImageTo3D}.}
-\cvarg{flags}{The operation flags; may be 0 or \texttt{CALIB\_ZERO\_DISPARITY}. If the flag is set, the function makes the principal points of each camera have the same pixel coordinates in the rectified views. And if the flag is not set, the function may still shift the images in horizontal or vertical direction (depending on the orientation of epipolar lines) in order to maximize the useful image area.}
+\cvarg{flags}{The operation flags; may be 0 or \texttt{CV\_CALIB\_ZERO\_DISPARITY}. If the flag is set, the function makes the principal points of each camera have the same pixel coordinates in the rectified views. And if the flag is not set, the function may still shift the images in horizontal or vertical direction (depending on the orientation of epipolar lines) in order to maximize the useful image area.}
+\cvarg{alpha}{The free scaling parameter. If it is -1\cvCpp{ or absent}, the functions performs some default scaling. Otherwise the parameter should be between 0 and 1. \texttt{alpha=0} means that the rectified images will be zoomed and shifted so that only valid pixels are visible (i.e. there will be no black areas after rectification). \texttt{alpha=1} means that the rectified image will be decimated and shifted so that all the pixels from the original images from the cameras are retained in the rectified images, i.e. no source image pixels are lost. Obviously, any intermediate value yields some intermediate result between those two extreme cases.}
+\cvarg{newImageSize}{The new image resolution after rectification. The same size should be passed to \cvCross{InitUndistortRectifyMap}{initUndistortRectifyMap}, see the \texttt{stereo\_calib.cpp} sample in OpenCV samples directory. By default, i.e. when (0,0) is passed, it is set to the original \texttt{imageSize}. Setting it to larger value can help you to preserve details in the original image, especially when there is big radial distortion.}
+\cvarg{roi1, roi2}{The optional output rectangles inside the rectified images where all the pixels are valid. If \texttt{alpha=0}, the ROIs will cover the whole images, otherwise they likely be smaller, see the picture below}
 \end{description}
 
 The function computes the rotation matrices for each camera that (virtually) make both camera image planes the same plane. Consequently, that makes all the epipolar lines parallel and thus simplifies the dense stereo correspondence problem. On input the function takes the matrices computed by \cvCppCross{stereoCalibrate} and on output it gives 2 rotation matrices and also 2 projection matrices in the new coordinates. The 2 cases are distinguished by the function are: 
@@ -1640,7 +1615,7 @@ f & 0 & cx_2 & T_x*f\\
 ,
 \]
 
-where $T_x$ is horizontal shift between the cameras and $cx_1=cx_2$ if \texttt{CALIB\_ZERO\_DISPARITY} is set.
+where $T_x$ is horizontal shift between the cameras and $cx_1=cx_2$ if \texttt{CV\_CALIB\_ZERO\_DISPARITY} is set.
 \item Vertical stereo, when 1st and 2nd camera views are shifted relative to each other mainly in vertical direction (and probably a bit in the horizontal direction too). Then the epipolar lines in the rectified images will be vertical and have the same x coordinate. P2 and P2 will look as:
 
 \[
@@ -1665,76 +1640,121 @@ where $T_y$ is vertical shift between the cameras and $cy_1=cy_2$ if \texttt{CAL
 \end{enumerate} 
 
 As you can see, the first 3 columns of \texttt{P1} and \texttt{P2} will effectively be the new "rectified" camera matrices. 
-The matrices, together with \texttt{R1} and \texttt{R2}, can then be passed to \cvCppCross{initUndistortRectifyMap} to initialize the rectification map for each camera.  
+The matrices, together with \texttt{R1} and \texttt{R2}, can then be passed to \cvCross{InitUndistortRectifyMap}{initUndistortRectifyMap} to initialize the rectification map for each camera.
+
+Below is the screenshot from \texttt{stereo\_calib.cpp} sample. Some red horizontal lines, as you can see, pass through the corresponding image regions, i.e. the images are well rectified (which is what most stereo correspondence algorithms rely on). The green rectangles are \texttt{roi1} and \texttt{roi2} - indeed, their interior are all valid pixels.
 
+\includegraphics[width=0.8\textwidth]{pics/stereo_undistort.jpg}
+
+\ifCPy
+\cvCPyFunc{StereoRectifyUncalibrated}
+\else
 \cvCppFunc{stereoRectifyUncalibrated}
-Computes rectification transforms for each head of an uncalibrated stereo camera.
+\fi
+Computes rectification transform for uncalibrated stereo camera.
 
+\cvdefC{void cvStereoRectifyUncalibrated( \par const CvMat* points1, \par const CvMat* points2,
+                                  \par const CvMat* F, \par CvSize imageSize,
+                                  \par CvMat* H1, \par CvMat* H2,
+                                  \par double threshold=5 );}
+\cvdefPy{StereoRectifyUncalibrated(points1,points2,F,imageSize,H1,H2,threshold=5)-> None}
 \cvdefCpp{bool stereoRectifyUncalibrated( const Mat\& points1,\par
                                 const Mat\& points2,\par
                                 const Mat\& F, Size imgSize,\par
                                 Mat\& H1, Mat\& H2,\par
                                 double threshold=5 );}
 \begin{description}
-\cvarg{points1, points2}{The two arrays of corresponding 2D points.}
-\cvarg{F}{Fundamental matrix. It can be computed using the same set of point pairs \texttt{points1} and \texttt{points2}  using \cvCppCross{findFundamentalMat}.}
+\cvarg{points1, points2}{The 2 arrays of corresponding 2D points. The same formats as in \cvCross{FindFundamentalMat}{findFundamentalMat} are supported}
+\cvarg{F}{The input fundamental matrix. It can be computed from the same set of point pairs using \cvCross{FindFundamentalMat}{findFundamentalMat}.}
 \cvarg{imageSize}{Size of the image.}
 \cvarg{H1, H2}{The output rectification homography matrices for the first and for the second images.}
-\cvarg{threshold}{Optional threshold used to filter out the outliers. If the parameter is greater than zero, then all the point pairs that do not comply the epipolar geometry well enough (that is, the points for which $|\texttt{points2[i]}^T*\texttt{F}*\texttt{points1[i]}|>\texttt{threshold}$) are rejected prior to computing the homographies.}
+\cvarg{threshold}{The optional threshold used to filter out the outliers. If the parameter is greater than zero, then all the point pairs that do not comply the epipolar geometry well enough (that is, the points for which $|\texttt{points2[i]}^T*\texttt{F}*\texttt{points1[i]}|>\texttt{threshold}$) are rejected prior to computing the homographies.
+Otherwise all the points are considered inliers.}
 \end{description}
 
-The function computes the rectification transformations without knowing intrinsic parameters of the cameras and their relative position in space, hence the suffix "Uncalibrated". Another related difference from \cvCppCross{stereoRectify} is that the function outputs not the rectification transformations in the object (3D) space, but the planar perspective transformations, encoded by the homography matrices \texttt{H1} and \texttt{H2}. The function implements the algorithm \cite{Hartley99}. 
+The function computes the rectification transformations without knowing intrinsic parameters of the cameras and their relative position in space, hence the suffix "Uncalibrated". Another related difference from \cvCross{StereoRectify}{stereoRectify} is that the function outputs not the rectification transformations in the object (3D) space, but the planar perspective transformations, encoded by the homography matrices \texttt{H1} and \texttt{H2}. The function implements the algorithm \cite{Hartley99}. 
 
-Note that while the algorithm does not need to know the intrinsic parameters of the cameras, it heavily depends on the epipolar geometry. Therefore, if the camera lenses have significant distortion, it would better be corrected before computing the fundamental matrix and calling this function. For example, distortion coefficients can be estimated for each head of stereo camera separately by using \cvCppCross{calibrateCamera} and then the images can be corrected using \cvCppCross{undistort}, or just the point coordinates can be corrected with \cvCppCross{undistortPoints}. 
+Note that while the algorithm does not need to know the intrinsic parameters of the cameras, it heavily depends on the epipolar geometry. Therefore, if the camera lenses have significant distortion, it would better be corrected before computing the fundamental matrix and calling this function. For example, distortion coefficients can be estimated for each head of stereo camera separately by using \cvCross{CalibrateCamera2}{calibrateCamera} and then the images can be corrected using \cvCross{Undistort2}{undistort}, or just the point coordinates can be corrected with \cvCross{UndistortPoints}{undistortPoints}.
 
-\cvCppFunc{StereoBM}
-The class for computing stereo correspondence using block matching algorithm.
 
-\begin{lstlisting}
-// Block matching stereo correspondence algorithm\par
-class StereoBM
-{
-    enum { NORMALIZED_RESPONSE = CV_STEREO_BM_NORMALIZED_RESPONSE,
-        BASIC_PRESET=CV_STEREO_BM_BASIC,
-        FISH_EYE_PRESET=CV_STEREO_BM_FISH_EYE,
-        NARROW_PRESET=CV_STEREO_BM_NARROW };
+\ifCPy
+\cvCPyFunc{Undistort2}
+\else
+\cvCppFunc{undistort}
+\fi
+Transforms an image to compensate for lens distortion.
 
-    StereoBM();
-    // the preset is one of ..._PRESET above.
-    // ndisparities is the size of disparity range,
-    // in which the optimal disparity at each pixel is searched for.
-    // SADWindowSize is the size of averaging window used to match pixel blocks
-    //    (larger values mean better robustness to noise, but yield blurry disparity maps)
-    StereoBM(int preset, int ndisparities=0, int SADWindowSize=21);
-    // separate initialization function
-    void init(int preset, int ndisparities=0, int SADWindowSize=21);
-    // computes the disparity for the two rectified 8-bit single-channel images.
-    // the disparity will be 16-bit singed image of the same size as left.
-    void operator()( const Mat& left, const Mat& right, Mat& disparity );
+\cvdefC{void cvUndistort2( \par const CvArr* src,\par CvArr* dst,\par const CvMat* cameraMatrix,
+    \par const CvMat* distCoeffs, \par const CvMat* newCameraMatrix=0 );}
+\cvdefPy{Undistort2(src,dst,cameraMatrix,distCoeffs)-> None}
 
-    Ptr<CvStereoBMState> state;
-};
-\end{lstlisting}
+\cvdefCpp{void undistort( const Mat\& src, Mat\& dst, const Mat\& cameraMatrix,\par
+                const Mat\& distCoeffs, const Mat\& newCameraMatrix=Mat() );}
+\begin{description}
+\cvarg{src}{The input (distorted) image}
+\cvarg{dst}{The output (corrected) image; will have the same size and the same type as \texttt{src}}
+\cvarg{cameraMatrix}{The input camera matrix $A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1} $}
+\cvarg{distCoeffs}{The vector of distortion coefficients, $(k_1^{(j)}, k_2^{(j)}, p_1^{(j)}, p_2^{(j)}[, k_3^{(j)}])$}
+\cvCpp{\cvarg{newCameraMatrix}{Camera matrix of the distorted image. By default it is the same as \texttt{cameraMatrix}, but you may additionally scale and shift the result by using some different matrix}}
+\end{description}
+
+The function transforms the image to compensate radial and tangential lens distortion.
+
+The function is simply a combination of \cvCross{InitUndistortRectifyMap}{initUndistortRectifyMap} (with unity \texttt{R}) and \cvCross{Remap}{remap} (with bilinear interpolation). See the former function for details of the transformation being performed.
+
+Those pixels in the destination image, for which there is no correspondent pixels in the source image, are filled with 0's (black color).
+
+The particular subset of the source image that will be visible in the corrected image can be regulated by \texttt{newCameraMatrix}. You can use \cvCross{GetOptimalNewCameraMatrix}{getOptimalNewCameraMatrix} to compute the appropriate \texttt{newCameraMatrix}, depending on your requirements.
+
+The camera matrix and the distortion parameters can be determined using
+\cvCross{CalibrateCamera2}{calibrateCamera}. If the resolution of images is different from the used at the calibration stage, $f_x, f_y, c_x$ and $c_y$ need to be scaled accordingly, while the distortion coefficients remain the same.
 
 
+\ifCPy
+\cvCPyFunc{UndistortPoints}
+\else
 \cvCppFunc{undistortPoints}
+\fi
 Computes the ideal point coordinates from the observed point coordinates.
 
+\cvdefC{void cvUndistortPoints( \par const CvMat* src, \par CvMat* dst,
+                        \par const CvMat* cameraMatrix,
+                        \par const CvMat* distCoeffs,
+                        \par const CvMat* R=NULL,
+                        \par const CvMat* P=NULL);}
+\cvdefPy{UndistortPoints(src,dst,cameraMatrix,distCoeffs,R=NULL,P=NULL)-> None}
+
 \cvdefCpp{void undistortPoints( const Mat\& src, vector<Point2f>\& dst,\par
                       const Mat\& cameraMatrix, const Mat\& distCoeffs,\par
                       const Mat\& R=Mat(), const Mat\& P=Mat());\newline
 void undistortPoints( const Mat\& src, Mat\& dst,\par
                       const Mat\& cameraMatrix, const Mat\& distCoeffs,\par
                       const Mat\& R=Mat(), const Mat\& P=Mat());}
+
 \begin{description}
-\cvarg{src}{The observed point coordinates, a matrix or vector of 2D points.}
-\cvarg{dst}{The ideal point coordinates, after undistortion and reverse perspective transformation}
+\cvarg{src}{The observed point coordinates, same format as \texttt{imagePoints} in \cvCross{ProjectPoints2}{projectPoints}}
+\cvarg{dst}{The output ideal point coordinates, after undistortion and reverse perspective transformation\cvCPy{, same format as \texttt{src}}.}
 \cvarg{cameraMatrix}{The camera matrix $\vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}$}
-\cvarg{distCoeffs}{he vector of distortion coefficients, \cvCppCross{4x1, 1x4, 5x1 or 1x5}}
+\cvarg{distCoeffs}{The vector of distortion coefficients, $(k_1^{(j)}, k_2^{(j)}, p_1^{(j)}, p_2^{(j)}[, k_3^{(j)}])$}
 \cvarg{R}{The rectification transformation in object space (3x3 matrix). \texttt{R1} or \texttt{R2}, computed by \cvCppCross{StereoRectify} can be passed here. If the matrix is empty, the identity transformation is used}
 \cvarg{P}{The new camera matrix (3x3) or the new projection matrix (3x4). \texttt{P1} or \texttt{P2}, computed by \cvCppCross{StereoRectify} can be passed here. If the matrix is empty, the identity new camera matrix is used}
 \end{description}
 
-The function is similar to \cvCppCross{undistort} and \cvCppCross{initUndistortRectifyMap}, but it operates on a sparse set of points instead of a raster image. Also the function does some kind of reverse transformation to \cvCppCross{projectPoints} (in the case of 3D object it will not reconstruct its 3D coordinates, of course; but for a planar object it will, up to a translation vector, if the proper \texttt{R} is specified).
+The function is similar to \cvCross{Undistort2}{undistort} and \cvCross{InitUndistortRectifyMap}{initUndistortRectifyMap}, but it operates on a sparse set of points instead of a raster image. Also the function does some kind of reverse transformation to \cvCross{ProjectPoints2}{projectPoints} (in the case of 3D object it will not reconstruct its 3D coordinates, of course; but for a planar object it will, up to a translation vector, if the proper \texttt{R} is specified).
 
-\fi
+\begin{lstlisting}
+// (u,v) is the input point, (u', v') is the output point
+// camera_matrix=[fx 0 cx; 0 fy cy; 0 0 1]
+// P=[fx' 0 cx' tx; 0 fy' cy' ty; 0 0 1 tz]
+x" = (u - cx)/fx
+y" = (v - cy)/fy
+(x',y') = undistort(x",y",dist_coeffs)
+[X,Y,W]T = R*[x' y' 1]T
+x = X/W, y = Y/W
+u' = x*fx' + cx'
+v' = y*fy' + cy',
+\end{lstlisting}
+
+where undistort() is approximate iterative algorithm that estimates the normalized original point coordinates out of the normalized distorted point coordinates ("normalized" means that the coordinates do not depend on the camera matrix).
+
+The function can be used both for a stereo camera head or for monocular camera (when R is \cvC{NULL}\cvPy{None}\cvCpp{empty}).