calib3d.hpp 21.5 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//  By downloading, copying, installing or using the software you agree to this license.
//  If you do not agree to this license, do not download, install,
//  copy or use the software.
//
//
10
//                          License Agreement
11 12 13 14
//                For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
//   * Redistribution's of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//
//   * Redistribution's in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//
//   * The name of the copyright holders may not be used to endorse or promote products
//     derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Intel Corporation or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/

#ifndef __OPENCV_CALIB3D_HPP__
#define __OPENCV_CALIB3D_HPP__

47
#include "opencv2/core.hpp"
48
#include "opencv2/features2d.hpp"
49

50 51
namespace cv
{
52

53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
//! type of the robust estimation algorithm
enum { LMEDS  = 4, //!< least-median algorithm
       RANSAC = 8  //!< RANSAC algorithm
     };

enum { ITERATIVE = 0,
       EPNP      = 1, // F.Moreno-Noguer, V.Lepetit and P.Fua "EPnP: Efficient Perspective-n-Point Camera Pose Estimation"
       P3P       = 2  // X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang; "Complete Solution Classification for the Perspective-Three-Point Problem"
     };

enum { CALIB_CB_ADAPTIVE_THRESH = 1,
       CALIB_CB_NORMALIZE_IMAGE = 2,
       CALIB_CB_FILTER_QUADS    = 4,
       CALIB_CB_FAST_CHECK      = 8
     };

enum { CALIB_CB_SYMMETRIC_GRID  = 1,
       CALIB_CB_ASYMMETRIC_GRID = 2,
       CALIB_CB_CLUSTERING      = 4
     };

enum { CALIB_USE_INTRINSIC_GUESS = 0x00001,
       CALIB_FIX_ASPECT_RATIO    = 0x00002,
       CALIB_FIX_PRINCIPAL_POINT = 0x00004,
       CALIB_ZERO_TANGENT_DIST   = 0x00008,
       CALIB_FIX_FOCAL_LENGTH    = 0x00010,
       CALIB_FIX_K1              = 0x00020,
       CALIB_FIX_K2              = 0x00040,
       CALIB_FIX_K3              = 0x00080,
       CALIB_FIX_K4              = 0x00800,
       CALIB_FIX_K5              = 0x01000,
       CALIB_FIX_K6              = 0x02000,
       CALIB_RATIONAL_MODEL      = 0x04000,
       CALIB_THIN_PRISM_MODEL    = 0x08000,
       CALIB_FIX_S1_S2_S3_S4     = 0x10000,
       // only for stereo
       CALIB_FIX_INTRINSIC       = 0x00100,
       CALIB_SAME_FOCAL_LENGTH   = 0x00200,
       // for stereo rectification
       CALIB_ZERO_DISPARITY      = 0x00400
     };
94

95 96 97 98 99 100
//! the algorithm for finding fundamental matrix
enum { FM_7POINT = 1, //!< 7-point algorithm
       FM_8POINT = 2, //!< 8-point algorithm
       FM_LMEDS  = 4, //!< least-median algorithm
       FM_RANSAC = 8  //!< RANSAC algorithm
     };
A
Alexander Shishkov 已提交
101

102

103

104
//! converts rotation vector to rotation matrix or vice versa using Rodrigues transformation
105
CV_EXPORTS_W void Rodrigues( InputArray src, OutputArray dst, OutputArray jacobian = noArray() );
106

107
//! computes the best-fit perspective transformation mapping srcPoints to dstPoints.
108
CV_EXPORTS_W Mat findHomography( InputArray srcPoints, InputArray dstPoints,
109
                                 int method = 0, double ransacReprojThreshold = 3,
110
                                 OutputArray mask=noArray());
111 112

//! variant of findHomography for backward compatibility
113
CV_EXPORTS Mat findHomography( InputArray srcPoints, InputArray dstPoints,
114
                               OutputArray mask, int method = 0, double ransacReprojThreshold = 3 );
115

116
//! Computes RQ decomposition of 3x3 matrix
117
CV_EXPORTS_W Vec3d RQDecomp3x3( InputArray src, OutputArray mtxR, OutputArray mtxQ,
118 119 120
                                OutputArray Qx = noArray(),
                                OutputArray Qy = noArray(),
                                OutputArray Qz = noArray());
121

122
//! Decomposes the projection matrix into camera matrix and the rotation martix and the translation vector
123
CV_EXPORTS_W void decomposeProjectionMatrix( InputArray projMatrix, OutputArray cameraMatrix,
124
                                             OutputArray rotMatrix, OutputArray transVect,
125 126 127 128
                                             OutputArray rotMatrixX = noArray(),
                                             OutputArray rotMatrixY = noArray(),
                                             OutputArray rotMatrixZ = noArray(),
                                             OutputArray eulerAngles =noArray() );
129

130
//! computes derivatives of the matrix product w.r.t each of the multiplied matrix coefficients
131
CV_EXPORTS_W void matMulDeriv( InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB );
132

133
//! composes 2 [R|t] transformations together. Also computes the derivatives of the result w.r.t the arguments
134 135
CV_EXPORTS_W void composeRT( InputArray rvec1, InputArray tvec1,
                             InputArray rvec2, InputArray tvec2,
136
                             OutputArray rvec3, OutputArray tvec3,
137 138 139 140
                             OutputArray dr3dr1 = noArray(), OutputArray dr3dt1 = noArray(),
                             OutputArray dr3dr2 = noArray(), OutputArray dr3dt2 = noArray(),
                             OutputArray dt3dr1 = noArray(), OutputArray dt3dt1 = noArray(),
                             OutputArray dt3dr2 = noArray(), OutputArray dt3dt2 = noArray() );
141

142
//! projects points from the model coordinate space to the image coordinates. Also computes derivatives of the image coordinates w.r.t the intrinsic and extrinsic camera parameters
143 144 145
CV_EXPORTS_W void projectPoints( InputArray objectPoints,
                                 InputArray rvec, InputArray tvec,
                                 InputArray cameraMatrix, InputArray distCoeffs,
146
                                 OutputArray imagePoints,
147 148
                                 OutputArray jacobian = noArray(),
                                 double aspectRatio = 0 );
149

150
//! computes the camera pose from a few 3D points and the corresponding projections. The outliers are not handled.
A
Alexander Shishkov 已提交
151
CV_EXPORTS_W bool solvePnP( InputArray objectPoints, InputArray imagePoints,
152
                            InputArray cameraMatrix, InputArray distCoeffs,
153
                            OutputArray rvec, OutputArray tvec,
154
                            bool useExtrinsicGuess = false, int flags = ITERATIVE );
155

A
Alexander Shishkov 已提交
156
//! computes the camera pose from a few 3D points and the corresponding projections. The outliers are possible.
157 158 159 160 161 162
CV_EXPORTS_W void solvePnPRansac( InputArray objectPoints, InputArray imagePoints,
                                  InputArray cameraMatrix, InputArray distCoeffs,
                                  OutputArray rvec, OutputArray tvec,
                                  bool useExtrinsicGuess = false, int iterationsCount = 100,
                                  float reprojectionError = 8.0, int minInliersCount = 100,
                                  OutputArray inliers = noArray(), int flags = ITERATIVE );
A
Alexander Shishkov 已提交
163

164
//! initializes camera matrix from a few 3D points and the corresponding projections.
165 166
CV_EXPORTS_W Mat initCameraMatrix2D( InputArrayOfArrays objectPoints,
                                     InputArrayOfArrays imagePoints,
167
                                     Size imageSize, double aspectRatio = 1.0 );
168

169
//! finds checkerboard pattern of the specified size in the image
170 171
CV_EXPORTS_W bool findChessboardCorners( InputArray image, Size patternSize, OutputArray corners,
                                         int flags = CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE );
172

173
//! finds subpixel-accurate positions of the chessboard corners
174
CV_EXPORTS bool find4QuadCornerSubpix( InputArray img, InputOutputArray corners, Size region_size );
175

176
//! draws the checkerboard pattern (found or partly found) in the image
177
CV_EXPORTS_W void drawChessboardCorners( InputOutputArray image, Size patternSize,
178
                                         InputArray corners, bool patternWasFound );
179 180

//! finds circles' grid pattern of the specified size in the image
181
CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize,
182
                                   OutputArray centers, int flags = CALIB_CB_SYMMETRIC_GRID,
R
Roman Donchenko 已提交
183
                                   const Ptr<FeatureDetector> &blobDetector = makePtr<SimpleBlobDetector>());
184

185
//! finds intrinsic and extrinsic camera parameters from several fews of a known calibration pattern.
186
CV_EXPORTS_W double calibrateCamera( InputArrayOfArrays objectPoints,
187 188
                                     InputArrayOfArrays imagePoints, Size imageSize,
                                     InputOutputArray cameraMatrix, InputOutputArray distCoeffs,
189
                                     OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs,
190 191
                                     int flags = 0, TermCriteria criteria = TermCriteria(
                                        TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON) );
192

193
//! computes several useful camera characteristics from the camera matrix, camera frame resolution and the physical sensor size.
194 195 196 197 198
CV_EXPORTS_W void calibrationMatrixValues( InputArray cameraMatrix, Size imageSize,
                                           double apertureWidth, double apertureHeight,
                                           CV_OUT double& fovx, CV_OUT double& fovy,
                                           CV_OUT double& focalLength, CV_OUT Point2d& principalPoint,
                                           CV_OUT double& aspectRatio );
199 200

//! finds intrinsic and extrinsic parameters of a stereo camera
201
CV_EXPORTS_W double stereoCalibrate( InputArrayOfArrays objectPoints,
202 203 204 205
                                     InputArrayOfArrays imagePoints1, InputArrayOfArrays imagePoints2,
                                     InputOutputArray cameraMatrix1, InputOutputArray distCoeffs1,
                                     InputOutputArray cameraMatrix2, InputOutputArray distCoeffs2,
                                     Size imageSize, OutputArray R,OutputArray T, OutputArray E, OutputArray F,
206 207
                                     int flags = CALIB_FIX_INTRINSIC,
                                     TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6) );
208

209

210
//! computes the rectification transformation for a stereo camera from its intrinsic and extrinsic parameters
211
CV_EXPORTS_W void stereoRectify( InputArray cameraMatrix1, InputArray distCoeffs1,
212 213 214 215 216 217 218
                                 InputArray cameraMatrix2, InputArray distCoeffs2,
                                 Size imageSize, InputArray R, InputArray T,
                                 OutputArray R1, OutputArray R2,
                                 OutputArray P1, OutputArray P2,
                                 OutputArray Q, int flags = CALIB_ZERO_DISPARITY,
                                 double alpha = -1, Size newImageSize = Size(),
                                 CV_OUT Rect* validPixROI1 = 0, CV_OUT Rect* validPixROI2 = 0 );
219

220
//! computes the rectification transformation for an uncalibrated stereo camera (zero distortion is assumed)
221 222
CV_EXPORTS_W bool stereoRectifyUncalibrated( InputArray points1, InputArray points2,
                                             InputArray F, Size imgSize,
223
                                             OutputArray H1, OutputArray H2,
224
                                             double threshold = 5 );
225 226

//! computes the rectification transformations for 3-head camera, where all the heads are on the same line.
227 228 229 230 231 232
CV_EXPORTS_W float rectify3Collinear( InputArray cameraMatrix1, InputArray distCoeffs1,
                                      InputArray cameraMatrix2, InputArray distCoeffs2,
                                      InputArray cameraMatrix3, InputArray distCoeffs3,
                                      InputArrayOfArrays imgpt1, InputArrayOfArrays imgpt3,
                                      Size imageSize, InputArray R12, InputArray T12,
                                      InputArray R13, InputArray T13,
233 234 235
                                      OutputArray R1, OutputArray R2, OutputArray R3,
                                      OutputArray P1, OutputArray P2, OutputArray P3,
                                      OutputArray Q, double alpha, Size newImgSize,
236
                                      CV_OUT Rect* roi1, CV_OUT Rect* roi2, int flags );
237

238
//! returns the optimal new camera matrix
239
CV_EXPORTS_W Mat getOptimalNewCameraMatrix( InputArray cameraMatrix, InputArray distCoeffs,
240 241 242
                                            Size imageSize, double alpha, Size newImgSize = Size(),
                                            CV_OUT Rect* validPixROI = 0,
                                            bool centerPrincipalPoint = false);
V
Vadim Pisarevsky 已提交
243

244
//! converts point coordinates from normal pixel coordinates to homogeneous coordinates ((x,y)->(x,y,1))
245
CV_EXPORTS_W void convertPointsToHomogeneous( InputArray src, OutputArray dst );
246

247
//! converts point coordinates from homogeneous to normal pixel coordinates ((x,y,z)->(x/z, y/z))
248
CV_EXPORTS_W void convertPointsFromHomogeneous( InputArray src, OutputArray dst );
249

250
//! for backward compatibility
251
CV_EXPORTS void convertPointsHomogeneous( InputArray src, OutputArray dst );
252

253
//! finds fundamental matrix from a set of corresponding 2D points
254
CV_EXPORTS_W Mat findFundamentalMat( InputArray points1, InputArray points2,
255 256 257
                                     int method = FM_RANSAC,
                                     double param1 = 3., double param2 = 0.99,
                                     OutputArray mask = noArray() );
258

259
//! variant of findFundamentalMat for backward compatibility
260
CV_EXPORTS Mat findFundamentalMat( InputArray points1, InputArray points2,
261 262
                                   OutputArray mask, int method = FM_RANSAC,
                                   double param1 = 3., double param2 = 0.99 );
263

264
//! finds essential matrix from a set of corresponding 2D points using five-point algorithm
265
CV_EXPORTS_W Mat findEssentialMat( InputArray points1, InputArray points2,
266 267 268
                                 double focal = 1.0, Point2d pp = Point2d(0, 0),
                                 int method = RANSAC, double prob = 0.999,
                                 double threshold = 1.0, OutputArray mask = noArray() );
269 270

//! decompose essential matrix to possible rotation matrix and one translation vector
271
CV_EXPORTS_W void decomposeEssentialMat( InputArray E, OutputArray R1, OutputArray R2, OutputArray t );
272 273

//! recover relative camera pose from a set of corresponding 2D points
274
CV_EXPORTS_W int recoverPose( InputArray E, InputArray points1, InputArray points2,
275
                            OutputArray R, OutputArray t,
276
                            double focal = 1.0, Point2d pp = Point2d(0, 0),
277
                            InputOutputArray mask = noArray() );
278

279

280
//! finds coordinates of epipolar lines corresponding the specified points
281 282
CV_EXPORTS_W void computeCorrespondEpilines( InputArray points, int whichImage,
                                             InputArray F, OutputArray lines );
283

284 285 286 287
CV_EXPORTS_W void triangulatePoints( InputArray projMatr1, InputArray projMatr2,
                                     InputArray projPoints1, InputArray projPoints2,
                                     OutputArray points4D );

288 289 290
CV_EXPORTS_W void correctMatches( InputArray F, InputArray points1, InputArray points2,
                                  OutputArray newPoints1, OutputArray newPoints2 );

291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
//! filters off speckles (small regions of incorrectly computed disparity)
CV_EXPORTS_W void filterSpeckles( InputOutputArray img, double newVal,
                                  int maxSpeckleSize, double maxDiff,
                                  InputOutputArray buf = noArray() );

//! computes valid disparity ROI from the valid ROIs of the rectified images (that are returned by cv::stereoRectify())
CV_EXPORTS_W Rect getValidDisparityROI( Rect roi1, Rect roi2,
                                        int minDisparity, int numberOfDisparities,
                                        int SADWindowSize );

//! validates disparity using the left-right check. The matrix "cost" should be computed by the stereo correspondence algorithm
CV_EXPORTS_W void validateDisparity( InputOutputArray disparity, InputArray cost,
                                     int minDisparity, int numberOfDisparities,
                                     int disp12MaxDisp = 1 );

//! reprojects disparity image to 3D: (x,y,d)->(X,Y,Z) using the matrix Q returned by cv::stereoRectify
CV_EXPORTS_W void reprojectImageTo3D( InputArray disparity,
                                      OutputArray _3dImage, InputArray Q,
                                      bool handleMissingValues = false,
                                      int ddepth = -1 );

CV_EXPORTS_W  int estimateAffine3D(InputArray src, InputArray dst,
                                   OutputArray out, OutputArray inliers,
                                   double ransacThreshold = 3, double confidence = 0.99);

316

317 318 319 320 321
CV_EXPORTS_W int decomposeHomographyMat(InputArray _H,
                                        InputArray _K,
                                        OutputArrayOfArrays _rotations,
                                        OutputArrayOfArrays _translations,
                                        OutputArrayOfArrays _normals);
322

V
Vadim Pisarevsky 已提交
323 324 325
class CV_EXPORTS_W StereoMatcher : public Algorithm
{
public:
326 327 328
    enum { DISP_SHIFT = 4,
           DISP_SCALE = (1 << DISP_SHIFT)
         };
329

V
Vadim Pisarevsky 已提交
330 331
    CV_WRAP virtual void compute( InputArray left, InputArray right,
                                  OutputArray disparity ) = 0;
332

333 334
    CV_WRAP virtual int getMinDisparity() const = 0;
    CV_WRAP virtual void setMinDisparity(int minDisparity) = 0;
V
Vadim Pisarevsky 已提交
335

336 337
    CV_WRAP virtual int getNumDisparities() const = 0;
    CV_WRAP virtual void setNumDisparities(int numDisparities) = 0;
338

339 340
    CV_WRAP virtual int getBlockSize() const = 0;
    CV_WRAP virtual void setBlockSize(int blockSize) = 0;
V
Vadim Pisarevsky 已提交
341

342 343 344 345 346 347 348 349 350
    CV_WRAP virtual int getSpeckleWindowSize() const = 0;
    CV_WRAP virtual void setSpeckleWindowSize(int speckleWindowSize) = 0;

    CV_WRAP virtual int getSpeckleRange() const = 0;
    CV_WRAP virtual void setSpeckleRange(int speckleRange) = 0;

    CV_WRAP virtual int getDisp12MaxDiff() const = 0;
    CV_WRAP virtual void setDisp12MaxDiff(int disp12MaxDiff) = 0;
};
V
Vadim Pisarevsky 已提交
351

352

353

354
class CV_EXPORTS_W StereoBM : public StereoMatcher
355 356
{
public:
357 358 359
    enum { PREFILTER_NORMALIZED_RESPONSE = 0,
           PREFILTER_XSOBEL              = 1
         };
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383

    CV_WRAP virtual int getPreFilterType() const = 0;
    CV_WRAP virtual void setPreFilterType(int preFilterType) = 0;

    CV_WRAP virtual int getPreFilterSize() const = 0;
    CV_WRAP virtual void setPreFilterSize(int preFilterSize) = 0;

    CV_WRAP virtual int getPreFilterCap() const = 0;
    CV_WRAP virtual void setPreFilterCap(int preFilterCap) = 0;

    CV_WRAP virtual int getTextureThreshold() const = 0;
    CV_WRAP virtual void setTextureThreshold(int textureThreshold) = 0;

    CV_WRAP virtual int getUniquenessRatio() const = 0;
    CV_WRAP virtual void setUniquenessRatio(int uniquenessRatio) = 0;

    CV_WRAP virtual int getSmallerBlockSize() const = 0;
    CV_WRAP virtual void setSmallerBlockSize(int blockSize) = 0;

    CV_WRAP virtual Rect getROI1() const = 0;
    CV_WRAP virtual void setROI1(Rect roi1) = 0;

    CV_WRAP virtual Rect getROI2() const = 0;
    CV_WRAP virtual void setROI2(Rect roi2) = 0;
384 385
};

386
CV_EXPORTS_W Ptr<StereoBM> createStereoBM(int numDisparities = 0, int blockSize = 21);
387

388 389

class CV_EXPORTS_W StereoSGBM : public StereoMatcher
390 391
{
public:
392 393 394
    enum { MODE_SGBM = 0,
           MODE_HH   = 1
         };
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409

    CV_WRAP virtual int getPreFilterCap() const = 0;
    CV_WRAP virtual void setPreFilterCap(int preFilterCap) = 0;

    CV_WRAP virtual int getUniquenessRatio() const = 0;
    CV_WRAP virtual void setUniquenessRatio(int uniquenessRatio) = 0;

    CV_WRAP virtual int getP1() const = 0;
    CV_WRAP virtual void setP1(int P1) = 0;

    CV_WRAP virtual int getP2() const = 0;
    CV_WRAP virtual void setP2(int P2) = 0;

    CV_WRAP virtual int getMode() const = 0;
    CV_WRAP virtual void setMode(int mode) = 0;
410 411
};

412

413
CV_EXPORTS_W Ptr<StereoSGBM> createStereoSGBM(int minDisparity, int numDisparities, int blockSize,
414 415 416 417
                                            int P1 = 0, int P2 = 0, int disp12MaxDiff = 0,
                                            int preFilterCap = 0, int uniquenessRatio = 0,
                                            int speckleWindowSize = 0, int speckleRange = 0,
                                            int mode = StereoSGBM::MODE_SGBM);
418

419
} // cv
420 421

#endif