OpenCV 4.5.3(日本語機械翻訳)
multicalib.hpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
8 //
9 //
10 // License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2015, Baisheng Lai (laibaisheng@gmail.com), Zhejiang University,
14 // all rights reserved.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
21 //
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
25 //
26 // * The name of the copyright holders may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/
41
42 #ifndef __OPENCV_MULTICAMERACALIBRATION_HPP__
43 #define __OPENCV_MULTICAMERACALIBRATION_HPP__
44
45 #include "opencv2/ccalib/randpattern.hpp"
46 #include "opencv2/ccalib/omnidir.hpp"
47 #include <string>
48 #include <iostream>
49
50 namespace cv { namespace multicalib {
51
54
55 #define HEAD -1
56 #define INVALID -2
57
72 class CV_EXPORTS MultiCameraCalibration
73{
74 public:
75 enum {
76 PINHOLE,
77 OMNIDIRECTIONAL
78 //FISHEYE
79 };
80
81 // an edge connects a camera and pattern
82 struct edge
83 {
84 int cameraVertex; // vertex index for camera in this edge
85 int photoVertex; // vertex index for pattern in this edge
86 int photoIndex; // photo index among photos for this camera
87 Mat transform; // transform from pattern to camera
88
89 edge(int cv, int pv, int pi, Mat trans)
90 {
91 cameraVertex = cv;
92 photoVertex = pv;
93 photoIndex = pi;
94 transform = trans;
95 }
96 };
97
98 struct vertex
99 {
100 Mat pose; // relative pose to the first camera. For camera vertex, it is the
101 // transform from the first camera to this camera, for pattern vertex,
102 // it is the transform from pattern to the first camera
103 int timestamp; // timestamp of photo, only available for photo vertex
104
105 vertex(Mat po, int ts)
106 {
107 pose = po;
108 timestamp = ts;
109 }
110
111 vertex()
112 {
113 pose = Mat::eye(4, 4, CV_32F);
114 timestamp = -1;
115 }
116 };
117 /* @brief Constructor
118 @param cameraType camera type, PINHOLE or OMNIDIRECTIONAL
119 @param nCameras number of cameras
120 @fileName filename of string list that are used for calibration, the file is generated
121 by imagelist_creator from OpenCv samples. The first one in the list is the pattern filename.
122 @patternWidth the physical width of pattern, in user defined unit.
123 @patternHeight the physical height of pattern, in user defined unit.
124 @showExtration whether show extracted features and feature filtering.
125 @nMiniMatches minimal number of matched features for a frame.
126 @flags Calibration flags
127 @criteria optimization stopping criteria.
128 @detector feature detector that detect feature points in pattern and images.
129 @descriptor feature descriptor.
130 @matcher feature matcher.
131 */
132 MultiCameraCalibration(int cameraType, int nCameras, const std::string& fileName, float patternWidth,
133 float patternHeight, int verbose = 0, int showExtration = 0, int nMiniMatches = 20, int flags = 0,
135 Ptr<FeatureDetector> detector = AKAZE::create(AKAZE::DESCRIPTOR_MLDB, 0, 3, 0.006f),
136 Ptr<DescriptorExtractor> descriptor = AKAZE::create(AKAZE::DESCRIPTOR_MLDB,0, 3, 0.006f),
137 Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce-L1"));
138
139 /* @brief load images
140 */
141 void loadImages();
142
143 /* @brief initialize multiple camera calibration. It calibrates each camera individually.
144 */
145 void initialize();
146
147 /* @brief optimization extrinsic parameters
148 */
149 double optimizeExtrinsics();
150
151 /* @brief run multi-camera camera calibration, it runs loadImage(), initialize() and optimizeExtrinsics()
152 */
153 double run();
154
155 /* @brief write camera parameters to file.
156 */
157 void writeParameters(const std::string& filename);
158
159 private:
160 std::vector<std::string> readStringList();
161
162 int getPhotoVertex(int timestamp);
163
164 void graphTraverse(const Mat& G, int begin, std::vector<int>& order, std::vector<int>& pre);
165
166 void findRowNonZero(const Mat& row, Mat& idx);
167
168 void computeJacobianExtrinsic(const Mat& extrinsicParams, Mat& JTJ_inv, Mat& JTE);
169
170 void computePhotoCameraJacobian(const Mat& rvecPhoto, const Mat& tvecPhoto, const Mat& rvecCamera,
171 const Mat& tvecCamera, Mat& rvecTran, Mat& tvecTran, const Mat& objectPoints, const Mat& imagePoints, const Mat& K,
172 const Mat& distort, const Mat& xi, Mat& jacobianPhoto, Mat& jacobianCamera, Mat& E);
173
174 void compose_motion(InputArray _om1, InputArray _T1, InputArray _om2, InputArray _T2, Mat& om3, Mat& T3, Mat& dom3dom1,
175 Mat& dom3dT1, Mat& dom3dom2, Mat& dom3dT2, Mat& dT3dom1, Mat& dT3dT1, Mat& dT3dom2, Mat& dT3dT2);
176
177 void JRodriguesMatlab(const Mat& src, Mat& dst);
178 void dAB(InputArray A, InputArray B, OutputArray dABdA, OutputArray dABdB);
179
180 double computeProjectError(Mat& parameters);
181
182 void vector2parameters(const Mat& parameters, std::vector<Vec3f>& rvecVertex, std::vector<Vec3f>& tvecVertexs);
183 void parameters2vector(const std::vector<Vec3f>& rvecVertex, const std::vector<Vec3f>& tvecVertex, Mat& parameters);
184
185 int _camType; //PINHOLE, FISHEYE or OMNIDIRECTIONAL
186 int _nCamera;
187 int _nMiniMatches;
188 int _flags;
189 int _verbose;
190 double _error;
191 float _patternWidth, _patternHeight;
192 TermCriteria _criteria;
193 std::string _filename;
194 int _showExtraction;
195 Ptr<FeatureDetector> _detector;
196 Ptr<DescriptorExtractor> _descriptor;
197 Ptr<DescriptorMatcher> _matcher;
198
199 std::vector<edge> _edgeList;
200 std::vector<vertex> _vertexList;
201 std::vector<std::vector<cv::Mat> > _objectPointsForEachCamera;
202 std::vector<std::vector<cv::Mat> > _imagePointsForEachCamera;
203 std::vector<cv::Mat> _cameraMatrix;
204 std::vector<cv::Mat> _distortCoeffs;
205 std::vector<cv::Mat> _xi;
206 std::vector<std::vector<Mat> > _omEachCamera, _tEachCamera;
207};
208
210
211}} // namespace multicalib, cv
212 #endif
This type is very similar to InputArray except that it is used for input/output and output function p...
Definition: mat.hpp:295
static CV_WRAP Ptr< AKAZE > create(AKAZE::DescriptorType descriptor_type=AKAZE::DESCRIPTOR_MLDB, int descriptor_size=0, int descriptor_channels=3, float threshold=0.001f, int nOctaves=4, int nOctaveLayers=4, KAZE::DiffusivityType diffusivity=KAZE::DIFF_PM_G2)
The AKAZE constructor
static CV_WRAP Ptr< DescriptorMatcher > create(const String &descriptorMatcherType)
Creates a descriptor matcher of a given type with the default parameters (using default constructor).
n-dimensional dense array class
Definition: mat.hpp:802
static MatExpr eye(int rows, int cols, int type)
Returns an identity matrix of the specified size and type.
The class defining termination criteria for iterative algorithms.
Definition: core/types.hpp:853
@ EPS
the desired accuracy or change in parameters at which the iterative algorithm stops
Definition: core/types.hpp:862
@ COUNT
the maximum number of iterations or elements to compute
Definition: core/types.hpp:860
Class for multiple camera calibration that supports pinhole camera and omnidirection camera....
Definition: multicalib.hpp:73
CV_EXPORTS_W void transform(InputArray src, OutputArray dst, InputArray m)
Performs the matrix transformation of every array element.
cv
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75
Definition: cvstd_wrapper.hpp:74
Definition: multicalib.hpp:83
Definition: multicalib.hpp:99