opencv  2.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
calib3d.hpp
Go to the documentation of this file.
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
8 //
9 //
10 // License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
22 //
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
26 //
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42 
43 #ifndef __OPENCV_CALIB3D_HPP__
44 #define __OPENCV_CALIB3D_HPP__
45 
46 #include "opencv2/core/core.hpp"
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 /****************************************************************************************\
53 * Camera Calibration, Pose Estimation and Stereo *
54 \****************************************************************************************/
55 
57 
58 /* Allocates and initializes CvPOSITObject structure before doing cvPOSIT */
59 CVAPI(CvPOSITObject*) cvCreatePOSITObject( CvPoint3D32f* points, int point_count );
60 
61 
62 /* Runs POSIT (POSe from ITeration) algorithm for determining 3d position of
63  an object given its model and projection in a weak-perspective case */
64 CVAPI(void) cvPOSIT( CvPOSITObject* posit_object, CvPoint2D32f* image_points,
65  double focal_length, CvTermCriteria criteria,
66  float* rotation_matrix, float* translation_vector);
67 
68 /* Releases CvPOSITObject structure */
69 CVAPI(void) cvReleasePOSITObject( CvPOSITObject** posit_object );
70 
71 /* updates the number of RANSAC iterations */
72 CVAPI(int) cvRANSACUpdateNumIters( double p, double err_prob,
73  int model_points, int max_iters );
74 
75 CVAPI(void) cvConvertPointsHomogeneous( const CvMat* src, CvMat* dst );
76 
77 /* Calculates fundamental matrix given a set of corresponding points */
78 #define CV_FM_7POINT 1
79 #define CV_FM_8POINT 2
80 
81 #define CV_LMEDS 4
82 #define CV_RANSAC 8
83 
84 #define CV_FM_LMEDS_ONLY CV_LMEDS
85 #define CV_FM_RANSAC_ONLY CV_RANSAC
86 #define CV_FM_LMEDS CV_LMEDS
87 #define CV_FM_RANSAC CV_RANSAC
88 
89 CVAPI(int) cvFindFundamentalMat( const CvMat* points1, const CvMat* points2,
90  CvMat* fundamental_matrix,
92  double param1 CV_DEFAULT(3.), double param2 CV_DEFAULT(0.99),
93  CvMat* status CV_DEFAULT(NULL) );
94 
95 /* For each input point on one of images
96  computes parameters of the corresponding
97  epipolar line on the other image */
98 CVAPI(void) cvComputeCorrespondEpilines( const CvMat* points,
99  int which_image,
100  const CvMat* fundamental_matrix,
101  CvMat* correspondent_lines );
102 
103 /* Triangulation functions */
104 
105 CVAPI(void) cvTriangulatePoints(CvMat* projMatr1, CvMat* projMatr2,
106  CvMat* projPoints1, CvMat* projPoints2,
107  CvMat* points4D);
108 
109 CVAPI(void) cvCorrectMatches(CvMat* F, CvMat* points1, CvMat* points2,
110  CvMat* new_points1, CvMat* new_points2);
111 
112 
113 /* Computes the optimal new camera matrix according to the free scaling parameter alpha:
114  alpha=0 - only valid pixels will be retained in the undistorted image
115  alpha=1 - all the source image pixels will be retained in the undistorted image
116 */
117 CVAPI(void) cvGetOptimalNewCameraMatrix( const CvMat* camera_matrix,
118  const CvMat* dist_coeffs,
119  CvSize image_size, double alpha,
120  CvMat* new_camera_matrix,
121  CvSize new_imag_size CV_DEFAULT(cvSize(0,0)),
122  CvRect* valid_pixel_ROI CV_DEFAULT(0) );
123 
124 /* Converts rotation vector to rotation matrix or vice versa */
125 CVAPI(int) cvRodrigues2( const CvMat* src, CvMat* dst,
126  CvMat* jacobian CV_DEFAULT(0) );
127 
128 /* Finds perspective transformation between the object plane and image (view) plane */
129 CVAPI(int) cvFindHomography( const CvMat* src_points,
130  const CvMat* dst_points,
131  CvMat* homography,
132  int method CV_DEFAULT(0),
133  double ransacReprojThreshold CV_DEFAULT(3),
134  CvMat* mask CV_DEFAULT(0));
135 
136 /* Computes RQ decomposition for 3x3 matrices */
137 CVAPI(void) cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ,
138  CvMat *matrixQx CV_DEFAULT(NULL),
139  CvMat *matrixQy CV_DEFAULT(NULL),
140  CvMat *matrixQz CV_DEFAULT(NULL),
141  CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
142 
143 /* Computes projection matrix decomposition */
144 CVAPI(void) cvDecomposeProjectionMatrix( const CvMat *projMatr, CvMat *calibMatr,
145  CvMat *rotMatr, CvMat *posVect,
146  CvMat *rotMatrX CV_DEFAULT(NULL),
147  CvMat *rotMatrY CV_DEFAULT(NULL),
148  CvMat *rotMatrZ CV_DEFAULT(NULL),
149  CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
150 
151 /* Computes d(AB)/dA and d(AB)/dB */
152 CVAPI(void) cvCalcMatMulDeriv( const CvMat* A, const CvMat* B, CvMat* dABdA, CvMat* dABdB );
153 
154 /* Computes r3 = rodrigues(rodrigues(r2)*rodrigues(r1)),
155  t3 = rodrigues(r2)*t1 + t2 and the respective derivatives */
156 CVAPI(void) cvComposeRT( const CvMat* _rvec1, const CvMat* _tvec1,
157  const CvMat* _rvec2, const CvMat* _tvec2,
158  CvMat* _rvec3, CvMat* _tvec3,
159  CvMat* dr3dr1 CV_DEFAULT(0), CvMat* dr3dt1 CV_DEFAULT(0),
160  CvMat* dr3dr2 CV_DEFAULT(0), CvMat* dr3dt2 CV_DEFAULT(0),
161  CvMat* dt3dr1 CV_DEFAULT(0), CvMat* dt3dt1 CV_DEFAULT(0),
162  CvMat* dt3dr2 CV_DEFAULT(0), CvMat* dt3dt2 CV_DEFAULT(0) );
163 
164 /* Projects object points to the view plane using
165  the specified extrinsic and intrinsic camera parameters */
166 CVAPI(void) cvProjectPoints2( const CvMat* object_points, const CvMat* rotation_vector,
167  const CvMat* translation_vector, const CvMat* camera_matrix,
168  const CvMat* distortion_coeffs, CvMat* image_points,
169  CvMat* dpdrot CV_DEFAULT(NULL), CvMat* dpdt CV_DEFAULT(NULL),
170  CvMat* dpdf CV_DEFAULT(NULL), CvMat* dpdc CV_DEFAULT(NULL),
171  CvMat* dpddist CV_DEFAULT(NULL),
172  double aspect_ratio CV_DEFAULT(0));
173 
174 /* Finds extrinsic camera parameters from
175  a few known corresponding point pairs and intrinsic parameters */
176 CVAPI(void) cvFindExtrinsicCameraParams2( const CvMat* object_points,
177  const CvMat* image_points,
178  const CvMat* camera_matrix,
179  const CvMat* distortion_coeffs,
180  CvMat* rotation_vector,
181  CvMat* translation_vector,
182  int use_extrinsic_guess CV_DEFAULT(0) );
183 
184 /* Computes initial estimate of the intrinsic camera parameters
185  in case of planar calibration target (e.g. chessboard) */
186 CVAPI(void) cvInitIntrinsicParams2D( const CvMat* object_points,
187  const CvMat* image_points,
188  const CvMat* npoints, CvSize image_size,
189  CvMat* camera_matrix,
190  double aspect_ratio CV_DEFAULT(1.) );
191 
192 #define CV_CALIB_CB_ADAPTIVE_THRESH 1
193 #define CV_CALIB_CB_NORMALIZE_IMAGE 2
194 #define CV_CALIB_CB_FILTER_QUADS 4
195 #define CV_CALIB_CB_FAST_CHECK 8
196 
197 // Performs a fast check if a chessboard is in the input image. This is a workaround to
198 // a problem of cvFindChessboardCorners being slow on images with no chessboard
199 // - src: input image
200 // - size: chessboard size
201 // Returns 1 if a chessboard can be in this image and findChessboardCorners should be called,
202 // 0 if there is no chessboard, -1 in case of error
203 CVAPI(int) cvCheckChessboard(IplImage* src, CvSize size);
204 
205  /* Detects corners on a chessboard calibration pattern */
206 CVAPI(int) cvFindChessboardCorners( const void* image, CvSize pattern_size,
207  CvPoint2D32f* corners,
208  int* corner_count CV_DEFAULT(NULL),
209  int flags CV_DEFAULT(CV_CALIB_CB_ADAPTIVE_THRESH+
211 
212 /* Draws individual chessboard corners or the whole chessboard detected */
213 CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size,
214  CvPoint2D32f* corners,
215  int count, int pattern_was_found );
216 
217 #define CV_CALIB_USE_INTRINSIC_GUESS 1
218 #define CV_CALIB_FIX_ASPECT_RATIO 2
219 #define CV_CALIB_FIX_PRINCIPAL_POINT 4
220 #define CV_CALIB_ZERO_TANGENT_DIST 8
221 #define CV_CALIB_FIX_FOCAL_LENGTH 16
222 #define CV_CALIB_FIX_K1 32
223 #define CV_CALIB_FIX_K2 64
224 #define CV_CALIB_FIX_K3 128
225 #define CV_CALIB_FIX_K4 2048
226 #define CV_CALIB_FIX_K5 4096
227 #define CV_CALIB_FIX_K6 8192
228 #define CV_CALIB_RATIONAL_MODEL 16384
229 
230 /* Finds intrinsic and extrinsic camera parameters
231  from a few views of known calibration pattern */
232 CVAPI(double) cvCalibrateCamera2( const CvMat* object_points,
233  const CvMat* image_points,
234  const CvMat* point_counts,
235  CvSize image_size,
236  CvMat* camera_matrix,
237  CvMat* distortion_coeffs,
238  CvMat* rotation_vectors CV_DEFAULT(NULL),
239  CvMat* translation_vectors CV_DEFAULT(NULL),
240  int flags CV_DEFAULT(0) );
241 
242 /* Computes various useful characteristics of the camera from the data computed by
243  cvCalibrateCamera2 */
244 CVAPI(void) cvCalibrationMatrixValues( const CvMat *camera_matrix,
245  CvSize image_size,
246  double aperture_width CV_DEFAULT(0),
247  double aperture_height CV_DEFAULT(0),
248  double *fovx CV_DEFAULT(NULL),
249  double *fovy CV_DEFAULT(NULL),
250  double *focal_length CV_DEFAULT(NULL),
251  CvPoint2D64f *principal_point CV_DEFAULT(NULL),
252  double *pixel_aspect_ratio CV_DEFAULT(NULL));
253 
254 #define CV_CALIB_FIX_INTRINSIC 256
255 #define CV_CALIB_SAME_FOCAL_LENGTH 512
256 
257 /* Computes the transformation from one camera coordinate system to another one
258  from a few correspondent views of the same calibration target. Optionally, calibrates
259  both cameras */
260 CVAPI(double) cvStereoCalibrate( const CvMat* object_points, const CvMat* image_points1,
261  const CvMat* image_points2, const CvMat* npoints,
262  CvMat* camera_matrix1, CvMat* dist_coeffs1,
263  CvMat* camera_matrix2, CvMat* dist_coeffs2,
264  CvSize image_size, CvMat* R, CvMat* T,
265  CvMat* E CV_DEFAULT(0), CvMat* F CV_DEFAULT(0),
266  CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria(
268  int flags CV_DEFAULT(CV_CALIB_FIX_INTRINSIC));
269 
270 #define CV_CALIB_ZERO_DISPARITY 1024
271 
272 /* Computes 3D rotations (+ optional shift) for each camera coordinate system to make both
273  views parallel (=> to make all the epipolar lines horizontal or vertical) */
274 CVAPI(void) cvStereoRectify( const CvMat* camera_matrix1, const CvMat* camera_matrix2,
275  const CvMat* dist_coeffs1, const CvMat* dist_coeffs2,
276  CvSize image_size, const CvMat* R, const CvMat* T,
277  CvMat* R1, CvMat* R2, CvMat* P1, CvMat* P2,
278  CvMat* Q CV_DEFAULT(0),
279  int flags CV_DEFAULT(CV_CALIB_ZERO_DISPARITY),
280  double alpha CV_DEFAULT(-1),
281  CvSize new_image_size CV_DEFAULT(cvSize(0,0)),
282  CvRect* valid_pix_ROI1 CV_DEFAULT(0),
283  CvRect* valid_pix_ROI2 CV_DEFAULT(0));
284 
285 /* Computes rectification transformations for uncalibrated pair of images using a set
286  of point correspondences */
287 CVAPI(int) cvStereoRectifyUncalibrated( const CvMat* points1, const CvMat* points2,
288  const CvMat* F, CvSize img_size,
289  CvMat* H1, CvMat* H2,
290  double threshold CV_DEFAULT(5));
291 
292 
293 
294 /* stereo correspondence parameters and functions */
295 
296 #define CV_STEREO_BM_NORMALIZED_RESPONSE 0
297 #define CV_STEREO_BM_XSOBEL 1
298 
299 /* Block matching algorithm structure */
300 typedef struct CvStereoBMState
301 {
302  // pre-filtering (normalization of input images)
303  int preFilterType; // =CV_STEREO_BM_NORMALIZED_RESPONSE now
304  int preFilterSize; // averaging window size: ~5x5..21x21
305  int preFilterCap; // the output of pre-filtering is clipped by [-preFilterCap,preFilterCap]
306 
307  // correspondence using Sum of Absolute Difference (SAD)
308  int SADWindowSize; // ~5x5..21x21
309  int minDisparity; // minimum disparity (can be negative)
310  int numberOfDisparities; // maximum disparity - minimum disparity (> 0)
311 
312  // post-filtering
313  int textureThreshold; // the disparity is only computed for pixels
314  // with textured enough neighborhood
315  int uniquenessRatio; // accept the computed disparity d* only if
316  // SAD(d) >= SAD(d*)*(1 + uniquenessRatio/100.)
317  // for any d != d*+/-1 within the search range.
318  int speckleWindowSize; // disparity variation window
319  int speckleRange; // acceptable range of variation in window
320 
321  int trySmallerWindows; // if 1, the results may be more accurate,
322  // at the expense of slower processing
325 
326  // temporary buffers
333 
334 #define CV_STEREO_BM_BASIC 0
335 #define CV_STEREO_BM_FISH_EYE 1
336 #define CV_STEREO_BM_NARROW 2
337 
338 CVAPI(CvStereoBMState*) cvCreateStereoBMState(int preset CV_DEFAULT(CV_STEREO_BM_BASIC),
339  int numberOfDisparities CV_DEFAULT(0));
340 
341 CVAPI(void) cvReleaseStereoBMState( CvStereoBMState** state );
342 
343 CVAPI(void) cvFindStereoCorrespondenceBM( const CvArr* left, const CvArr* right,
344  CvArr* disparity, CvStereoBMState* state );
345 
346 CVAPI(CvRect) cvGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity,
347  int numberOfDisparities, int SADWindowSize );
348 
349 CVAPI(void) cvValidateDisparity( CvArr* disparity, const CvArr* cost,
350  int minDisparity, int numberOfDisparities,
351  int disp12MaxDiff CV_DEFAULT(1) );
352 
353 /* Kolmogorov-Zabin stereo-correspondence algorithm (a.k.a. KZ1) */
354 #define CV_STEREO_GC_OCCLUDED SHRT_MAX
355 
356 typedef struct CvStereoGCState
357 {
364  int maxIters;
365 
375 
376 CVAPI(CvStereoGCState*) cvCreateStereoGCState( int numberOfDisparities, int maxIters );
377 CVAPI(void) cvReleaseStereoGCState( CvStereoGCState** state );
378 
379 CVAPI(void) cvFindStereoCorrespondenceGC( const CvArr* left, const CvArr* right,
380  CvArr* disparityLeft, CvArr* disparityRight,
381  CvStereoGCState* state,
382  int useDisparityGuess CV_DEFAULT(0) );
383 
384 /* Reprojects the computed disparity image to the 3D space using the specified 4x4 matrix */
385 CVAPI(void) cvReprojectImageTo3D( const CvArr* disparityImage,
386  CvArr* _3dImage, const CvMat* Q,
387  int handleMissingValues CV_DEFAULT(0) );
388 
389 
390 #ifdef __cplusplus
391 }
392 
394 
396 {
397 public:
398  CvLevMarq();
399  CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria=
400  cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
401  bool completeSymmFlag=false );
402  ~CvLevMarq();
403  void init( int nparams, int nerrs, CvTermCriteria criteria=
404  cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
405  bool completeSymmFlag=false );
406  bool update( const CvMat*& param, CvMat*& J, CvMat*& err );
407  bool updateAlt( const CvMat*& param, CvMat*& JtJ, CvMat*& JtErr, double*& errNorm );
408 
409  void clear();
410  void step();
411  enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 };
412 
423  double prevErrNorm, errNorm;
426  int state;
427  int iters;
429 };
430 
431 namespace cv
432 {
433 
435 CV_EXPORTS_W void Rodrigues(const Mat& src, CV_OUT Mat& dst);
436 
438 CV_EXPORTS_AS(RodriguesJ) void Rodrigues(const Mat& src, CV_OUT Mat& dst, CV_OUT Mat& jacobian);
439 
441 enum
442 {
445 };
446 
448 CV_EXPORTS_AS(findHomographyAndOutliers) Mat findHomography( const Mat& srcPoints,
449  const Mat& dstPoints,
450  vector<uchar>& mask, int method=0,
452 
454 CV_EXPORTS_W Mat findHomography( const Mat& srcPoints,
455  const Mat& dstPoints,
456  int method=0, double ransacReprojThreshold=3 );
457 
459 CV_EXPORTS int estimateAffine3D(const Mat& from, const Mat& to, CV_OUT Mat& dst,
460  CV_OUT vector<uchar>& outliers,
461  double param1 = 3.0, double param2 = 0.99);
462 
464 CV_EXPORTS void RQDecomp3x3( const Mat& M, Mat& R, Mat& Q );
465 
467 CV_EXPORTS_W Vec3d RQDecomp3x3( const Mat& M, Mat& R, Mat& Q,
468  CV_OUT Mat& Qx, CV_OUT Mat& Qy, CV_OUT Mat& Qz );
469 
471 CV_EXPORTS void decomposeProjectionMatrix( const Mat& projMatrix, Mat& cameraMatrix,
472  Mat& rotMatrix, Mat& transVect );
473 
475 CV_EXPORTS_W void decomposeProjectionMatrix( const Mat& projMatrix, CV_OUT Mat& cameraMatrix,
476  CV_OUT Mat& rotMatrix, CV_OUT Mat& transVect,
477  CV_OUT Mat& rotMatrixX, CV_OUT Mat& rotMatrixY,
478  CV_OUT Mat& rotMatrixZ, CV_OUT Vec3d& eulerAngles );
479 
481 CV_EXPORTS_W void matMulDeriv( const Mat& A, const Mat& B, CV_OUT Mat& dABdA, CV_OUT Mat& dABdB );
482 
484 CV_EXPORTS_W void composeRT( const Mat& rvec1, const Mat& tvec1,
485  const Mat& rvec2, const Mat& tvec2,
487 
489 CV_EXPORTS_AS(composeRT_J) void composeRT( const Mat& rvec1, const Mat& tvec1,
490  const Mat& rvec2, const Mat& tvec2,
491  CV_OUT Mat& rvec3, CV_OUT Mat& tvec3,
496 
498 CV_EXPORTS_W void projectPoints( const Mat& objectPoints,
499  const Mat& rvec, const Mat& tvec,
500  const Mat& cameraMatrix,
501  const Mat& distCoeffs,
502  CV_OUT vector<Point2f>& imagePoints );
503 
505 CV_EXPORTS_AS(projectPointsJ) void projectPoints( const Mat& objectPoints,
506  const Mat& rvec, const Mat& tvec,
507  const Mat& cameraMatrix,
508  const Mat& distCoeffs,
509  CV_OUT vector<Point2f>& imagePoints,
512  double aspectRatio=0 );
513 
515 CV_EXPORTS_W void solvePnP( const Mat& objectPoints,
516  const Mat& imagePoints,
517  const Mat& cameraMatrix,
518  const Mat& distCoeffs,
519  CV_OUT Mat& rvec, CV_OUT Mat& tvec,
520  bool useExtrinsicGuess=false );
521 
523 CV_EXPORTS_W Mat initCameraMatrix2D( const vector<vector<Point3f> >& objectPoints,
524  const vector<vector<Point2f> >& imagePoints,
525  Size imageSize, double aspectRatio=1. );
526 
527 
530 
532 CV_EXPORTS_W bool findChessboardCorners( const Mat& image, Size patternSize,
533  CV_OUT vector<Point2f>& corners,
536 
538 CV_EXPORTS_W void drawChessboardCorners( Mat& image, Size patternSize,
539  const Mat& corners,
540  bool patternWasFound );
541 
542 CV_EXPORTS void drawChessboardCorners( Mat& image, Size patternSize,
543  const vector<Point2f>& corners,
544  bool patternWasFound );
545 
546 enum
547 {
560  // only for stereo
563  // for stereo rectification
564  CALIB_ZERO_DISPARITY = CV_CALIB_ZERO_DISPARITY
565 };
566 
568 CV_EXPORTS_W double calibrateCamera( const vector<vector<Point3f> >& objectPoints,
569  const vector<vector<Point2f> >& imagePoints,
570  Size imageSize,
571  CV_IN_OUT Mat& cameraMatrix,
572  CV_IN_OUT Mat& distCoeffs,
573  CV_OUT vector<Mat>& rvecs, CV_OUT vector<Mat>& tvecs,
574  int flags=0 );
575 
578  Size imageSize,
579  double apertureWidth,
580  double apertureHeight,
581  CV_OUT double& fovx,
582  CV_OUT double& fovy,
583  CV_OUT double& focalLength,
584  CV_OUT Point2d& principalPoint,
585  CV_OUT double& aspectRatio );
586 
588 CV_EXPORTS_W double stereoCalibrate( const vector<vector<Point3f> >& objectPoints,
589  const vector<vector<Point2f> >& imagePoints1,
590  const vector<vector<Point2f> >& imagePoints2,
591  CV_IN_OUT Mat& cameraMatrix1, CV_IN_OUT Mat& distCoeffs1,
592  CV_IN_OUT Mat& cameraMatrix2, CV_IN_OUT Mat& distCoeffs2,
593  Size imageSize, CV_OUT Mat& R, CV_OUT Mat& T,
594  CV_OUT Mat& E, CV_OUT Mat& F,
595  TermCriteria criteria = TermCriteria(TermCriteria::COUNT+
596  TermCriteria::EPS, 30, 1e-6),
598 
599 
601 CV_EXPORTS void stereoRectify( const Mat& cameraMatrix1, const Mat& distCoeffs1,
602  const Mat& cameraMatrix2, const Mat& distCoeffs2,
603  Size imageSize, const Mat& R, const Mat& T,
604  CV_OUT Mat& R1, CV_OUT Mat& R2,
605  CV_OUT Mat& P1, CV_OUT Mat& P2, CV_OUT Mat& Q,
607 
609 CV_EXPORTS_W void stereoRectify( const Mat& cameraMatrix1, const Mat& distCoeffs1,
610  const Mat& cameraMatrix2, const Mat& distCoeffs2,
611  Size imageSize, const Mat& R, const Mat& T,
612  CV_OUT Mat& R1, CV_OUT Mat& R2,
613  CV_OUT Mat& P1, CV_OUT Mat& P2, CV_OUT Mat& Q,
614  double alpha, Size newImageSize=Size(),
615  CV_OUT Rect* validPixROI1=0, CV_OUT Rect* validPixROI2=0,
617 
619 CV_EXPORTS_W bool stereoRectifyUncalibrated( const Mat& points1, const Mat& points2,
620  const Mat& F, Size imgSize,
621  CV_OUT Mat& H1, CV_OUT Mat& H2,
622  double threshold=5 );
623 
625 CV_EXPORTS_W float rectify3Collinear( const Mat& cameraMatrix1, const Mat& distCoeffs1,
626  const Mat& cameraMatrix2, const Mat& distCoeffs2,
627  const Mat& cameraMatrix3, const Mat& distCoeffs3,
628  const vector<vector<Point2f> >& imgpt1,
629  const vector<vector<Point2f> >& imgpt3,
630  Size imageSize, const Mat& R12, const Mat& T12,
631  const Mat& R13, const Mat& T13,
632  CV_OUT Mat& R1, CV_OUT Mat& R2, CV_OUT Mat& R3,
633  CV_OUT Mat& P1, CV_OUT Mat& P2, CV_OUT Mat& P3, CV_OUT Mat& Q,
634  double alpha, Size newImgSize,
635  CV_OUT Rect* roi1, CV_OUT Rect* roi2, int flags );
636 
639  Size imageSize, double alpha, Size newImgSize=Size(),
640  CV_OUT Rect* validPixROI=0);
641 
643 CV_EXPORTS void convertPointsHomogeneous( const Mat& src, CV_OUT vector<Point3f>& dst );
645 CV_EXPORTS void convertPointsHomogeneous( const Mat& src, CV_OUT vector<Point2f>& dst );
646 
648 enum
649 {
653  FM_RANSAC = CV_FM_RANSAC
654 };
655 
657 CV_EXPORTS Mat findFundamentalMat( const Mat& points1, const Mat& points2,
658  CV_OUT vector<uchar>& mask, int method=FM_RANSAC,
659  double param1=3., double param2=0.99 );
660 
662 CV_EXPORTS_W Mat findFundamentalMat( const Mat& points1, const Mat& points2,
663  int method=FM_RANSAC,
664  double param1=3., double param2=0.99 );
665 
667 CV_EXPORTS void computeCorrespondEpilines( const Mat& points1,
668  int whichImage, const Mat& F,
669  CV_OUT vector<Vec3f>& lines );
670 
672 
679 {
680 public:
681  enum { PREFILTER_NORMALIZED_RESPONSE = 0, PREFILTER_XSOBEL = 1,
682  BASIC_PRESET=0, FISH_EYE_PRESET=1, NARROW_PRESET=2 };
683 
685  CV_WRAP StereoBM();
687  CV_WRAP StereoBM(int preset, int ndisparities=0, int SADWindowSize=21);
689  void init(int preset, int ndisparities=0, int SADWindowSize=21);
691  CV_WRAP_AS(compute) void operator()( const Mat& left, const Mat& right, Mat& disparity, int disptype=CV_16S );
692 
695 };
696 
697 
704 {
705 public:
706  enum { DISP_SHIFT=4, DISP_SCALE = (1<<DISP_SHIFT) };
707 
709  CV_WRAP StereoSGBM();
710 
712  CV_WRAP StereoSGBM(int minDisparity, int numDisparities, int SADWindowSize,
713  int P1=0, int P2=0, int disp12MaxDiff=0,
714  int preFilterCap=0, int uniquenessRatio=0,
715  int speckleWindowSize=0, int speckleRange=0,
716  bool fullDP=false);
718  virtual ~StereoSGBM();
719 
721  CV_WRAP_AS(compute) virtual void operator()(const Mat& left, const Mat& right, Mat& disp);
722 
723  CV_PROP_RW int minDisparity;
724  CV_PROP_RW int numberOfDisparities;
725  CV_PROP_RW int SADWindowSize;
726  CV_PROP_RW int preFilterCap;
727  CV_PROP_RW int uniquenessRatio;
728  CV_PROP_RW int P1;
729  CV_PROP_RW int P2;
730  CV_PROP_RW int speckleWindowSize;
731  CV_PROP_RW int speckleRange;
732  CV_PROP_RW int disp12MaxDiff;
733  CV_PROP_RW bool fullDP;
734 
735 protected:
736  Mat buffer;
737 };
738 
740 CV_EXPORTS_W void filterSpeckles( Mat& img, double newVal, int maxSpeckleSize, double maxDiff, Mat& buf );
741 
744  int minDisparity, int numberOfDisparities,
745  int SADWindowSize );
746 
748 CV_EXPORTS_W void validateDisparity( Mat& disparity, const Mat& cost,
749  int minDisparity, int numberOfDisparities,
750  int disp12MaxDisp=1 );
751 
753 CV_EXPORTS_W void reprojectImageTo3D( const Mat& disparity,
754  CV_OUT Mat& _3dImage, const Mat& Q,
755  bool handleMissingValues=false );
756 
757 }
758 
759 #endif
760 
761 #endif