Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/stitching/include/opencv2/stitching.hpp
16337 views
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) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
16
//
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
19
//
20
// * Redistribution's of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
22
//
23
// * Redistribution's in binary form must reproduce the above copyright notice,
24
// this list of conditions and the following disclaimer in the documentation
25
// and/or other materials provided with the distribution.
26
//
27
// * The name of the copyright holders may not be used to endorse or promote products
28
// derived from this software without specific prior written permission.
29
//
30
// This software is provided by the copyright holders and contributors "as is" and
31
// any express or implied warranties, including, but not limited to, the implied
32
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33
// In no event shall the Intel Corporation or contributors be liable for any direct,
34
// indirect, incidental, special, exemplary, or consequential damages
35
// (including, but not limited to, procurement of substitute goods or services;
36
// loss of use, data, or profits; or business interruption) however caused
37
// and on any theory of liability, whether in contract, strict liability,
38
// or tort (including negligence or otherwise) arising in any way out of
39
// the use of this software, even if advised of the possibility of such damage.
40
//
41
//M*/
42
43
#ifndef OPENCV_STITCHING_STITCHER_HPP
44
#define OPENCV_STITCHING_STITCHER_HPP
45
46
#include "opencv2/core.hpp"
47
#include "opencv2/features2d.hpp"
48
#include "opencv2/stitching/warpers.hpp"
49
#include "opencv2/stitching/detail/matchers.hpp"
50
#include "opencv2/stitching/detail/motion_estimators.hpp"
51
#include "opencv2/stitching/detail/exposure_compensate.hpp"
52
#include "opencv2/stitching/detail/seam_finders.hpp"
53
#include "opencv2/stitching/detail/blenders.hpp"
54
#include "opencv2/stitching/detail/camera.hpp"
55
56
57
#if defined(Status)
58
# warning Detected X11 'Status' macro definition, it can cause build conflicts. Please, include this header before any X11 headers.
59
#endif
60
61
62
/**
63
@defgroup stitching Images stitching
64
65
This figure illustrates the stitching module pipeline implemented in the Stitcher class. Using that
66
class it's possible to configure/remove some steps, i.e. adjust the stitching pipeline according to
67
the particular needs. All building blocks from the pipeline are available in the detail namespace,
68
one can combine and use them separately.
69
70
The implemented stitching pipeline is very similar to the one proposed in @cite BL07 .
71
72
![stitching pipeline](StitchingPipeline.jpg)
73
74
Camera models
75
-------------
76
77
There are currently 2 camera models implemented in stitching pipeline.
78
79
- _Homography model_ expecting perspective transformations between images
80
implemented in @ref cv::detail::BestOf2NearestMatcher cv::detail::HomographyBasedEstimator
81
cv::detail::BundleAdjusterReproj cv::detail::BundleAdjusterRay
82
- _Affine model_ expecting affine transformation with 6 DOF or 4 DOF implemented in
83
@ref cv::detail::AffineBestOf2NearestMatcher cv::detail::AffineBasedEstimator
84
cv::detail::BundleAdjusterAffine cv::detail::BundleAdjusterAffinePartial cv::AffineWarper
85
86
Homography model is useful for creating photo panoramas captured by camera,
87
while affine-based model can be used to stitch scans and object captured by
88
specialized devices. Use @ref cv::Stitcher::create to get preconfigured pipeline for one
89
of those models.
90
91
@note
92
Certain detailed settings of @ref cv::Stitcher might not make sense. Especially
93
you should not mix classes implementing affine model and classes implementing
94
Homography model, as they work with different transformations.
95
96
@{
97
@defgroup stitching_match Features Finding and Images Matching
98
@defgroup stitching_rotation Rotation Estimation
99
@defgroup stitching_autocalib Autocalibration
100
@defgroup stitching_warp Images Warping
101
@defgroup stitching_seam Seam Estimation
102
@defgroup stitching_exposure Exposure Compensation
103
@defgroup stitching_blend Image Blenders
104
@}
105
*/
106
107
namespace cv {
108
109
//! @addtogroup stitching
110
//! @{
111
112
/** @example samples/cpp/stitching.cpp
113
A basic example on image stitching
114
*/
115
116
/** @example samples/cpp/stitching_detailed.cpp
117
A detailed example on image stitching
118
*/
119
120
/** @brief High level image stitcher.
121
122
It's possible to use this class without being aware of the entire stitching pipeline. However, to
123
be able to achieve higher stitching stability and quality of the final images at least being
124
familiar with the theory is recommended.
125
126
@note
127
- A basic example on image stitching can be found at
128
opencv_source_code/samples/cpp/stitching.cpp
129
- A detailed example on image stitching can be found at
130
opencv_source_code/samples/cpp/stitching_detailed.cpp
131
*/
132
class CV_EXPORTS_W Stitcher
133
{
134
public:
135
enum { ORIG_RESOL = -1 };
136
enum Status
137
{
138
OK = 0,
139
ERR_NEED_MORE_IMGS = 1,
140
ERR_HOMOGRAPHY_EST_FAIL = 2,
141
ERR_CAMERA_PARAMS_ADJUST_FAIL = 3
142
};
143
enum Mode
144
{
145
/** Mode for creating photo panoramas. Expects images under perspective
146
transformation and projects resulting pano to sphere.
147
148
@sa detail::BestOf2NearestMatcher SphericalWarper
149
*/
150
PANORAMA = 0,
151
/** Mode for composing scans. Expects images under affine transformation does
152
not compensate exposure by default.
153
154
@sa detail::AffineBestOf2NearestMatcher AffineWarper
155
*/
156
SCANS = 1,
157
158
};
159
160
// Stitcher() {}
161
/** @brief Creates a stitcher with the default parameters.
162
163
@param try_use_gpu Flag indicating whether GPU should be used whenever it's possible.
164
@return Stitcher class instance.
165
*/
166
static Stitcher createDefault(bool try_use_gpu = false);
167
/** @brief Creates a Stitcher configured in one of the stitching modes.
168
169
@param mode Scenario for stitcher operation. This is usually determined by source of images
170
to stitch and their transformation. Default parameters will be chosen for operation in given
171
scenario.
172
@param try_use_gpu Flag indicating whether GPU should be used whenever it's possible.
173
@return Stitcher class instance.
174
*/
175
static Ptr<Stitcher> create(Mode mode = PANORAMA, bool try_use_gpu = false);
176
177
CV_WRAP double registrationResol() const { return registr_resol_; }
178
CV_WRAP void setRegistrationResol(double resol_mpx) { registr_resol_ = resol_mpx; }
179
180
CV_WRAP double seamEstimationResol() const { return seam_est_resol_; }
181
CV_WRAP void setSeamEstimationResol(double resol_mpx) { seam_est_resol_ = resol_mpx; }
182
183
CV_WRAP double compositingResol() const { return compose_resol_; }
184
CV_WRAP void setCompositingResol(double resol_mpx) { compose_resol_ = resol_mpx; }
185
186
CV_WRAP double panoConfidenceThresh() const { return conf_thresh_; }
187
CV_WRAP void setPanoConfidenceThresh(double conf_thresh) { conf_thresh_ = conf_thresh; }
188
189
CV_WRAP bool waveCorrection() const { return do_wave_correct_; }
190
CV_WRAP void setWaveCorrection(bool flag) { do_wave_correct_ = flag; }
191
192
detail::WaveCorrectKind waveCorrectKind() const { return wave_correct_kind_; }
193
void setWaveCorrectKind(detail::WaveCorrectKind kind) { wave_correct_kind_ = kind; }
194
195
Ptr<detail::FeaturesFinder> featuresFinder() { return features_finder_; }
196
const Ptr<detail::FeaturesFinder> featuresFinder() const { return features_finder_; }
197
void setFeaturesFinder(Ptr<detail::FeaturesFinder> features_finder)
198
{ features_finder_ = features_finder; }
199
200
Ptr<detail::FeaturesMatcher> featuresMatcher() { return features_matcher_; }
201
const Ptr<detail::FeaturesMatcher> featuresMatcher() const { return features_matcher_; }
202
void setFeaturesMatcher(Ptr<detail::FeaturesMatcher> features_matcher)
203
{ features_matcher_ = features_matcher; }
204
205
const cv::UMat& matchingMask() const { return matching_mask_; }
206
void setMatchingMask(const cv::UMat &mask)
207
{
208
CV_Assert(mask.type() == CV_8U && mask.cols == mask.rows);
209
matching_mask_ = mask.clone();
210
}
211
212
Ptr<detail::BundleAdjusterBase> bundleAdjuster() { return bundle_adjuster_; }
213
const Ptr<detail::BundleAdjusterBase> bundleAdjuster() const { return bundle_adjuster_; }
214
void setBundleAdjuster(Ptr<detail::BundleAdjusterBase> bundle_adjuster)
215
{ bundle_adjuster_ = bundle_adjuster; }
216
217
/* TODO OpenCV ABI 4.x
218
Ptr<detail::Estimator> estimator() { return estimator_; }
219
const Ptr<detail::Estimator> estimator() const { return estimator_; }
220
void setEstimator(Ptr<detail::Estimator> estimator)
221
{ estimator_ = estimator; }
222
*/
223
224
Ptr<WarperCreator> warper() { return warper_; }
225
const Ptr<WarperCreator> warper() const { return warper_; }
226
void setWarper(Ptr<WarperCreator> creator) { warper_ = creator; }
227
228
Ptr<detail::ExposureCompensator> exposureCompensator() { return exposure_comp_; }
229
const Ptr<detail::ExposureCompensator> exposureCompensator() const { return exposure_comp_; }
230
void setExposureCompensator(Ptr<detail::ExposureCompensator> exposure_comp)
231
{ exposure_comp_ = exposure_comp; }
232
233
Ptr<detail::SeamFinder> seamFinder() { return seam_finder_; }
234
const Ptr<detail::SeamFinder> seamFinder() const { return seam_finder_; }
235
void setSeamFinder(Ptr<detail::SeamFinder> seam_finder) { seam_finder_ = seam_finder; }
236
237
Ptr<detail::Blender> blender() { return blender_; }
238
const Ptr<detail::Blender> blender() const { return blender_; }
239
void setBlender(Ptr<detail::Blender> b) { blender_ = b; }
240
241
/** @overload */
242
CV_WRAP Status estimateTransform(InputArrayOfArrays images);
243
/** @brief These functions try to match the given images and to estimate rotations of each camera.
244
245
@note Use the functions only if you're aware of the stitching pipeline, otherwise use
246
Stitcher::stitch.
247
248
@param images Input images.
249
@param rois Region of interest rectangles.
250
@return Status code.
251
*/
252
Status estimateTransform(InputArrayOfArrays images, const std::vector<std::vector<Rect> > &rois);
253
254
/** @overload */
255
CV_WRAP Status composePanorama(OutputArray pano);
256
/** @brief These functions try to compose the given images (or images stored internally from the other function
257
calls) into the final pano under the assumption that the image transformations were estimated
258
before.
259
260
@note Use the functions only if you're aware of the stitching pipeline, otherwise use
261
Stitcher::stitch.
262
263
@param images Input images.
264
@param pano Final pano.
265
@return Status code.
266
*/
267
Status composePanorama(InputArrayOfArrays images, OutputArray pano);
268
269
/** @overload */
270
CV_WRAP Status stitch(InputArrayOfArrays images, OutputArray pano);
271
/** @brief These functions try to stitch the given images.
272
273
@param images Input images.
274
@param rois Region of interest rectangles.
275
@param pano Final pano.
276
@return Status code.
277
*/
278
Status stitch(InputArrayOfArrays images, const std::vector<std::vector<Rect> > &rois, OutputArray pano);
279
280
std::vector<int> component() const { return indices_; }
281
std::vector<detail::CameraParams> cameras() const { return cameras_; }
282
CV_WRAP double workScale() const { return work_scale_; }
283
284
private:
285
//Stitcher() {}
286
287
Status matchImages();
288
Status estimateCameraParams();
289
290
double registr_resol_;
291
double seam_est_resol_;
292
double compose_resol_;
293
double conf_thresh_;
294
Ptr<detail::FeaturesFinder> features_finder_;
295
Ptr<detail::FeaturesMatcher> features_matcher_;
296
cv::UMat matching_mask_;
297
Ptr<detail::BundleAdjusterBase> bundle_adjuster_;
298
/* TODO OpenCV ABI 4.x
299
Ptr<detail::Estimator> estimator_;
300
*/
301
bool do_wave_correct_;
302
detail::WaveCorrectKind wave_correct_kind_;
303
Ptr<WarperCreator> warper_;
304
Ptr<detail::ExposureCompensator> exposure_comp_;
305
Ptr<detail::SeamFinder> seam_finder_;
306
Ptr<detail::Blender> blender_;
307
308
std::vector<cv::UMat> imgs_;
309
std::vector<std::vector<cv::Rect> > rois_;
310
std::vector<cv::Size> full_img_sizes_;
311
std::vector<detail::ImageFeatures> features_;
312
std::vector<detail::MatchesInfo> pairwise_matches_;
313
std::vector<cv::UMat> seam_est_imgs_;
314
std::vector<int> indices_;
315
std::vector<detail::CameraParams> cameras_;
316
double work_scale_;
317
double seam_scale_;
318
double seam_work_aspect_;
319
double warped_image_scale_;
320
};
321
322
CV_EXPORTS_W Ptr<Stitcher> createStitcher(bool try_use_gpu = false);
323
CV_EXPORTS_W Ptr<Stitcher> createStitcherScans(bool try_use_gpu = false);
324
325
//! @} stitching
326
327
} // namespace cv
328
329
#endif // OPENCV_STITCHING_STITCHER_HPP
330
331