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_OBJDETECT) && (CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7))
43 #include <opencv2/objdetect/charuco_detector.hpp>
44 #define HAVE_CHARUCO
45 #elif defined(HAVE_OPENCV_ARUCO)
46 #include <opencv2/aruco/charuco.hpp>
47 #define HAVE_CHARUCO
48 #endif
49 
50 class Ui_calibrationDialog;
51 class QTextStream;
52 
53 namespace rtabmap {
54 
55 class RTABMAP_GUI_EXPORT CalibrationDialog : public QDialog, public UEventsHandler
56 {
57  Q_OBJECT;
58 
59 public:
60  CalibrationDialog(bool stereo = false, const QString & savingDirectory = ".", bool switchImages = false, QWidget * parent = 0);
61  virtual ~CalibrationDialog();
62 
63  bool isCalibrated() const {return models_[0].isValidForProjection() && (stereo_?models_[1].isValidForProjection():true);}
64  const rtabmap::CameraModel & getLeftCameraModel() const {return models_[0];}
65  const rtabmap::CameraModel & getRightCameraModel() const {return models_[1];}
66  const rtabmap::StereoCameraModel & getStereoCameraModel() const {return stereoModel_;}
67  bool isProcessing() const {return processingData_;}
68  int getStereoPairs() const {return (int)stereoImagePoints_[0].size();}
69  int boardWidth() const;
70  int boardHeight() const;
71  double squareSize() const;
72  double markerLength() const;
73 
74  void saveSettings(QSettings & settings, const QString & group = "") const;
75  void loadSettings(QSettings & settings, const QString & group = "");
76  void resetSettings();
77 
78  void setCameraName(const QString & name);
79  void setProgressVisibility(bool visible);
80  void setSwitchedImages(bool switched);
81  void setFisheyeModel();
82  void setPlumbobModel();
83  void setRationalModel();
84  void setStereoMode(bool stereo, const QString & leftSuffix = "left", const QString & rightSuffix = "right");
85  void setSavingDirectory(const QString & savingDirectory) {savingDirectory_ = savingDirectory;}
86 
87  StereoCameraModel stereoCalibration(const CameraModel & left, const CameraModel & right, bool ignoreStereoRectification, QTextStream * logStream = 0) const;
88 
89 public Q_SLOTS:
90 
91  void setBoardType(int type);
92  void setBoardWidth(int width);
93  void setBoardHeight(int height);
94  void setSquareSize(double size);
95  void setMarkerDictionary(int dictionary);
96  void setMarkerLength(double length);
97  void setSubpixelRefinement(bool enabled);
98  void setSubpixelMaxError(double value);
99  void setCalibrationDataSaved(bool enabled);
100  void setExpectedStereoBaseline(double length);
101  void setMaxScale(int scale);
102 
103  void processImages(const cv::Mat & imageLeft, const cv::Mat & imageRight, const QString & cameraName);
104  void generateBoard();
105  void calibrate();
106  void restart();
107  bool save();
108 
109 private Q_SLOTS:
110  void unlock();
111 
112 protected:
113  virtual void closeEvent(QCloseEvent* event);
114  virtual bool handleEvent(UEvent * event);
115 
116 private:
117  float getArea(const std::vector<cv::Point2f> & corners, const cv::Size & boardSize);
118  float getSkew(const std::vector<cv::Point2f> & fourCorners);
119  float getSkew(const std::vector<cv::Point2f> & corners, const cv::Size & boardSize);
120 
121  // x -> [0, 1] (left, right)
122  // y -> [0, 1] (top, bottom)
123  // size -> [0, 1] (small -> big)
124  // skew -> [0, 1] (low, high)
125  void getParams(const std::vector<cv::Point2f> & corners, const cv::Size & boardSize, const cv::Size & imageSize,
126  float & x, float & y, float & size, float & skew);
127 
128 private:
129  // parameters
130  bool stereo_;
131  QString leftSuffix_;
132  QString rightSuffix_;
134 
135  QString cameraName_;
139  QString timestamp_;
140 
141  std::vector<cv::Point3f> chessboardPoints_;
142  std::vector<int> chessboardPointIds_;
143 #ifdef HAVE_CHARUCO
144  cv::Ptr<cv::aruco::Dictionary> markerDictionary_;
145  cv::Ptr<cv::aruco::DetectorParameters> arucoDetectorParams_;
146  cv::Ptr<cv::aruco::CharucoBoard> charucoBoard_;
147 #if CV_MAJOR_VERSION > 4 || (CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7)
148  cv::Ptr<cv::aruco::ArucoDetector> arucoDetector_;
149  cv::Ptr<cv::aruco::CharucoDetector> charucoDetector_;
150 #endif
151 #endif
152 
153 
154  std::vector<std::vector<std::vector<cv::Point2f> > > imagePoints_;
155  std::vector<std::vector<std::vector<cv::Point3f> > > objectPoints_;
156  std::vector<std::vector<std::vector<float> > > imageParams_;
157  std::vector<std::vector<int > > imageIds_;
158  std::vector<std::vector<std::vector<cv::Point2f> > > stereoImagePoints_;
159  std::vector<std::vector<cv::Point3f> > stereoObjectPoints_;
160  std::vector<int> stereoImageIds_;
161  std::vector<cv::Size > imageSize_;
162  std::vector<rtabmap::CameraModel> models_;
164  std::vector<unsigned short> minIrs_;
165  std::vector<unsigned short> maxIrs_;
166 
167  Ui_calibrationDialog * ui_;
168 };
169 
170 } /* namespace rtabmap */
171 #endif /* CALIBRATIONDIALOG_H_ */
UEventsHandler
Definition: UEventsHandler.h:128
rtabmap::CalibrationDialog::cameraName_
QString cameraName_
Definition: CalibrationDialog.h:135
save
save
rtabmap::CalibrationDialog::getLeftCameraModel
const rtabmap::CameraModel & getLeftCameraModel() const
Definition: CalibrationDialog.h:64
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:164
rtabmap::CalibrationDialog::objectPoints_
std::vector< std::vector< std::vector< cv::Point3f > > > objectPoints_
Definition: CalibrationDialog.h:155
rtabmap::CalibrationDialog::getStereoPairs
int getStereoPairs() const
Definition: CalibrationDialog.h:68
rtabmap::CalibrationDialog::leftSuffix_
QString leftSuffix_
Definition: CalibrationDialog.h:131
rtabmap::CalibrationDialog::currentId_
int currentId_
Definition: CalibrationDialog.h:138
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:161
rtabmap::CalibrationDialog::imageParams_
std::vector< std::vector< std::vector< float > > > imageParams_
Definition: CalibrationDialog.h:156
rtabmap::CalibrationDialog::rightSuffix_
QString rightSuffix_
Definition: CalibrationDialog.h:132
type
rtabmap::CalibrationDialog::getStereoCameraModel
const rtabmap::StereoCameraModel & getStereoCameraModel() const
Definition: CalibrationDialog.h:66
rtabmap::CalibrationDialog::stereoImagePoints_
std::vector< std::vector< std::vector< cv::Point2f > > > stereoImagePoints_
Definition: CalibrationDialog.h:158
UEvent
Definition: UEvent.h:57
rtabmap::CalibrationDialog::ui_
Ui_calibrationDialog * ui_
Definition: CalibrationDialog.h:167
rtabmap::CalibrationDialog::models_
std::vector< rtabmap::CameraModel > models_
Definition: CalibrationDialog.h:162
rtabmap::CalibrationDialog::stereoImageIds_
std::vector< int > stereoImageIds_
Definition: CalibrationDialog.h:160
rtabmap::CalibrationDialog::getRightCameraModel
const rtabmap::CameraModel & getRightCameraModel() const
Definition: CalibrationDialog.h:65
StereoCameraModel.h
rtabmap::CalibrationDialog::savedCalibration_
bool savedCalibration_
Definition: CalibrationDialog.h:137
rtabmap::CalibrationDialog::isProcessing
bool isProcessing() const
Definition: CalibrationDialog.h:67
rtabmap::CalibrationDialog::setSavingDirectory
void setSavingDirectory(const QString &savingDirectory)
Definition: CalibrationDialog.h:85
rtabmap::CalibrationDialog::stereo_
bool stereo_
Definition: CalibrationDialog.h:130
rtabmap::CalibrationDialog::imagePoints_
std::vector< std::vector< std::vector< cv::Point2f > > > imagePoints_
Definition: CalibrationDialog.h:154
UEventsHandler.h
rtabmap::CalibrationDialog::imageIds_
std::vector< std::vector< int > > imageIds_
Definition: CalibrationDialog.h:157
rtabmap::CalibrationDialog::isCalibrated
bool isCalibrated() const
Definition: CalibrationDialog.h:63
rtabmap::CalibrationDialog::stereoObjectPoints_
std::vector< std::vector< cv::Point3f > > stereoObjectPoints_
Definition: CalibrationDialog.h:159
rtabmap::CalibrationDialog
Definition: CalibrationDialog.h:55
rtabmap::CalibrationDialog::processingData_
bool processingData_
Definition: CalibrationDialog.h:136
rtabmap::CalibrationDialog::stereoModel_
rtabmap::StereoCameraModel stereoModel_
Definition: CalibrationDialog.h:163
CameraModel.h
rtabmap::CalibrationDialog::chessboardPointIds_
std::vector< int > chessboardPointIds_
Definition: CalibrationDialog.h:142
rtabmap
Definition: CameraARCore.cpp:35
rtabmap::CalibrationDialog::savingDirectory_
QString savingDirectory_
Definition: CalibrationDialog.h:133
rtabmap::CalibrationDialog::chessboardPoints_
std::vector< cv::Point3f > chessboardPoints_
Definition: CalibrationDialog.h:141
rtabmap::CalibrationDialog::maxIrs_
std::vector< unsigned short > maxIrs_
Definition: CalibrationDialog.h:165
rtabmap::CalibrationDialog::timestamp_
QString timestamp_
Definition: CalibrationDialog.h:139


rtabmap
Author(s): Mathieu Labbe
autogenerated on Sun Dec 1 2024 03:42:41