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 std::string
138 getDefaultName() const override
139 {
140 return default_name;
141 }
142
143 protected:
144 // inherited from VisionComponent
145 void onInitImageProcessor() override;
146 void onConnectImageProcessor() override;
147 void onDisconnectImageProcessor() override;
148 void onExitImageProcessor() override;
149
150 void process() override;
151
152 /**
153 * @see PropertyUser::createPropertyDefinitions()
154 */
157 {
160
161 def->defineOptionalProperty<std::string>("ImageProviderAdapterName",
162 "ImageProvider",
163 "Ice Adapter name of the image provider");
164 def->defineOptionalProperty<int>(
165 "NumberOfImages", 20, "Number of images used for the calibration");
166 def->defineOptionalProperty<int>(
167 "WaitingIntervalBetweenImages", 500, "Waiting time between captured images, in ms");
168 def->defineOptionalProperty<int>("NumberOfRows",
169 5,
170 "Number of corner rows on the calibration pattern "
171 "(height; chessboard squares - 1)");
172 def->defineOptionalProperty<int>("NumberOfColumns",
173 5,
174 "Number of corner columns on the calibration pattern "
175 "(width; chessboard squares - 1)");
176 def->defineOptionalProperty<double>(
177 "PatternSquareSize", 30.0, "Size of the squares on the calibration pattern");
178 def->defineOptionalProperty<std::string>(
179 "OutputFileName", "cameras.txt", "Path to the file for saving the calibration");
180 def->defineOptionalProperty<bool>(
181 "UseAdditionalParams", false, "Also use K3-K6 parameters");
182 def->defineOptionalProperty<bool>(
183 "EnableFixAspectRatio", false, "Fix/Calibrate focal length aspect ratio");
184 def->defineOptionalProperty<std::string>(
185 "ImageToUse", "left", "Use left or rigth image for calibration")
186 .map("left", "left")
187 .map("right", "right");
188 return def;
189 }
190
191 private:
192 enum
193 {
194 CAPTURING,
195 CALIBRATED
196 };
197
198 int m_mode = CAPTURING;
199
200 Settings m_settings;
201
202 std::vector<std::vector<cv::Point2f>> imagePoints;
203 cv::Mat cameraMatrix, distCoeffs;
204 cv::Size imageSize;
205
206 std::string providerName;
207 ImageProviderInterfacePrx imageProviderPrx;
208
209 // CvCalibFilter* m_pCalibFilter;
210 // CvPoint2D32f* m_pCorners2DFloat;
211 // CvPoint2D64f* m_pCorners2D;
212 // CvPoint3D64f* m_pCorners3D;
213
214 CByteImage** cameraImages;
215 //int waitingIntervalBetweenImages, desiredNumberOfImages, numberOfCapturedImages;
216 std::string m_outputFileName;
217
218 IceUtil::Time waitingTimeBetweenCaptures;
219 IceUtil::Time timeOfLastCapture;
220 unsigned int imageID;
221 bool finished;
222 };
223
224} // 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.
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.