MRPT  2.0.4
chessboard_stereo_camera_calib.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #pragma once
11 
12 #include <mrpt/img/CImage.h>
13 #include <mrpt/img/TStereoCamera.h>
14 #include <mrpt/poses/CPose3D.h>
16 #include <mrpt/vision/types.h>
17 #include <array>
18 
19 namespace mrpt::vision
20 {
21 /** \addtogroup chessboard_calib Chessboard calibration
22  * \ingroup mrpt_vision_grp
23  * @{ */
24 
25 /** Data associated to each stereo image in the calibration process
26  * mrpt::vision::checkerBoardCameraCalibration (All the information can be left
27  * empty and will be filled up in the calibration method).
28  */
30 {
32 
33  /** Empty all the data */
34  void clear() { *this = TImageStereoCalibData(); }
35 };
36 
37 /** Params of the optional callback provided by the user */
39 {
40  /** =-1:Processing images; =0: Initial calib without distortion, =1: Calib
41  * of all parameters */
42  int calibRound{-1};
43  size_t current_iter{0};
44  /** Current root-mean square reprojection error (in pixels) */
45  double current_rmse{0};
46  /** Info for calibRound==-1 */
47  unsigned int nImgsProcessed{0}, nImgsToProcess{0};
48 };
49 
50 /** Prototype of optional user callback function. */
52  void (*)(const TImageStereoCallbackData& d, void* user_data);
53 
54 /** Input parameters for mrpt::vision::checkerBoardStereoCalibration */
56 {
57  /** The number of squares in the checkerboard in the "X" & "Y" direction. */
58  unsigned int check_size_x{7}, check_size_y{9};
59  /** The size of each square in the checkerboard, in meters, in the "X" & Y"
60  * axes. */
63  bool normalize_image{true};
64  bool skipDrawDetectedImgs{false};
65  /** Show progress messages to std::cout console (default=true) */
66  bool verbose{true};
67  /** Maximum number of iterations of the optimizer (default=300) */
68  size_t maxIters{2000};
69 
70  /** Select which distortion parameters (of both left/right cameras) will be
71  * optimzed:
72  * k1,k2,k3 are the r^2, r^4 and r^6 radial distorion coeficients, and t1
73  * and t2 are the tangential distortion coeficients (see
74  * mrpt::img::TCamera).
75  * Those set to false will be assumed to be fixed to zero (no distortion).
76  * \note Default values are to only assume distortion via k1 and k2 (the
77  * rest are zeros).
78  */
79  bool optimize_k1{true}, optimize_k2{true}, optimize_k3{false},
80  optimize_t1{false}, optimize_t2{false};
81 
82  /** Employ a Pseudo-Huber robustifier kernel (Default: false) */
83  bool use_robust_kernel{false};
84  /** The parameter of the robust kernel, in pixels (only if
85  * use_robust_kernel=true) (Default=10) */
86  double robust_kernel_param{10};
87 
88  /** If set to !=NULL, this function will be called within each Lev-Marq.
89  * iteration (don't do heavy stuff here since performance will degrade) */
91  /** If using a callback function, you can use this to pass custom data to
92  * your callback. */
93  void* callback_user_param{nullptr};
94 
95  // Ctor: Set default values
97 };
98 
99 /** Output results for mrpt::vision::checkerBoardStereoCalibration */
101 {
103 
104  /** Recovered parameters of the stereo camera */
106  /** The pose of the left camera as seen from the right camera */
108 
109  /** Poses of the origin of coordinates of the pattern wrt the left camera
110  * (i.e. the origin of coordinates, as seen from the different camera poses)
111  */
112  std::vector<mrpt::math::TPose3D> left_cam_poses;
113  /** true if a checkerboard was correctly detected in both left/right images.
114  * false if it wasn't, so the image pair didn't make it to the optimization.
115  */
116  std::vector<bool> image_pair_was_used;
117 
118  /** Final reprojection square Root Mean Square Error (in pixels). */
119  double final_rmse{0};
120  /** Final number of optimization iterations executed. */
121  size_t final_iters{0};
122  /** Number of image pairs in which valid checkerboards were correctly
123  * detected. */
125 
126  /** The inverse variance (information/precision) of each of the 9 left/right
127  * camera parameters [fx fy cx cy k1 k2 k3 t1 t2].
128  * Those not estimated as indicated in TStereoCalibParams will be zeros
129  * (i.e. an "infinite uncertainty")
130  */
132 };
133 
134 /** A list of images, used in checkerBoardStereoCalibration
135  * \sa checkerBoardStereoCalibration
136  */
137 using TCalibrationStereoImageList = std::vector<TImageStereoCalibData>;
138 
139 /** Optimize the calibration parameters of a stereo camera or a RGB+D (Kinect)
140  * camera.
141  * This computes the projection and distortion parameters of each camera, and
142  * their relative spatial pose,
143  * from a sequence of pairs of captured images of a checkerboard.
144  * A custom implementation of an optimizer (Levenberg-Marquartd) seeks for the
145  * set of selected parameters to estimate that minimize the reprojection errors.
146  *
147  * \param input_images [IN/OUT] At input, this list must have one entry for
148  * each image to process. At output the original, detected checkboard and
149  * rectified images can be found here. See TImageCalibData.
150  * \param params [IN] Mandatory: the user must provide the size of the
151  * checkerboard, which parameters to optimize and which to leave fixed to zero,
152  * etc.
153  * \param out_results [OUT] The results of the calibration, and its
154  * uncertainty measure, will be found here upon return.
155  *
156  * \return false on any error (more info will be dumped to cout), or true on
157  * success.
158  * \note See also the ready-to-use application: <a
159  * href="http://www.mrpt.org/list-of-mrpt-apps/application-kinect-calibrate"
160  * >kinect-calibrate</a>
161  * \sa CImage::findChessboardCorners, checkerBoardCameraCalibration,
162  * mrpt::hwdrivers::CKinect
163  */
166  TStereoCalibResults& out_results);
167 
168 /** @} */ // end of grouping
169 } // namespace mrpt::vision
mrpt::vision::TStereoCalibParams::maxIters
size_t maxIters
Maximum number of iterations of the optimizer (default=300)
Definition: chessboard_stereo_camera_calib.h:68
mrpt::vision::TStereoCalibResults::left_cam_poses
std::vector< mrpt::math::TPose3D > left_cam_poses
Poses of the origin of coordinates of the pattern wrt the left camera (i.e.
Definition: chessboard_stereo_camera_calib.h:112
mrpt::vision::TStereoCalibParams::normalize_image
bool normalize_image
Definition: chessboard_stereo_camera_calib.h:63
mrpt::vision::TStereoCalibParams::callback_user_param
void * callback_user_param
If using a callback function, you can use this to pass custom data to your callback.
Definition: chessboard_stereo_camera_calib.h:93
mrpt::vision::TStereoCalibResults::right_params_inv_variance
std::array< double, 9 > right_params_inv_variance
Definition: chessboard_stereo_camera_calib.h:131
mrpt::vision::TImageStereoCallbackData::current_iter
size_t current_iter
Definition: chessboard_stereo_camera_calib.h:43
mrpt::vision::TStereoCalibParams::optimize_k2
bool optimize_k2
Definition: chessboard_stereo_camera_calib.h:79
mrpt::vision::TImageStereoCalibData::left
TImageCalibData left
Definition: chessboard_stereo_camera_calib.h:31
TStereoCamera.h
mrpt::vision::TStereoCalibParams::check_size_y
unsigned int check_size_y
Definition: chessboard_stereo_camera_calib.h:58
mrpt::vision::checkerBoardStereoCalibration
bool checkerBoardStereoCalibration(TCalibrationStereoImageList &images, const TStereoCalibParams &params, TStereoCalibResults &out_results)
Optimize the calibration parameters of a stereo camera or a RGB+D (Kinect) camera.
Definition: chessboard_stereo_camera_calib.cpp:44
mrpt::vision::TImageStereoCalibData::right
TImageCalibData right
Definition: chessboard_stereo_camera_calib.h:31
mrpt::vision
Copyright (C) 2010 Hauke Strasdat Imperial College London Copyright (c) 2005-2020,...
Definition: bundle_adjustment.h:35
mrpt::vision::TStereoCalibParams
Input parameters for mrpt::vision::checkerBoardStereoCalibration.
Definition: chessboard_stereo_camera_calib.h:55
mrpt::vision::TImageStereoCallbackData::nImgsToProcess
unsigned int nImgsToProcess
Definition: chessboard_stereo_camera_calib.h:47
mrpt::vision::TStereoCalibResults::image_pair_was_used
std::vector< bool > image_pair_was_used
true if a checkerboard was correctly detected in both left/right images.
Definition: chessboard_stereo_camera_calib.h:116
mrpt::vision::TStereoCalibResults::cam_params
mrpt::img::TStereoCamera cam_params
Recovered parameters of the stereo camera.
Definition: chessboard_stereo_camera_calib.h:105
mrpt::vision::TImageStereoCalibData
Data associated to each stereo image in the calibration process mrpt::vision::checkerBoardCameraCalib...
Definition: chessboard_stereo_camera_calib.h:29
mrpt::vision::TStereoCalibParams::check_squares_length_X_meters
double check_squares_length_X_meters
The size of each square in the checkerboard, in meters, in the "X" & Y" axes.
Definition: chessboard_stereo_camera_calib.h:61
images
mrpt::vision::TCalibrationStereoImageList images
Definition: chessboard_stereo_camera_calib_unittest.cpp:20
mrpt::vision::TStereoCalibParams::TStereoCalibParams
TStereoCalibParams()
mrpt::vision::TStereoCalibResults::right2left_camera_pose
mrpt::poses::CPose3D right2left_camera_pose
The pose of the left camera as seen from the right camera.
Definition: chessboard_stereo_camera_calib.h:107
mrpt::vision::TStereoCalibResults::TStereoCalibResults
TStereoCalibResults()
mrpt::vision::TImageCalibData
Data associated to each image in the calibration process mrpt::vision::checkerBoardCameraCalibration ...
Definition: chessboard_camera_calib.h:28
mrpt::vision::TStereoCalibParams::callback
TSteroCalibCallbackFunctor callback
If set to !=NULL, this function will be called within each Lev-Marq.
Definition: chessboard_stereo_camera_calib.h:90
chessboard_camera_calib.h
mrpt::vision::TStereoCalibParams::skipDrawDetectedImgs
bool skipDrawDetectedImgs
Definition: chessboard_stereo_camera_calib.h:64
mrpt::vision::TStereoCalibResults::final_number_good_image_pairs
size_t final_number_good_image_pairs
Number of image pairs in which valid checkerboards were correctly detected.
Definition: chessboard_stereo_camera_calib.h:124
mrpt::vision::TStereoCalibParams::check_size_x
unsigned int check_size_x
The number of squares in the checkerboard in the "X" & "Y" direction.
Definition: chessboard_stereo_camera_calib.h:58
mrpt::img::TStereoCamera
Structure to hold the parameters of a pinhole stereo camera model.
Definition: TStereoCamera.h:23
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
mrpt::vision::TStereoCalibResults
Output results for mrpt::vision::checkerBoardStereoCalibration.
Definition: chessboard_stereo_camera_calib.h:100
mrpt::vision::TImageStereoCallbackData::nImgsProcessed
unsigned int nImgsProcessed
Info for calibRound==-1.
Definition: chessboard_stereo_camera_calib.h:47
mrpt::vision::TSteroCalibCallbackFunctor
void(*)(const TImageStereoCallbackData &d, void *user_data) TSteroCalibCallbackFunctor
Prototype of optional user callback function.
Definition: chessboard_stereo_camera_calib.h:52
mrpt::vision::TStereoCalibResults::final_iters
size_t final_iters
Final number of optimization iterations executed.
Definition: chessboard_stereo_camera_calib.h:121
params
mrpt::vision::TStereoCalibParams params
Definition: chessboard_stereo_camera_calib_unittest.cpp:24
mrpt::vision::TImageStereoCalibData::clear
void clear()
Empty all the data.
Definition: chessboard_stereo_camera_calib.h:34
mrpt::vision::TStereoCalibParams::verbose
bool verbose
Show progress messages to std::cout console (default=true)
Definition: chessboard_stereo_camera_calib.h:66
CPose3D.h
mrpt::vision::TStereoCalibResults::final_rmse
double final_rmse
Final reprojection square Root Mean Square Error (in pixels).
Definition: chessboard_stereo_camera_calib.h:119
mrpt::vision::TImageStereoCallbackData::current_rmse
double current_rmse
Current root-mean square reprojection error (in pixels)
Definition: chessboard_stereo_camera_calib.h:45
mrpt::vision::TImageStereoCallbackData
Params of the optional callback provided by the user.
Definition: chessboard_stereo_camera_calib.h:38
mrpt::vision::TStereoCalibParams::optimize_t1
bool optimize_t1
Definition: chessboard_stereo_camera_calib.h:80
mrpt::vision::TImageStereoCallbackData::calibRound
int calibRound
=-1:Processing images; =0: Initial calib without distortion, =1: Calib of all parameters
Definition: chessboard_stereo_camera_calib.h:42
mrpt::vision::TCalibrationStereoImageList
std::vector< TImageStereoCalibData > TCalibrationStereoImageList
A list of images, used in checkerBoardStereoCalibration.
Definition: chessboard_stereo_camera_calib.h:137
mrpt::vision::TStereoCalibParams::check_squares_length_Y_meters
double check_squares_length_Y_meters
Definition: chessboard_stereo_camera_calib.h:62
mrpt::vision::TStereoCalibResults::left_params_inv_variance
std::array< double, 9 > left_params_inv_variance
The inverse variance (information/precision) of each of the 9 left/right camera parameters [fx fy cx ...
Definition: chessboard_stereo_camera_calib.h:131
CImage.h
mrpt::vision::TStereoCalibParams::use_robust_kernel
bool use_robust_kernel
Employ a Pseudo-Huber robustifier kernel (Default: false)
Definition: chessboard_stereo_camera_calib.h:83
mrpt::vision::TStereoCalibParams::optimize_t2
bool optimize_t2
Definition: chessboard_stereo_camera_calib.h:80
types.h
mrpt::vision::TStereoCalibParams::robust_kernel_param
double robust_kernel_param
The parameter of the robust kernel, in pixels (only if use_robust_kernel=true) (Default=10)
Definition: chessboard_stereo_camera_calib.h:86
mrpt::vision::TStereoCalibParams::optimize_k1
bool optimize_k1
Select which distortion parameters (of both left/right cameras) will be optimzed: k1,...
Definition: chessboard_stereo_camera_calib.h:79
mrpt::vision::TStereoCalibParams::optimize_k3
bool optimize_k3
Definition: chessboard_stereo_camera_calib.h:79



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sun Jul 19 17:54:30 UTC 2020