include/opencv2/calib3d/calib3d.hpp
Go to the documentation of this file.
00001 /*M///////////////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
00004 //
00005 //  By downloading, copying, installing or using the software you agree to this license.
00006 //  If you do not agree to this license, do not download, install,
00007 //  copy or use the software.
00008 //
00009 //
00010 //                           License Agreement
00011 //                For Open Source Computer Vision Library
00012 //
00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
00015 // Third party copyrights are property of their respective owners.
00016 //
00017 // Redistribution and use in source and binary forms, with or without modification,
00018 // are permitted provided that the following conditions are met:
00019 //
00020 //   * Redistribution's of source code must retain the above copyright notice,
00021 //     this list of conditions and the following disclaimer.
00022 //
00023 //   * Redistribution's in binary form must reproduce the above copyright notice,
00024 //     this list of conditions and the following disclaimer in the documentation
00025 //     and/or other materials provided with the distribution.
00026 //
00027 //   * The name of the copyright holders may not be used to endorse or promote products
00028 //     derived from this software without specific prior written permission.
00029 //
00030 // This software is provided by the copyright holders and contributors "as is" and
00031 // any express or implied warranties, including, but not limited to, the implied
00032 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00033 // In no event shall the Intel Corporation or contributors be liable for any direct,
00034 // indirect, incidental, special, exemplary, or consequential damages
00035 // (including, but not limited to, procurement of substitute goods or services;
00036 // loss of use, data, or profits; or business interruption) however caused
00037 // and on any theory of liability, whether in contract, strict liability,
00038 // or tort (including negligence or otherwise) arising in any way out of
00039 // the use of this software, even if advised of the possibility of such damage.
00040 //
00041 //M*/
00042 
00043 #ifndef __OPENCV_CALIB3D_HPP__
00044 #define __OPENCV_CALIB3D_HPP__
00045 
00046 #include "opencv2/core/core.hpp"
00047 #include "opencv2/features2d/features2d.hpp"
00048 
00049 #ifdef __cplusplus
00050 extern "C" {
00051 #endif
00052 
00053 /****************************************************************************************\
00054 *                      Camera Calibration, Pose Estimation and Stereo                    *
00055 \****************************************************************************************/
00056 
00057 typedef struct CvPOSITObject CvPOSITObject;
00058 
00059 /* Allocates and initializes CvPOSITObject structure before doing cvPOSIT */
00060 CVAPI(CvPOSITObject*)  cvCreatePOSITObject( CvPoint3D32f* points, int point_count );
00061 
00062 
00063 /* Runs POSIT (POSe from ITeration) algorithm for determining 3d position of
00064    an object given its model and projection in a weak-perspective case */
00065 CVAPI(void)  cvPOSIT(  CvPOSITObject* posit_object, CvPoint2D32f* image_points,
00066                        double focal_length, CvTermCriteria criteria,
00067                        float* rotation_matrix, float* translation_vector);
00068 
00069 /* Releases CvPOSITObject structure */
00070 CVAPI(void)  cvReleasePOSITObject( CvPOSITObject**  posit_object );
00071 
00072 /* updates the number of RANSAC iterations */
00073 CVAPI(int) cvRANSACUpdateNumIters( double p, double err_prob,
00074                                    int model_points, int max_iters );
00075 
00076 CVAPI(void) cvConvertPointsHomogeneous( const CvMat* src, CvMat* dst );
00077 
00078 /* Calculates fundamental matrix given a set of corresponding points */
00079 #define CV_FM_7POINT 1
00080 #define CV_FM_8POINT 2
00081 
00082 #define CV_LMEDS 4
00083 #define CV_RANSAC 8
00084 
00085 #define CV_FM_LMEDS_ONLY  CV_LMEDS
00086 #define CV_FM_RANSAC_ONLY CV_RANSAC
00087 #define CV_FM_LMEDS CV_LMEDS
00088 #define CV_FM_RANSAC CV_RANSAC
00089 
00090 enum
00091 {
00092     CV_ITERATIVE = 0,
00093     CV_EPNP = 1, // F.Moreno-Noguer, V.Lepetit and P.Fua "EPnP: Efficient Perspective-n-Point Camera Pose Estimation"
00094     CV_P3P = 2 // X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang; "Complete Solution Classification for the Perspective-Three-Point Problem"
00095 };
00096 
00097 CVAPI(int) cvFindFundamentalMat( const CvMat* points1, const CvMat* points2,
00098                                  CvMat* fundamental_matrix,
00099                                  int method CV_DEFAULT(CV_FM_RANSAC),
00100                                  double param1 CV_DEFAULT(3.), double param2 CV_DEFAULT(0.99),
00101                                  CvMat* status CV_DEFAULT(NULL) );
00102 
00103 /* For each input point on one of images
00104    computes parameters of the corresponding
00105    epipolar line on the other image */
00106 CVAPI(void) cvComputeCorrespondEpilines( const CvMat* points,
00107                                          int which_image,
00108                                          const CvMat* fundamental_matrix,
00109                                          CvMat* correspondent_lines );
00110 
00111 /* Triangulation functions */
00112 
00113 CVAPI(void) cvTriangulatePoints(CvMat* projMatr1, CvMat* projMatr2,
00114                                 CvMat* projPoints1, CvMat* projPoints2,
00115                                 CvMat* points4D);
00116 
00117 CVAPI(void) cvCorrectMatches(CvMat* F, CvMat* points1, CvMat* points2,
00118                              CvMat* new_points1, CvMat* new_points2);
00119 
00120 
00121 /* Computes the optimal new camera matrix according to the free scaling parameter alpha:
00122    alpha=0 - only valid pixels will be retained in the undistorted image
00123    alpha=1 - all the source image pixels will be retained in the undistorted image
00124 */
00125 CVAPI(void) cvGetOptimalNewCameraMatrix( const CvMat* camera_matrix,
00126                                          const CvMat* dist_coeffs,
00127                                          CvSize image_size, double alpha,
00128                                          CvMat* new_camera_matrix,
00129                                          CvSize new_imag_size CV_DEFAULT(cvSize(0,0)),
00130                                          CvRect* valid_pixel_ROI CV_DEFAULT(0),
00131                                          int center_principal_point CV_DEFAULT(0));
00132 
00133 /* Converts rotation vector to rotation matrix or vice versa */
00134 CVAPI(int) cvRodrigues2( const CvMat* src, CvMat* dst,
00135                          CvMat* jacobian CV_DEFAULT(0) );
00136 
00137 /* Finds perspective transformation between the object plane and image (view) plane */
00138 CVAPI(int) cvFindHomography( const CvMat* src_points,
00139                              const CvMat* dst_points,
00140                              CvMat* homography,
00141                              int method CV_DEFAULT(0),
00142                              double ransacReprojThreshold CV_DEFAULT(3),
00143                              CvMat* mask CV_DEFAULT(0));
00144 
00145 /* Computes RQ decomposition for 3x3 matrices */
00146 CVAPI(void) cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ,
00147                            CvMat *matrixQx CV_DEFAULT(NULL),
00148                            CvMat *matrixQy CV_DEFAULT(NULL),
00149                            CvMat *matrixQz CV_DEFAULT(NULL),
00150                            CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
00151 
00152 /* Computes projection matrix decomposition */
00153 CVAPI(void) cvDecomposeProjectionMatrix( const CvMat *projMatr, CvMat *calibMatr,
00154                                          CvMat *rotMatr, CvMat *posVect,
00155                                          CvMat *rotMatrX CV_DEFAULT(NULL),
00156                                          CvMat *rotMatrY CV_DEFAULT(NULL),
00157                                          CvMat *rotMatrZ CV_DEFAULT(NULL),
00158                                          CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
00159 
00160 /* Computes d(AB)/dA and d(AB)/dB */
00161 CVAPI(void) cvCalcMatMulDeriv( const CvMat* A, const CvMat* B, CvMat* dABdA, CvMat* dABdB );
00162 
00163 /* Computes r3 = rodrigues(rodrigues(r2)*rodrigues(r1)),
00164    t3 = rodrigues(r2)*t1 + t2 and the respective derivatives */
00165 CVAPI(void) cvComposeRT( const CvMat* _rvec1, const CvMat* _tvec1,
00166                          const CvMat* _rvec2, const CvMat* _tvec2,
00167                          CvMat* _rvec3, CvMat* _tvec3,
00168                          CvMat* dr3dr1 CV_DEFAULT(0), CvMat* dr3dt1 CV_DEFAULT(0),
00169                          CvMat* dr3dr2 CV_DEFAULT(0), CvMat* dr3dt2 CV_DEFAULT(0),
00170                          CvMat* dt3dr1 CV_DEFAULT(0), CvMat* dt3dt1 CV_DEFAULT(0),
00171                          CvMat* dt3dr2 CV_DEFAULT(0), CvMat* dt3dt2 CV_DEFAULT(0) );
00172 
00173 /* Projects object points to the view plane using
00174    the specified extrinsic and intrinsic camera parameters */
00175 CVAPI(void) cvProjectPoints2( const CvMat* object_points, const CvMat* rotation_vector,
00176                               const CvMat* translation_vector, const CvMat* camera_matrix,
00177                               const CvMat* distortion_coeffs, CvMat* image_points,
00178                               CvMat* dpdrot CV_DEFAULT(NULL), CvMat* dpdt CV_DEFAULT(NULL),
00179                               CvMat* dpdf CV_DEFAULT(NULL), CvMat* dpdc CV_DEFAULT(NULL),
00180                               CvMat* dpddist CV_DEFAULT(NULL),
00181                               double aspect_ratio CV_DEFAULT(0));
00182 
00183 /* Finds extrinsic camera parameters from
00184    a few known corresponding point pairs and intrinsic parameters */
00185 CVAPI(void) cvFindExtrinsicCameraParams2( const CvMat* object_points,
00186                                           const CvMat* image_points,
00187                                           const CvMat* camera_matrix,
00188                                           const CvMat* distortion_coeffs,
00189                                           CvMat* rotation_vector,
00190                                           CvMat* translation_vector,
00191                                           int use_extrinsic_guess CV_DEFAULT(0) );
00192 
00193 /* Computes initial estimate of the intrinsic camera parameters
00194    in case of planar calibration target (e.g. chessboard) */
00195 CVAPI(void) cvInitIntrinsicParams2D( const CvMat* object_points,
00196                                      const CvMat* image_points,
00197                                      const CvMat* npoints, CvSize image_size,
00198                                      CvMat* camera_matrix,
00199                                      double aspect_ratio CV_DEFAULT(1.) );
00200 
00201 #define CV_CALIB_CB_ADAPTIVE_THRESH  1
00202 #define CV_CALIB_CB_NORMALIZE_IMAGE  2
00203 #define CV_CALIB_CB_FILTER_QUADS     4
00204 #define CV_CALIB_CB_FAST_CHECK       8
00205 
00206 // Performs a fast check if a chessboard is in the input image. This is a workaround to
00207 // a problem of cvFindChessboardCorners being slow on images with no chessboard
00208 // - src: input image
00209 // - size: chessboard size
00210 // Returns 1 if a chessboard can be in this image and findChessboardCorners should be called,
00211 // 0 if there is no chessboard, -1 in case of error
00212 CVAPI(int) cvCheckChessboard(IplImage* src, CvSize size);
00213 
00214     /* Detects corners on a chessboard calibration pattern */
00215 CVAPI(int) cvFindChessboardCorners( const void* image, CvSize pattern_size,
00216                                     CvPoint2D32f* corners,
00217                                     int* corner_count CV_DEFAULT(NULL),
00218                                     int flags CV_DEFAULT(CV_CALIB_CB_ADAPTIVE_THRESH+CV_CALIB_CB_NORMALIZE_IMAGE) );
00219 
00220 /* Draws individual chessboard corners or the whole chessboard detected */
00221 CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size,
00222                                      CvPoint2D32f* corners,
00223                                      int count, int pattern_was_found );
00224 
00225 #define CV_CALIB_USE_INTRINSIC_GUESS  1
00226 #define CV_CALIB_FIX_ASPECT_RATIO     2
00227 #define CV_CALIB_FIX_PRINCIPAL_POINT  4
00228 #define CV_CALIB_ZERO_TANGENT_DIST    8
00229 #define CV_CALIB_FIX_FOCAL_LENGTH 16
00230 #define CV_CALIB_FIX_K1  32
00231 #define CV_CALIB_FIX_K2  64
00232 #define CV_CALIB_FIX_K3  128
00233 #define CV_CALIB_FIX_K4  2048
00234 #define CV_CALIB_FIX_K5  4096
00235 #define CV_CALIB_FIX_K6  8192
00236 #define CV_CALIB_RATIONAL_MODEL 16384
00237 
00238 /* Finds intrinsic and extrinsic camera parameters
00239    from a few views of known calibration pattern */
00240 CVAPI(double) cvCalibrateCamera2( const CvMat* object_points,
00241                                 const CvMat* image_points,
00242                                 const CvMat* point_counts,
00243                                 CvSize image_size,
00244                                 CvMat* camera_matrix,
00245                                 CvMat* distortion_coeffs,
00246                                 CvMat* rotation_vectors CV_DEFAULT(NULL),
00247                                 CvMat* translation_vectors CV_DEFAULT(NULL),
00248                                 int flags CV_DEFAULT(0),
00249                                 CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria(
00250                                     CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,DBL_EPSILON)) );
00251 
00252 /* Computes various useful characteristics of the camera from the data computed by
00253    cvCalibrateCamera2 */
00254 CVAPI(void) cvCalibrationMatrixValues( const CvMat *camera_matrix,
00255                                 CvSize image_size,
00256                                 double aperture_width CV_DEFAULT(0),
00257                                 double aperture_height CV_DEFAULT(0),
00258                                 double *fovx CV_DEFAULT(NULL),
00259                                 double *fovy CV_DEFAULT(NULL),
00260                                 double *focal_length CV_DEFAULT(NULL),
00261                                 CvPoint2D64f *principal_point CV_DEFAULT(NULL),
00262                                 double *pixel_aspect_ratio CV_DEFAULT(NULL));
00263 
00264 #define CV_CALIB_FIX_INTRINSIC  256
00265 #define CV_CALIB_SAME_FOCAL_LENGTH 512
00266 
00267 /* Computes the transformation from one camera coordinate system to another one
00268    from a few correspondent views of the same calibration target. Optionally, calibrates
00269    both cameras */
00270 CVAPI(double) cvStereoCalibrate( const CvMat* object_points, const CvMat* image_points1,
00271                                const CvMat* image_points2, const CvMat* npoints,
00272                                CvMat* camera_matrix1, CvMat* dist_coeffs1,
00273                                CvMat* camera_matrix2, CvMat* dist_coeffs2,
00274                                CvSize image_size, CvMat* R, CvMat* T,
00275                                CvMat* E CV_DEFAULT(0), CvMat* F CV_DEFAULT(0),
00276                                CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria(
00277                                    CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,1e-6)),
00278                                int flags CV_DEFAULT(CV_CALIB_FIX_INTRINSIC));
00279 
00280 #define CV_CALIB_ZERO_DISPARITY 1024
00281 
00282 /* Computes 3D rotations (+ optional shift) for each camera coordinate system to make both
00283    views parallel (=> to make all the epipolar lines horizontal or vertical) */
00284 CVAPI(void) cvStereoRectify( const CvMat* camera_matrix1, const CvMat* camera_matrix2,
00285                              const CvMat* dist_coeffs1, const CvMat* dist_coeffs2,
00286                              CvSize image_size, const CvMat* R, const CvMat* T,
00287                              CvMat* R1, CvMat* R2, CvMat* P1, CvMat* P2,
00288                              CvMat* Q CV_DEFAULT(0),
00289                              int flags CV_DEFAULT(CV_CALIB_ZERO_DISPARITY),
00290                              double alpha CV_DEFAULT(-1),
00291                              CvSize new_image_size CV_DEFAULT(cvSize(0,0)),
00292                              CvRect* valid_pix_ROI1 CV_DEFAULT(0),
00293                              CvRect* valid_pix_ROI2 CV_DEFAULT(0));
00294 
00295 /* Computes rectification transformations for uncalibrated pair of images using a set
00296    of point correspondences */
00297 CVAPI(int) cvStereoRectifyUncalibrated( const CvMat* points1, const CvMat* points2,
00298                                         const CvMat* F, CvSize img_size,
00299                                         CvMat* H1, CvMat* H2,
00300                                         double threshold CV_DEFAULT(5));
00301 
00302 
00303 
00304 /* stereo correspondence parameters and functions */
00305 
00306 #define CV_STEREO_BM_NORMALIZED_RESPONSE  0
00307 #define CV_STEREO_BM_XSOBEL               1
00308 
00309 /* Block matching algorithm structure */
00310 typedef struct CvStereoBMState
00311 {
00312     // pre-filtering (normalization of input images)
00313     int preFilterType; // =CV_STEREO_BM_NORMALIZED_RESPONSE now
00314     int preFilterSize; // averaging window size: ~5x5..21x21
00315     int preFilterCap; // the output of pre-filtering is clipped by [-preFilterCap,preFilterCap]
00316 
00317     // correspondence using Sum of Absolute Difference (SAD)
00318     int SADWindowSize; // ~5x5..21x21
00319     int minDisparity;  // minimum disparity (can be negative)
00320     int numberOfDisparities; // maximum disparity - minimum disparity (> 0)
00321 
00322     // post-filtering
00323     int textureThreshold;  // the disparity is only computed for pixels
00324                            // with textured enough neighborhood
00325     int uniquenessRatio;   // accept the computed disparity d* only if
00326                            // SAD(d) >= SAD(d*)*(1 + uniquenessRatio/100.)
00327                            // for any d != d*+/-1 within the search range.
00328     int speckleWindowSize; // disparity variation window
00329     int speckleRange; // acceptable range of variation in window
00330 
00331     int trySmallerWindows; // if 1, the results may be more accurate,
00332                            // at the expense of slower processing
00333     CvRect roi1, roi2;
00334     int disp12MaxDiff;
00335 
00336     // temporary buffers
00337     CvMat* preFilteredImg0;
00338     CvMat* preFilteredImg1;
00339     CvMat* slidingSumBuf;
00340     CvMat* cost;
00341     CvMat* disp;
00342 } CvStereoBMState;
00343 
00344 #define CV_STEREO_BM_BASIC 0
00345 #define CV_STEREO_BM_FISH_EYE 1
00346 #define CV_STEREO_BM_NARROW 2
00347 
00348 CVAPI(CvStereoBMState*) cvCreateStereoBMState(int preset CV_DEFAULT(CV_STEREO_BM_BASIC),
00349                                               int numberOfDisparities CV_DEFAULT(0));
00350 
00351 CVAPI(void) cvReleaseStereoBMState( CvStereoBMState** state );
00352 
00353 CVAPI(void) cvFindStereoCorrespondenceBM( const CvArr* left, const CvArr* right,
00354                                           CvArr* disparity, CvStereoBMState* state );
00355 
00356 CVAPI(CvRect) cvGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity,
00357                                       int numberOfDisparities, int SADWindowSize );
00358 
00359 CVAPI(void) cvValidateDisparity( CvArr* disparity, const CvArr* cost,
00360                                  int minDisparity, int numberOfDisparities,
00361                                  int disp12MaxDiff CV_DEFAULT(1) );
00362 
00363 /* Reprojects the computed disparity image to the 3D space using the specified 4x4 matrix */
00364 CVAPI(void)  cvReprojectImageTo3D( const CvArr* disparityImage,
00365                                    CvArr* _3dImage, const CvMat* Q,
00366                                    int handleMissingValues CV_DEFAULT(0) );
00367 
00368 
00369 #ifdef __cplusplus
00370 }
00371 
00373 class CV_EXPORTS CvLevMarq
00374 {
00375 public:
00376     CvLevMarq();
00377     CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria=
00378               cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
00379               bool completeSymmFlag=false );
00380     ~CvLevMarq();
00381     void init( int nparams, int nerrs, CvTermCriteria criteria=
00382               cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
00383               bool completeSymmFlag=false );
00384     bool update( const CvMat*& param, CvMat*& J, CvMat*& err );
00385     bool updateAlt( const CvMat*& param, CvMat*& JtJ, CvMat*& JtErr, double*& errNorm );
00386 
00387     void clear();
00388     void step();
00389     enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 };
00390 
00391     cv::Ptr<CvMat> mask;
00392     cv::Ptr<CvMat> prevParam;
00393     cv::Ptr<CvMat> param;
00394     cv::Ptr<CvMat> J;
00395     cv::Ptr<CvMat> err;
00396     cv::Ptr<CvMat> JtJ;
00397     cv::Ptr<CvMat> JtJN;
00398     cv::Ptr<CvMat> JtErr;
00399     cv::Ptr<CvMat> JtJV;
00400     cv::Ptr<CvMat> JtJW;
00401     double prevErrNorm, errNorm;
00402     int lambdaLg10;
00403     CvTermCriteria criteria;
00404     int state;
00405     int iters;
00406     bool completeSymmFlag;
00407 };
00408 
00409 namespace cv
00410 {
00412 CV_EXPORTS_W void Rodrigues(InputArray src, OutputArray dst, OutputArray jacobian=noArray());
00413 
00415 enum
00416 {
00417     LMEDS=CV_LMEDS, 
00418     RANSAC=CV_RANSAC 
00419 };
00420 
00422 CV_EXPORTS_W Mat findHomography( InputArray srcPoints, InputArray dstPoints,
00423                                  int method=0, double ransacReprojThreshold=3,
00424                                  OutputArray mask=noArray());
00425 
00427 CV_EXPORTS Mat findHomography( InputArray srcPoints, InputArray dstPoints,
00428                                OutputArray mask, int method=0, double ransacReprojThreshold=3);
00429 
00431 CV_EXPORTS_W Vec3d RQDecomp3x3( InputArray src, OutputArray mtxR, OutputArray mtxQ,
00432                                 OutputArray Qx=noArray(),
00433                                 OutputArray Qy=noArray(),
00434                                 OutputArray Qz=noArray());
00435 
00437 CV_EXPORTS_W void decomposeProjectionMatrix( InputArray projMatrix, OutputArray cameraMatrix,
00438                                              OutputArray rotMatrix, OutputArray transVect,
00439                                              OutputArray rotMatrixX=noArray(),
00440                                              OutputArray rotMatrixY=noArray(),
00441                                              OutputArray rotMatrixZ=noArray(),
00442                                              OutputArray eulerAngles=noArray() );
00443 
00445 CV_EXPORTS_W void matMulDeriv( InputArray A, InputArray B,
00446                                OutputArray dABdA,
00447                                OutputArray dABdB );
00448 
00450 CV_EXPORTS_W void composeRT( InputArray rvec1, InputArray tvec1,
00451                              InputArray rvec2, InputArray tvec2,
00452                              OutputArray rvec3, OutputArray tvec3,
00453                              OutputArray dr3dr1=noArray(), OutputArray dr3dt1=noArray(),
00454                              OutputArray dr3dr2=noArray(), OutputArray dr3dt2=noArray(),
00455                              OutputArray dt3dr1=noArray(), OutputArray dt3dt1=noArray(),
00456                              OutputArray dt3dr2=noArray(), OutputArray dt3dt2=noArray() );
00457 
00459 CV_EXPORTS_W void projectPoints( InputArray objectPoints,
00460                                  InputArray rvec, InputArray tvec,
00461                                  InputArray cameraMatrix, InputArray distCoeffs,
00462                                  OutputArray imagePoints,
00463                                  OutputArray jacobian=noArray(),
00464                                  double aspectRatio=0 );
00465 
00467 enum
00468 {
00469     ITERATIVE=CV_ITERATIVE,
00470     EPNP=CV_EPNP,
00471     P3P=CV_P3P
00472 };
00473 CV_EXPORTS_W bool solvePnP( InputArray objectPoints, InputArray imagePoints,
00474                             InputArray cameraMatrix, InputArray distCoeffs,
00475                             OutputArray rvec, OutputArray tvec,
00476                             bool useExtrinsicGuess=false, int flags=ITERATIVE);
00477 
00479 CV_EXPORTS_W void solvePnPRansac( InputArray objectPoints,
00480                                   InputArray imagePoints,
00481                                   InputArray cameraMatrix,
00482                                   InputArray distCoeffs,
00483                                   OutputArray rvec,
00484                                   OutputArray tvec,
00485                                   bool useExtrinsicGuess = false,
00486                                   int iterationsCount = 100,
00487                                   float reprojectionError = 8.0,
00488                                   int minInliersCount = 100,
00489                                   OutputArray inliers = noArray(),
00490                                   int flags = ITERATIVE);
00491 
00493 CV_EXPORTS_W Mat initCameraMatrix2D( InputArrayOfArrays objectPoints,
00494                                      InputArrayOfArrays imagePoints,
00495                                      Size imageSize, double aspectRatio=1. );
00496 
00497 enum { CALIB_CB_ADAPTIVE_THRESH = 1, CALIB_CB_NORMALIZE_IMAGE = 2,
00498        CALIB_CB_FILTER_QUADS = 4, CALIB_CB_FAST_CHECK = 8 };
00499 
00501 CV_EXPORTS_W bool findChessboardCorners( InputArray image, Size patternSize,
00502                                          OutputArray corners,
00503                                          int flags=CALIB_CB_ADAPTIVE_THRESH+CALIB_CB_NORMALIZE_IMAGE );
00504 
00506 CV_EXPORTS bool find4QuadCornerSubpix(InputArray img, InputOutputArray corners, Size region_size);
00507 
00509 CV_EXPORTS_W void drawChessboardCorners( InputOutputArray image, Size patternSize,
00510                                          InputArray corners, bool patternWasFound );
00511 
00512 enum { CALIB_CB_SYMMETRIC_GRID = 1, CALIB_CB_ASYMMETRIC_GRID = 2,
00513        CALIB_CB_CLUSTERING = 4 };
00514 
00516 CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize,
00517                                  OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID,
00518                                  const Ptr<FeatureDetector> &blobDetector = new SimpleBlobDetector());
00519 
00521 CV_EXPORTS_W bool findCirclesGridDefault( InputArray image, Size patternSize,
00522                                           OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID );
00523 enum
00524 {
00525     CALIB_USE_INTRINSIC_GUESS = CV_CALIB_USE_INTRINSIC_GUESS,
00526     CALIB_FIX_ASPECT_RATIO = CV_CALIB_FIX_ASPECT_RATIO,
00527     CALIB_FIX_PRINCIPAL_POINT = CV_CALIB_FIX_PRINCIPAL_POINT,
00528     CALIB_ZERO_TANGENT_DIST = CV_CALIB_ZERO_TANGENT_DIST,
00529     CALIB_FIX_FOCAL_LENGTH = CV_CALIB_FIX_FOCAL_LENGTH,
00530     CALIB_FIX_K1 = CV_CALIB_FIX_K1,
00531     CALIB_FIX_K2 = CV_CALIB_FIX_K2,
00532     CALIB_FIX_K3 = CV_CALIB_FIX_K3,
00533     CALIB_FIX_K4 = CV_CALIB_FIX_K4,
00534     CALIB_FIX_K5 = CV_CALIB_FIX_K5,
00535     CALIB_FIX_K6 = CV_CALIB_FIX_K6,
00536     CALIB_RATIONAL_MODEL = CV_CALIB_RATIONAL_MODEL,
00537     // only for stereo
00538     CALIB_FIX_INTRINSIC = CV_CALIB_FIX_INTRINSIC,
00539     CALIB_SAME_FOCAL_LENGTH = CV_CALIB_SAME_FOCAL_LENGTH,
00540     // for stereo rectification
00541     CALIB_ZERO_DISPARITY = CV_CALIB_ZERO_DISPARITY
00542 };
00543 
00545 CV_EXPORTS_W double calibrateCamera( InputArrayOfArrays objectPoints,
00546                                      InputArrayOfArrays imagePoints,
00547                                      Size imageSize,
00548                                      CV_OUT InputOutputArray cameraMatrix,
00549                                      CV_OUT InputOutputArray distCoeffs,
00550                                      OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs,
00551                                      int flags=0, TermCriteria criteria = TermCriteria(
00552                                          TermCriteria::COUNT+TermCriteria::EPS, 30, DBL_EPSILON) );
00553 
00555 CV_EXPORTS_W void calibrationMatrixValues( InputArray cameraMatrix,
00556                                 Size imageSize,
00557                                 double apertureWidth,
00558                                 double apertureHeight,
00559                                 CV_OUT double& fovx,
00560                                 CV_OUT double& fovy,
00561                                 CV_OUT double& focalLength,
00562                                 CV_OUT Point2d& principalPoint,
00563                                 CV_OUT double& aspectRatio );
00564 
00566 CV_EXPORTS_W double stereoCalibrate( InputArrayOfArrays objectPoints,
00567                                      InputArrayOfArrays imagePoints1,
00568                                      InputArrayOfArrays imagePoints2,
00569                                      CV_OUT InputOutputArray cameraMatrix1,
00570                                      CV_OUT InputOutputArray distCoeffs1,
00571                                      CV_OUT InputOutputArray cameraMatrix2,
00572                                      CV_OUT InputOutputArray distCoeffs2,
00573                                      Size imageSize, OutputArray R,
00574                                      OutputArray T, OutputArray E, OutputArray F,
00575                                      TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6),
00576                                      int flags=CALIB_FIX_INTRINSIC );
00577 
00578 
00580 CV_EXPORTS_W void stereoRectify( InputArray cameraMatrix1, InputArray distCoeffs1,
00581                                InputArray cameraMatrix2, InputArray distCoeffs2,
00582                                Size imageSize, InputArray R, InputArray T,
00583                                OutputArray R1, OutputArray R2,
00584                                OutputArray P1, OutputArray P2,
00585                                OutputArray Q, int flags=CALIB_ZERO_DISPARITY,
00586                                double alpha=-1, Size newImageSize=Size(),
00587                                CV_OUT Rect* validPixROI1=0, CV_OUT Rect* validPixROI2=0 );
00588 
00590 CV_EXPORTS_W bool stereoRectifyUncalibrated( InputArray points1, InputArray points2,
00591                                              InputArray F, Size imgSize,
00592                                              OutputArray H1, OutputArray H2,
00593                                              double threshold=5 );
00594 
00596 CV_EXPORTS_W float rectify3Collinear( InputArray cameraMatrix1, InputArray distCoeffs1,
00597                                       InputArray cameraMatrix2, InputArray distCoeffs2,
00598                                       InputArray cameraMatrix3, InputArray distCoeffs3,
00599                                       InputArrayOfArrays imgpt1, InputArrayOfArrays imgpt3,
00600                                       Size imageSize, InputArray R12, InputArray T12,
00601                                       InputArray R13, InputArray T13,
00602                                       OutputArray R1, OutputArray R2, OutputArray R3,
00603                                       OutputArray P1, OutputArray P2, OutputArray P3,
00604                                       OutputArray Q, double alpha, Size newImgSize,
00605                                       CV_OUT Rect* roi1, CV_OUT Rect* roi2, int flags );
00606 
00608 CV_EXPORTS_W Mat getOptimalNewCameraMatrix( InputArray cameraMatrix, InputArray distCoeffs,
00609                                             Size imageSize, double alpha, Size newImgSize=Size(),
00610                                             CV_OUT Rect* validPixROI=0, bool centerPrincipalPoint=false);
00611 
00613 CV_EXPORTS_W void convertPointsToHomogeneous( InputArray src, OutputArray dst );
00614 
00616 CV_EXPORTS_W void convertPointsFromHomogeneous( InputArray src, OutputArray dst );
00617 
00619 CV_EXPORTS void convertPointsHomogeneous( InputArray src, OutputArray dst );
00620 
00622 enum
00623 {
00624     FM_7POINT = CV_FM_7POINT, 
00625     FM_8POINT = CV_FM_8POINT, 
00626     FM_LMEDS = CV_FM_LMEDS,  
00627     FM_RANSAC = CV_FM_RANSAC  
00628 };
00629 
00631 CV_EXPORTS_W Mat findFundamentalMat( InputArray points1, InputArray points2,
00632                                      int method=FM_RANSAC,
00633                                      double param1=3., double param2=0.99,
00634                                      OutputArray mask=noArray());
00635 
00637 CV_EXPORTS Mat findFundamentalMat( InputArray points1, InputArray points2,
00638                                    OutputArray mask, int method=FM_RANSAC,
00639                                    double param1=3., double param2=0.99);
00640 
00642 CV_EXPORTS void computeCorrespondEpilines( InputArray points,
00643                                            int whichImage, InputArray F,
00644                                            OutputArray lines );
00645 
00646 CV_EXPORTS_W void triangulatePoints( InputArray projMatr1, InputArray projMatr2,
00647                                      InputArray projPoints1, InputArray projPoints2,
00648                                      OutputArray points4D );
00649 
00650 CV_EXPORTS_W void correctMatches( InputArray F, InputArray points1, InputArray points2,
00651                                   OutputArray newPoints1, OutputArray newPoints2 );
00652 
00653 template<> CV_EXPORTS void Ptr<CvStereoBMState>::delete_obj();
00654 
00660 class CV_EXPORTS_W StereoBM
00661 {
00662 public:
00663     enum { PREFILTER_NORMALIZED_RESPONSE = 0, PREFILTER_XSOBEL = 1,
00664         BASIC_PRESET=0, FISH_EYE_PRESET=1, NARROW_PRESET=2 };
00665 
00667     CV_WRAP StereoBM();
00669     CV_WRAP StereoBM(int preset, int ndisparities=0, int SADWindowSize=21);
00671     void init(int preset, int ndisparities=0, int SADWindowSize=21);
00673     CV_WRAP_AS(compute) void operator()( InputArray left, InputArray right,
00674                                          OutputArray disparity, int disptype=CV_16S );
00675 
00677     Ptr<CvStereoBMState> state;
00678 };
00679 
00680 
00686 class CV_EXPORTS_W StereoSGBM
00687 {
00688 public:
00689     enum { DISP_SHIFT=4, DISP_SCALE = (1<<DISP_SHIFT) };
00690 
00692     CV_WRAP StereoSGBM();
00693 
00695     CV_WRAP StereoSGBM(int minDisparity, int numDisparities, int SADWindowSize,
00696                int P1=0, int P2=0, int disp12MaxDiff=0,
00697                int preFilterCap=0, int uniquenessRatio=0,
00698                int speckleWindowSize=0, int speckleRange=0,
00699                bool fullDP=false);
00701     virtual ~StereoSGBM();
00702 
00704     CV_WRAP_AS(compute) virtual void operator()(InputArray left, InputArray right,
00705                                                 OutputArray disp);
00706 
00707     CV_PROP_RW int minDisparity;
00708     CV_PROP_RW int numberOfDisparities;
00709     CV_PROP_RW int SADWindowSize;
00710     CV_PROP_RW int preFilterCap;
00711     CV_PROP_RW int uniquenessRatio;
00712     CV_PROP_RW int P1;
00713     CV_PROP_RW int P2;
00714     CV_PROP_RW int speckleWindowSize;
00715     CV_PROP_RW int speckleRange;
00716     CV_PROP_RW int disp12MaxDiff;
00717     CV_PROP_RW bool fullDP;
00718 
00719 protected:
00720     Mat buffer;
00721 };
00722 
00724 CV_EXPORTS_W void filterSpeckles( InputOutputArray img, double newVal, int maxSpeckleSize, double maxDiff,
00725                                   InputOutputArray buf=noArray() );
00726 
00728 CV_EXPORTS_W Rect getValidDisparityROI( Rect roi1, Rect roi2,
00729                                         int minDisparity, int numberOfDisparities,
00730                                         int SADWindowSize );
00731 
00733 CV_EXPORTS_W void validateDisparity( InputOutputArray disparity, InputArray cost,
00734                                      int minDisparity, int numberOfDisparities,
00735                                      int disp12MaxDisp=1 );
00736 
00738 CV_EXPORTS_W void reprojectImageTo3D( InputArray disparity,
00739                                       OutputArray _3dImage, InputArray Q,
00740                                       bool handleMissingValues=false,
00741                                       int ddepth=-1 );
00742 
00743 CV_EXPORTS_W  int estimateAffine3D(InputArray src, InputArray dst,
00744                                    OutputArray out, OutputArray inliers,
00745                                    double ransacThreshold=3, double confidence=0.99);
00746 
00747 }
00748 
00749 #endif
00750 
00751 #endif