CalibrationCreator2.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package VisionX::ArmarXObjects::CalibrationCreator2
17 * @author Christian R. G. Dreher <c.dreher@kit.edu>
18 * @date 2020
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
23
24#pragma once
25
26
27#include <string>
28
29// VisionX
31
32// IVT
33#include <opencv2/calib3d.hpp>
34#include <opencv2/core.hpp>
35#include <opencv2/core/utility.hpp>
36#include <opencv2/highgui.hpp>
37#include <opencv2/imgcodecs.hpp>
38#include <opencv2/imgproc.hpp>
39#include <opencv2/videoio.hpp>
40
41#include <Math/Math2d.h>
42#include <Math/Math3d.h>
43
44
45class CByteImage;
46
47namespace visionx
48{
49
51 {
52 public:
54 {
55 }
56
64
65 void
67 {
68 goodInput = true;
69 if (boardSize.width <= 0 || boardSize.height <= 0)
70 {
71 ARMARX_ERROR << "Invalid Board size: " << boardSize.width << " "
72 << boardSize.height;
73 goodInput = false;
74 }
75 if (squareSize <= 10e-6)
76 {
77 ARMARX_ERROR << "Invalid square size " << squareSize;
78 goodInput = false;
79 }
80 if (nrFrames <= 0)
81 {
82 ARMARX_ERROR << "Invalid number of frames " << nrFrames;
83 goodInput = false;
84 }
85
86 flag = 0;
87
88 if (useK3ToK6)
89 {
90 flag |= cv::CALIB_RATIONAL_MODEL;
91 }
92 else
93 {
94 flag |= cv::CALIB_FIX_K3;
95 flag |= cv::CALIB_FIX_K4;
96 flag |= cv::CALIB_FIX_K5;
97 flag |= cv::CALIB_FIX_K6;
98 }
99
100 //flag |= cv::CALIB_FIX_PRINCIPAL_POINT;
101 //flag |= cv::CALIB_ZERO_TANGENT_DIST;
102 if (aspectRatio)
103 {
104 flag |= cv::CALIB_FIX_ASPECT_RATIO;
105 }
106 //flag |= cv::CALIB_FIX_K1;
107 //flag |= cv::CALIB_FIX_K2;
108
110 {
111 ARMARX_ERROR << " Camera calibration mode does not exist. ";
112 goodInput = false;
113 }
114 }
115
116 public:
117 cv::Size boardSize; // The size of the board -> Number of items by width and height
118 Pattern calibrationPattern; // One of the Chessboard, circles, or asymmetric circle pattern
119 double squareSize; // The size of a square in your defined unit (point, millimeter,etc).
120 int nrFrames; // The number of frames to use from the input for calibration
121 float aspectRatio; // The aspect ratio
122 bool writePoints; // Write detected feature points
123 bool writeExtrinsics; // Write extrinsic parameters
124 bool flipVertical; // Flip the captured images around the horizontal axis
125 std::string outputFileName; // The name of the file where to write
127
129 int flag;
130 };
131
133 {
134 public:
135 static const std::string default_name;
136
137 static std::string GetDefaultName()
138 {
139 return default_name;
140 }
141
142 std::string
143 getDefaultName() const override
144 {
145 return GetDefaultName();
146 }
147
148 protected:
149 // inherited from VisionComponent
150 void onInitImageProcessor() override;
151 void onConnectImageProcessor() override;
152 void onDisconnectImageProcessor() override;
153 void onExitImageProcessor() override;
154
155 void process() override;
156
157 /**
158 * @see PropertyUser::createPropertyDefinitions()
159 */
162 {
165
166 def->defineOptionalProperty<std::string>("ImageProviderAdapterName",
167 "ImageProvider",
168 "Ice Adapter name of the image provider");
169 def->defineOptionalProperty<int>(
170 "NumberOfImages", 20, "Number of images used for the calibration");
171 def->defineOptionalProperty<int>(
172 "WaitingIntervalBetweenImages", 500, "Waiting time between captured images, in ms");
173 def->defineOptionalProperty<int>("NumberOfRows",
174 5,
175 "Number of corner rows on the calibration pattern "
176 "(height; chessboard squares - 1)");
177 def->defineOptionalProperty<int>("NumberOfColumns",
178 5,
179 "Number of corner columns on the calibration pattern "
180 "(width; chessboard squares - 1)");
181 def->defineOptionalProperty<double>(
182 "PatternSquareSize", 30.0, "Size of the squares on the calibration pattern");
183 def->defineOptionalProperty<std::string>(
184 "OutputFileName", "cameras.txt", "Path to the file for saving the calibration");
185 def->defineOptionalProperty<bool>(
186 "UseAdditionalParams", false, "Also use K3-K6 parameters");
187 def->defineOptionalProperty<bool>(
188 "EnableFixAspectRatio", false, "Fix/Calibrate focal length aspect ratio");
189 def->defineOptionalProperty<std::string>(
190 "ImageToUse", "left", "Use left or rigth image for calibration")
191 .map("left", "left")
192 .map("right", "right");
193 return def;
194 }
195
196 private:
197 enum
198 {
199 CAPTURING,
200 CALIBRATED
201 };
202
203 int m_mode = CAPTURING;
204
205 Settings m_settings;
206
207 std::vector<std::vector<cv::Point2f>> imagePoints;
208 cv::Mat cameraMatrix, distCoeffs;
209 cv::Size imageSize;
210
211 std::string providerName;
212 ImageProviderInterfacePrx imageProviderPrx;
213
214 // CvCalibFilter* m_pCalibFilter;
215 // CvPoint2D32f* m_pCorners2DFloat;
216 // CvPoint2D64f* m_pCorners2D;
217 // CvPoint3D64f* m_pCorners3D;
218
219 CByteImage** cameraImages;
220 //int waitingIntervalBetweenImages, desiredNumberOfImages, numberOfCapturedImages;
221 std::string m_outputFileName;
222
223 IceUtil::Time waitingTimeBetweenCaptures;
224 IceUtil::Time timeOfLastCapture;
225 unsigned int imageID;
226 bool finished;
227 };
228
229} // namespace visionx
Default component property definition container.
Definition Component.h:70
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
static const std::string default_name
void onConnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component is fully initia...
void onExitImageProcessor() override
Exit the ImapeProcessor component.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void process() override
Process the vision component.
void onInitImageProcessor() override
Setup the vision component.
static std::string GetDefaultName()
void onDisconnectImageProcessor() override
Implement this method in the ImageProcessor in order execute parts when the component looses network ...
std::string getDefaultName() const override
Retrieve default name of component.
The ImageProcessor class provides an interface for access to ImageProviders via Ice and shared memory...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
ArmarX headers.