1// This file is part of OpenCV project.
2// It is subject to the license terms in the LICENSE file found in the top-level directory
3// of this distribution and at http://opencv.org/license.html.
4
5#ifndef CALIB_COMMON_HPP
6#define CALIB_COMMON_HPP
7
8#include <opencv2/core.hpp>
9
10#include <memory>
11#include <vector>
12#include <string>
13
14namespace calib
15{
16 #define OVERLAY_DELAY 1000
17 #define IMAGE_MAX_WIDTH 1280
18 #define IMAGE_MAX_HEIGHT 960
19
20 bool showOverlayMessage(const std::string& message);
21
22 enum InputType { Video, Pictures };
23 enum InputVideoSource { Camera, File };
24 enum TemplateType { AcirclesGrid, Chessboard, ChArUco, DoubleAcirclesGrid, CirclesGrid };
25
26 static const std::string mainWindowName = "Calibration";
27 static const std::string gridWindowName = "Board locations";
28 static const std::string consoleHelp = "Hot keys:\nesc - exit application\n"
29 "s - save current data to .xml file\n"
30 "r - delete last frame\n"
31 "u - enable/disable applying undistortion\n"
32 "d - delete all frames\n"
33 "v - switch visualization";
34
35 static const double sigmaMult = 1.96;
36
37 struct calibrationData
38 {
39 cv::Mat cameraMatrix;
40 cv::Mat distCoeffs;
41 cv::Mat stdDeviations;
42 cv::Mat perViewErrors;
43 std::vector<cv::Mat> rvecs;
44 std::vector<cv::Mat> tvecs;
45 double totalAvgErr;
46 cv::Size imageSize;
47
48 std::vector<cv::Mat> allFrames;
49
50 std::vector<std::vector<cv::Point2f> > imagePoints;
51 std::vector< std::vector<cv::Point3f> > objectPoints;
52
53 std::vector<cv::Mat> allCharucoCorners;
54 std::vector<cv::Mat> allCharucoIds;
55
56 cv::Mat undistMap1, undistMap2;
57
58 calibrationData()
59 {
60 imageSize = cv::Size(IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT);
61 }
62 };
63
64 struct cameraParameters
65 {
66 cv::Mat cameraMatrix;
67 cv::Mat distCoeffs;
68 cv::Mat stdDeviations;
69 double avgError;
70
71 cameraParameters(){}
72 cameraParameters(cv::Mat& _cameraMatrix, cv::Mat& _distCoeffs, cv::Mat& _stdDeviations, double _avgError = 0) :
73 cameraMatrix(_cameraMatrix), distCoeffs(_distCoeffs), stdDeviations(_stdDeviations), avgError(_avgError)
74 {}
75 };
76
77 struct captureParameters
78 {
79 InputType captureMethod;
80 InputVideoSource source;
81 TemplateType board;
82 cv::Size inputBoardSize;
83 cv::Size boardSizeInnerCorners; // board size in inner corners for chessboard
84 cv::Size boardSizeUnits; // board size in squares, circles, etc.
85 int charucoDictName;
86 std::string charucoDictFile;
87 int calibrationStep;
88 float charucoSquareLength, charucoMarkerSize;
89 float captureDelay;
90 float squareSize;
91 float templDst;
92 std::string videoFileName;
93 bool flipVertical;
94 int camID;
95 int fps;
96 cv::Size cameraResolution;
97 int maxFramesNum;
98 int minFramesNum;
99 bool saveFrames;
100 float zoom;
101 bool forceReopen;
102
103 captureParameters()
104 {
105 calibrationStep = 1;
106 captureDelay = 500.f;
107 maxFramesNum = 30;
108 minFramesNum = 10;
109 fps = 30;
110 cameraResolution = cv::Size(IMAGE_MAX_WIDTH, IMAGE_MAX_HEIGHT);
111 saveFrames = false;
112 }
113 };
114
115 struct internalParameters
116 {
117 double solverEps;
118 int solverMaxIters;
119 bool fastSolving;
120 double filterAlpha;
121
122 internalParameters()
123 {
124 solverEps = 1e-7;
125 solverMaxIters = 30;
126 fastSolving = false;
127 filterAlpha = 0.1;
128 }
129 };
130}
131
132#endif
133

source code of opencv/apps/interactive-calibration/calibCommon.hpp