Path: blob/master/modules/stitching/include/opencv2/stitching.hpp
16337 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.13// Copyright (C) 2009, Willow Garage Inc., all rights reserved.14// Third party copyrights are property of their respective owners.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 documentation24// and/or other materials provided with the distribution.25//26// * The name of the copyright holders may not be used to endorse or promote products27// derived from this software without specific prior written permission.28//29// This software is provided by the copyright holders and contributors "as is" and30// any express or implied warranties, including, but not limited to, the implied31// 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 damages34// (including, but not limited to, procurement of substitute goods or services;35// loss of use, data, or profits; or business interruption) however caused36// and on any theory of liability, whether in contract, strict liability,37// or tort (including negligence or otherwise) arising in any way out of38// the use of this software, even if advised of the possibility of such damage.39//40//M*/4142#ifndef OPENCV_STITCHING_STITCHER_HPP43#define OPENCV_STITCHING_STITCHER_HPP4445#include "opencv2/core.hpp"46#include "opencv2/features2d.hpp"47#include "opencv2/stitching/warpers.hpp"48#include "opencv2/stitching/detail/matchers.hpp"49#include "opencv2/stitching/detail/motion_estimators.hpp"50#include "opencv2/stitching/detail/exposure_compensate.hpp"51#include "opencv2/stitching/detail/seam_finders.hpp"52#include "opencv2/stitching/detail/blenders.hpp"53#include "opencv2/stitching/detail/camera.hpp"545556#if defined(Status)57# warning Detected X11 'Status' macro definition, it can cause build conflicts. Please, include this header before any X11 headers.58#endif596061/**62@defgroup stitching Images stitching6364This figure illustrates the stitching module pipeline implemented in the Stitcher class. Using that65class it's possible to configure/remove some steps, i.e. adjust the stitching pipeline according to66the particular needs. All building blocks from the pipeline are available in the detail namespace,67one can combine and use them separately.6869The implemented stitching pipeline is very similar to the one proposed in @cite BL07 .70717273Camera models74-------------7576There are currently 2 camera models implemented in stitching pipeline.7778- _Homography model_ expecting perspective transformations between images79implemented in @ref cv::detail::BestOf2NearestMatcher cv::detail::HomographyBasedEstimator80cv::detail::BundleAdjusterReproj cv::detail::BundleAdjusterRay81- _Affine model_ expecting affine transformation with 6 DOF or 4 DOF implemented in82@ref cv::detail::AffineBestOf2NearestMatcher cv::detail::AffineBasedEstimator83cv::detail::BundleAdjusterAffine cv::detail::BundleAdjusterAffinePartial cv::AffineWarper8485Homography model is useful for creating photo panoramas captured by camera,86while affine-based model can be used to stitch scans and object captured by87specialized devices. Use @ref cv::Stitcher::create to get preconfigured pipeline for one88of those models.8990@note91Certain detailed settings of @ref cv::Stitcher might not make sense. Especially92you should not mix classes implementing affine model and classes implementing93Homography model, as they work with different transformations.9495@{96@defgroup stitching_match Features Finding and Images Matching97@defgroup stitching_rotation Rotation Estimation98@defgroup stitching_autocalib Autocalibration99@defgroup stitching_warp Images Warping100@defgroup stitching_seam Seam Estimation101@defgroup stitching_exposure Exposure Compensation102@defgroup stitching_blend Image Blenders103@}104*/105106namespace cv {107108//! @addtogroup stitching109//! @{110111/** @example samples/cpp/stitching.cpp112A basic example on image stitching113*/114115/** @example samples/cpp/stitching_detailed.cpp116A detailed example on image stitching117*/118119/** @brief High level image stitcher.120121It's possible to use this class without being aware of the entire stitching pipeline. However, to122be able to achieve higher stitching stability and quality of the final images at least being123familiar with the theory is recommended.124125@note126- A basic example on image stitching can be found at127opencv_source_code/samples/cpp/stitching.cpp128- A detailed example on image stitching can be found at129opencv_source_code/samples/cpp/stitching_detailed.cpp130*/131class CV_EXPORTS_W Stitcher132{133public:134enum { ORIG_RESOL = -1 };135enum Status136{137OK = 0,138ERR_NEED_MORE_IMGS = 1,139ERR_HOMOGRAPHY_EST_FAIL = 2,140ERR_CAMERA_PARAMS_ADJUST_FAIL = 3141};142enum Mode143{144/** Mode for creating photo panoramas. Expects images under perspective145transformation and projects resulting pano to sphere.146147@sa detail::BestOf2NearestMatcher SphericalWarper148*/149PANORAMA = 0,150/** Mode for composing scans. Expects images under affine transformation does151not compensate exposure by default.152153@sa detail::AffineBestOf2NearestMatcher AffineWarper154*/155SCANS = 1,156157};158159// Stitcher() {}160/** @brief Creates a stitcher with the default parameters.161162@param try_use_gpu Flag indicating whether GPU should be used whenever it's possible.163@return Stitcher class instance.164*/165static Stitcher createDefault(bool try_use_gpu = false);166/** @brief Creates a Stitcher configured in one of the stitching modes.167168@param mode Scenario for stitcher operation. This is usually determined by source of images169to stitch and their transformation. Default parameters will be chosen for operation in given170scenario.171@param try_use_gpu Flag indicating whether GPU should be used whenever it's possible.172@return Stitcher class instance.173*/174static Ptr<Stitcher> create(Mode mode = PANORAMA, bool try_use_gpu = false);175176CV_WRAP double registrationResol() const { return registr_resol_; }177CV_WRAP void setRegistrationResol(double resol_mpx) { registr_resol_ = resol_mpx; }178179CV_WRAP double seamEstimationResol() const { return seam_est_resol_; }180CV_WRAP void setSeamEstimationResol(double resol_mpx) { seam_est_resol_ = resol_mpx; }181182CV_WRAP double compositingResol() const { return compose_resol_; }183CV_WRAP void setCompositingResol(double resol_mpx) { compose_resol_ = resol_mpx; }184185CV_WRAP double panoConfidenceThresh() const { return conf_thresh_; }186CV_WRAP void setPanoConfidenceThresh(double conf_thresh) { conf_thresh_ = conf_thresh; }187188CV_WRAP bool waveCorrection() const { return do_wave_correct_; }189CV_WRAP void setWaveCorrection(bool flag) { do_wave_correct_ = flag; }190191detail::WaveCorrectKind waveCorrectKind() const { return wave_correct_kind_; }192void setWaveCorrectKind(detail::WaveCorrectKind kind) { wave_correct_kind_ = kind; }193194Ptr<detail::FeaturesFinder> featuresFinder() { return features_finder_; }195const Ptr<detail::FeaturesFinder> featuresFinder() const { return features_finder_; }196void setFeaturesFinder(Ptr<detail::FeaturesFinder> features_finder)197{ features_finder_ = features_finder; }198199Ptr<detail::FeaturesMatcher> featuresMatcher() { return features_matcher_; }200const Ptr<detail::FeaturesMatcher> featuresMatcher() const { return features_matcher_; }201void setFeaturesMatcher(Ptr<detail::FeaturesMatcher> features_matcher)202{ features_matcher_ = features_matcher; }203204const cv::UMat& matchingMask() const { return matching_mask_; }205void setMatchingMask(const cv::UMat &mask)206{207CV_Assert(mask.type() == CV_8U && mask.cols == mask.rows);208matching_mask_ = mask.clone();209}210211Ptr<detail::BundleAdjusterBase> bundleAdjuster() { return bundle_adjuster_; }212const Ptr<detail::BundleAdjusterBase> bundleAdjuster() const { return bundle_adjuster_; }213void setBundleAdjuster(Ptr<detail::BundleAdjusterBase> bundle_adjuster)214{ bundle_adjuster_ = bundle_adjuster; }215216/* TODO OpenCV ABI 4.x217Ptr<detail::Estimator> estimator() { return estimator_; }218const Ptr<detail::Estimator> estimator() const { return estimator_; }219void setEstimator(Ptr<detail::Estimator> estimator)220{ estimator_ = estimator; }221*/222223Ptr<WarperCreator> warper() { return warper_; }224const Ptr<WarperCreator> warper() const { return warper_; }225void setWarper(Ptr<WarperCreator> creator) { warper_ = creator; }226227Ptr<detail::ExposureCompensator> exposureCompensator() { return exposure_comp_; }228const Ptr<detail::ExposureCompensator> exposureCompensator() const { return exposure_comp_; }229void setExposureCompensator(Ptr<detail::ExposureCompensator> exposure_comp)230{ exposure_comp_ = exposure_comp; }231232Ptr<detail::SeamFinder> seamFinder() { return seam_finder_; }233const Ptr<detail::SeamFinder> seamFinder() const { return seam_finder_; }234void setSeamFinder(Ptr<detail::SeamFinder> seam_finder) { seam_finder_ = seam_finder; }235236Ptr<detail::Blender> blender() { return blender_; }237const Ptr<detail::Blender> blender() const { return blender_; }238void setBlender(Ptr<detail::Blender> b) { blender_ = b; }239240/** @overload */241CV_WRAP Status estimateTransform(InputArrayOfArrays images);242/** @brief These functions try to match the given images and to estimate rotations of each camera.243244@note Use the functions only if you're aware of the stitching pipeline, otherwise use245Stitcher::stitch.246247@param images Input images.248@param rois Region of interest rectangles.249@return Status code.250*/251Status estimateTransform(InputArrayOfArrays images, const std::vector<std::vector<Rect> > &rois);252253/** @overload */254CV_WRAP Status composePanorama(OutputArray pano);255/** @brief These functions try to compose the given images (or images stored internally from the other function256calls) into the final pano under the assumption that the image transformations were estimated257before.258259@note Use the functions only if you're aware of the stitching pipeline, otherwise use260Stitcher::stitch.261262@param images Input images.263@param pano Final pano.264@return Status code.265*/266Status composePanorama(InputArrayOfArrays images, OutputArray pano);267268/** @overload */269CV_WRAP Status stitch(InputArrayOfArrays images, OutputArray pano);270/** @brief These functions try to stitch the given images.271272@param images Input images.273@param rois Region of interest rectangles.274@param pano Final pano.275@return Status code.276*/277Status stitch(InputArrayOfArrays images, const std::vector<std::vector<Rect> > &rois, OutputArray pano);278279std::vector<int> component() const { return indices_; }280std::vector<detail::CameraParams> cameras() const { return cameras_; }281CV_WRAP double workScale() const { return work_scale_; }282283private:284//Stitcher() {}285286Status matchImages();287Status estimateCameraParams();288289double registr_resol_;290double seam_est_resol_;291double compose_resol_;292double conf_thresh_;293Ptr<detail::FeaturesFinder> features_finder_;294Ptr<detail::FeaturesMatcher> features_matcher_;295cv::UMat matching_mask_;296Ptr<detail::BundleAdjusterBase> bundle_adjuster_;297/* TODO OpenCV ABI 4.x298Ptr<detail::Estimator> estimator_;299*/300bool do_wave_correct_;301detail::WaveCorrectKind wave_correct_kind_;302Ptr<WarperCreator> warper_;303Ptr<detail::ExposureCompensator> exposure_comp_;304Ptr<detail::SeamFinder> seam_finder_;305Ptr<detail::Blender> blender_;306307std::vector<cv::UMat> imgs_;308std::vector<std::vector<cv::Rect> > rois_;309std::vector<cv::Size> full_img_sizes_;310std::vector<detail::ImageFeatures> features_;311std::vector<detail::MatchesInfo> pairwise_matches_;312std::vector<cv::UMat> seam_est_imgs_;313std::vector<int> indices_;314std::vector<detail::CameraParams> cameras_;315double work_scale_;316double seam_scale_;317double seam_work_aspect_;318double warped_image_scale_;319};320321CV_EXPORTS_W Ptr<Stitcher> createStitcher(bool try_use_gpu = false);322CV_EXPORTS_W Ptr<Stitcher> createStitcherScans(bool try_use_gpu = false);323324//! @} stitching325326} // namespace cv327328#endif // OPENCV_STITCHING_STITCHER_HPP329330331