Skip to content

Commit 9011368

Browse files
committed
Merge pull request #266 from jiuerbujie:omnidir_camera_calib
2 parents cdbe335 + bf9dd72 commit 9011368

28 files changed

+11207
-43
lines changed

modules/ccalib/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
Custom Calibration Pattern for 3D reconstruction
22
================================================
3+
1. Custom calibration pattern for 3D reconstruction
4+
2. Omnidirectional camera calibration
5+
3. random pattern calibration object
6+
4. multi-camera calibration
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
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 ([email protected]), 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+
52+
//! @addtogroup ccalib
53+
//! @{
54+
55+
#define HEAD -1
56+
#define INVALID -2
57+
58+
/** @brief Class for multiple camera calibration that supports pinhole camera and omnidirection camera.
59+
For omnidirectional camera model, please refer to omnidir.hpp in ccalib module.
60+
It first calibrate each camera individually, then a bundle adjustment like optimization is applied to
61+
refine extrinsic parameters. So far, it only support "random" pattern for calibration,
62+
see randomPattern.hpp in ccalib module for details.
63+
Images that are used should be named by "cameraIdx-timestamp.*", several images with the same timestamp
64+
means that they are the same pattern that are photographed. cameraIdx should start from 0.
65+
66+
For more details, please refer to paper
67+
B. Li, L. Heng, K. Kevin and M. Pollefeys, "A Multiple-Camera System
68+
Calibration Toolbox Using A Feature Descriptor-Based Calibration
69+
Pattern", in IROS 2013.
70+
*/
71+
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,
134+
TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 200, 1e-7),
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+
209+
//! @}
210+
211+
}} // namespace multicalib, cv
212+
#endif

0 commit comments

Comments
 (0)