CalibrationDialog.h
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7  * Redistributions of source code must retain the above copyright
8  notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright
10  notice, this list of conditions and the following disclaimer in the
11  documentation and/or other materials provided with the distribution.
12  * Neither the name of the Universite de Sherbrooke nor the
13  names of its contributors may be used to endorse or promote products
14  derived from this software without specific prior written permission.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27 
28 #ifndef RTABMAP_CALIBRATIONDIALOG_H_
29 #define RTABMAP_CALIBRATIONDIALOG_H_
30 
31 #include "rtabmap/gui/rtabmap_gui_export.h" // DLL export/import defines
32 
33 #include <QDialog>
34 #include <QSettings>
35 #include <opencv2/opencv.hpp>
36 
39 
41 
42 #if defined(HAVE_OPENCV_ARUCO) || CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7)
43 #include <opencv2/aruco/charuco.hpp>
44 #define HAVE_CHARUCO
45 #endif
46 
47 class Ui_calibrationDialog;
48 class QTextStream;
49 
50 namespace rtabmap {
51 
52 class RTABMAP_GUI_EXPORT CalibrationDialog : public QDialog, public UEventsHandler
53 {
54  Q_OBJECT;
55 
56 public:
57  CalibrationDialog(bool stereo = false, const QString & savingDirectory = ".", bool switchImages = false, QWidget * parent = 0);
58  virtual ~CalibrationDialog();
59 
60  bool isCalibrated() const {return models_[0].isValidForProjection() && (stereo_?models_[1].isValidForProjection():true);}
61  const rtabmap::CameraModel & getLeftCameraModel() const {return models_[0];}
62  const rtabmap::CameraModel & getRightCameraModel() const {return models_[1];}
63  const rtabmap::StereoCameraModel & getStereoCameraModel() const {return stereoModel_;}
64  bool isProcessing() const {return processingData_;}
65  int getStereoPairs() const {return (int)stereoImagePoints_[0].size();}
66  int boardWidth() const;
67  int boardHeight() const;
68  double squareSize() const;
69  double markerLength() const;
70 
71  void saveSettings(QSettings & settings, const QString & group = "") const;
72  void loadSettings(QSettings & settings, const QString & group = "");
73  void resetSettings();
74 
75  void setCameraName(const QString & name);
76  void setProgressVisibility(bool visible);
77  void setSwitchedImages(bool switched);
78  void setFisheyeModel();
79  void setPlumbobModel();
80  void setRationalModel();
81  void setStereoMode(bool stereo, const QString & leftSuffix = "left", const QString & rightSuffix = "right");
82  void setSavingDirectory(const QString & savingDirectory) {savingDirectory_ = savingDirectory;}
83 
84  StereoCameraModel stereoCalibration(const CameraModel & left, const CameraModel & right, bool ignoreStereoRectification, QTextStream * logStream = 0) const;
85 
86 public Q_SLOTS:
87 
88  void setBoardType(int type);
89  void setBoardWidth(int width);
90  void setBoardHeight(int height);
91  void setSquareSize(double size);
92  void setMarkerDictionary(int dictionary);
93  void setMarkerLength(double length);
94  void setSubpixelRefinement(bool enabled);
95  void setSubpixelMaxError(double value);
96  void setCalibrationDataSaved(bool enabled);
97  void setExpectedStereoBaseline(double length);
98  void setMaxScale(int scale);
99 
100  void processImages(const cv::Mat & imageLeft, const cv::Mat & imageRight, const QString & cameraName);
101  void generateBoard();
102  void calibrate();
103  void restart();
104  bool save();
105 
106 private Q_SLOTS:
107  void unlock();
108 
109 protected:
110  virtual void closeEvent(QCloseEvent* event);
111  virtual bool handleEvent(UEvent * event);
112 
113 private:
114  float getArea(const std::vector<cv::Point2f> & corners, const cv::Size & boardSize);
115  float getSkew(const std::vector<cv::Point2f> & fourCorners);
116  float getSkew(const std::vector<cv::Point2f> & corners, const cv::Size & boardSize);
117 
118  // x -> [0, 1] (left, right)
119  // y -> [0, 1] (top, bottom)
120  // size -> [0, 1] (small -> big)
121  // skew -> [0, 1] (low, high)
122  void getParams(const std::vector<cv::Point2f> & corners, const cv::Size & boardSize, const cv::Size & imageSize,
123  float & x, float & y, float & size, float & skew);
124 
125 private:
126  // parameters
127  bool stereo_;
128  QString leftSuffix_;
129  QString rightSuffix_;
131 
132  QString cameraName_;
136  QString timestamp_;
137 
138  std::vector<cv::Point3f> chessboardPoints_;
139  std::vector<int> chessboardPointIds_;
140 #ifdef HAVE_CHARUCO
141  cv::Ptr<cv::aruco::Dictionary> markerDictionary_;
142  cv::Ptr<cv::aruco::DetectorParameters> arucoDetectorParams_;
143  cv::Ptr<cv::aruco::CharucoBoard> charucoBoard_;
144 #endif
145 
146 
147  std::vector<std::vector<std::vector<cv::Point2f> > > imagePoints_;
148  std::vector<std::vector<std::vector<cv::Point3f> > > objectPoints_;
149  std::vector<std::vector<std::vector<float> > > imageParams_;
150  std::vector<std::vector<int > > imageIds_;
151  std::vector<std::vector<std::vector<cv::Point2f> > > stereoImagePoints_;
152  std::vector<std::vector<cv::Point3f> > stereoObjectPoints_;
153  std::vector<int> stereoImageIds_;
154  std::vector<cv::Size > imageSize_;
155  std::vector<rtabmap::CameraModel> models_;
157  std::vector<unsigned short> minIrs_;
158  std::vector<unsigned short> maxIrs_;
159 
160  Ui_calibrationDialog * ui_;
161 };
162 
163 } /* namespace rtabmap */
164 #endif /* CALIBRATIONDIALOG_H_ */
UEventsHandler
Definition: UEventsHandler.h:128
rtabmap::CalibrationDialog::cameraName_
QString cameraName_
Definition: CalibrationDialog.h:132
save
save
rtabmap::CalibrationDialog::getLeftCameraModel
const rtabmap::CameraModel & getLeftCameraModel() const
Definition: CalibrationDialog.h:61
name
rtabmap::StereoCameraModel
Definition: StereoCameraModel.h:35
glm::length
GLM_FUNC_DECL genType::value_type length(genType const &x)
rtabmap::CalibrationDialog::minIrs_
std::vector< unsigned short > minIrs_
Definition: CalibrationDialog.h:157
rtabmap::CalibrationDialog::objectPoints_
std::vector< std::vector< std::vector< cv::Point3f > > > objectPoints_
Definition: CalibrationDialog.h:148
rtabmap::CalibrationDialog::getStereoPairs
int getStereoPairs() const
Definition: CalibrationDialog.h:65
rtabmap::CalibrationDialog::leftSuffix_
QString leftSuffix_
Definition: CalibrationDialog.h:128
rtabmap::CalibrationDialog::currentId_
int currentId_
Definition: CalibrationDialog.h:135
clams::calibrate
DiscreteDepthDistortionModel RTABMAP_CORE_EXPORT calibrate(const std::map< int, rtabmap::SensorData > &sequence, const std::map< int, rtabmap::Transform > &trajectory, const pcl::PointCloud< pcl::PointXYZ >::Ptr &map, double coneRadius=0.02, double coneStdevThresh=0.03)
rtabmap::CameraModel
Definition: CameraModel.h:38
rtabmap::CalibrationDialog::imageSize_
std::vector< cv::Size > imageSize_
Definition: CalibrationDialog.h:154
rtabmap::CalibrationDialog::imageParams_
std::vector< std::vector< std::vector< float > > > imageParams_
Definition: CalibrationDialog.h:149
rtabmap::CalibrationDialog::rightSuffix_
QString rightSuffix_
Definition: CalibrationDialog.h:129
type
rtabmap::CalibrationDialog::getStereoCameraModel
const rtabmap::StereoCameraModel & getStereoCameraModel() const
Definition: CalibrationDialog.h:63
rtabmap::CalibrationDialog::stereoImagePoints_
std::vector< std::vector< std::vector< cv::Point2f > > > stereoImagePoints_
Definition: CalibrationDialog.h:151
UEvent
Definition: UEvent.h:57
rtabmap::CalibrationDialog::ui_
Ui_calibrationDialog * ui_
Definition: CalibrationDialog.h:160
rtabmap::CalibrationDialog::models_
std::vector< rtabmap::CameraModel > models_
Definition: CalibrationDialog.h:155
rtabmap::CalibrationDialog::stereoImageIds_
std::vector< int > stereoImageIds_
Definition: CalibrationDialog.h:153
rtabmap::CalibrationDialog::getRightCameraModel
const rtabmap::CameraModel & getRightCameraModel() const
Definition: CalibrationDialog.h:62
StereoCameraModel.h
rtabmap::CalibrationDialog::savedCalibration_
bool savedCalibration_
Definition: CalibrationDialog.h:134
rtabmap::CalibrationDialog::isProcessing
bool isProcessing() const
Definition: CalibrationDialog.h:64
rtabmap::CalibrationDialog::setSavingDirectory
void setSavingDirectory(const QString &savingDirectory)
Definition: CalibrationDialog.h:82
rtabmap::CalibrationDialog::stereo_
bool stereo_
Definition: CalibrationDialog.h:127
rtabmap::CalibrationDialog::imagePoints_
std::vector< std::vector< std::vector< cv::Point2f > > > imagePoints_
Definition: CalibrationDialog.h:147
UEventsHandler.h
rtabmap::CalibrationDialog::imageIds_
std::vector< std::vector< int > > imageIds_
Definition: CalibrationDialog.h:150
rtabmap::CalibrationDialog::isCalibrated
bool isCalibrated() const
Definition: CalibrationDialog.h:60
rtabmap::CalibrationDialog::stereoObjectPoints_
std::vector< std::vector< cv::Point3f > > stereoObjectPoints_
Definition: CalibrationDialog.h:152
rtabmap::CalibrationDialog
Definition: CalibrationDialog.h:52
rtabmap::CalibrationDialog::processingData_
bool processingData_
Definition: CalibrationDialog.h:133
rtabmap::CalibrationDialog::stereoModel_
rtabmap::StereoCameraModel stereoModel_
Definition: CalibrationDialog.h:156
CameraModel.h
rtabmap::CalibrationDialog::chessboardPointIds_
std::vector< int > chessboardPointIds_
Definition: CalibrationDialog.h:139
rtabmap
Definition: CameraARCore.cpp:35
rtabmap::CalibrationDialog::savingDirectory_
QString savingDirectory_
Definition: CalibrationDialog.h:130
rtabmap::CalibrationDialog::chessboardPoints_
std::vector< cv::Point3f > chessboardPoints_
Definition: CalibrationDialog.h:138
rtabmap::CalibrationDialog::maxIrs_
std::vector< unsigned short > maxIrs_
Definition: CalibrationDialog.h:158
rtabmap::CalibrationDialog::timestamp_
QString timestamp_
Definition: CalibrationDialog.h:136


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:06