opencv on mbed

Dependencies:   mbed

Committer:
joeverbout
Date:
Thu Mar 31 21:16:38 2016 +0000
Revision:
0:ea44dc9ed014
OpenCV on mbed attempt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joeverbout 0:ea44dc9ed014 1 /*M///////////////////////////////////////////////////////////////////////////////////////
joeverbout 0:ea44dc9ed014 2 //
joeverbout 0:ea44dc9ed014 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
joeverbout 0:ea44dc9ed014 4 //
joeverbout 0:ea44dc9ed014 5 // By downloading, copying, installing or using the software you agree to this license.
joeverbout 0:ea44dc9ed014 6 // If you do not agree to this license, do not download, install,
joeverbout 0:ea44dc9ed014 7 // copy or use the software.
joeverbout 0:ea44dc9ed014 8 //
joeverbout 0:ea44dc9ed014 9 //
joeverbout 0:ea44dc9ed014 10 // License Agreement
joeverbout 0:ea44dc9ed014 11 // For Open Source Computer Vision Library
joeverbout 0:ea44dc9ed014 12 //
joeverbout 0:ea44dc9ed014 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
joeverbout 0:ea44dc9ed014 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
joeverbout 0:ea44dc9ed014 15 // Third party copyrights are property of their respective owners.
joeverbout 0:ea44dc9ed014 16 //
joeverbout 0:ea44dc9ed014 17 // Redistribution and use in source and binary forms, with or without modification,
joeverbout 0:ea44dc9ed014 18 // are permitted provided that the following conditions are met:
joeverbout 0:ea44dc9ed014 19 //
joeverbout 0:ea44dc9ed014 20 // * Redistribution's of source code must retain the above copyright notice,
joeverbout 0:ea44dc9ed014 21 // this list of conditions and the following disclaimer.
joeverbout 0:ea44dc9ed014 22 //
joeverbout 0:ea44dc9ed014 23 // * Redistribution's in binary form must reproduce the above copyright notice,
joeverbout 0:ea44dc9ed014 24 // this list of conditions and the following disclaimer in the documentation
joeverbout 0:ea44dc9ed014 25 // and/or other materials provided with the distribution.
joeverbout 0:ea44dc9ed014 26 //
joeverbout 0:ea44dc9ed014 27 // * The name of the copyright holders may not be used to endorse or promote products
joeverbout 0:ea44dc9ed014 28 // derived from this software without specific prior written permission.
joeverbout 0:ea44dc9ed014 29 //
joeverbout 0:ea44dc9ed014 30 // This software is provided by the copyright holders and contributors "as is" and
joeverbout 0:ea44dc9ed014 31 // any express or implied warranties, including, but not limited to, the implied
joeverbout 0:ea44dc9ed014 32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
joeverbout 0:ea44dc9ed014 33 // In no event shall the Intel Corporation or contributors be liable for any direct,
joeverbout 0:ea44dc9ed014 34 // indirect, incidental, special, exemplary, or consequential damages
joeverbout 0:ea44dc9ed014 35 // (including, but not limited to, procurement of substitute goods or services;
joeverbout 0:ea44dc9ed014 36 // loss of use, data, or profits; or business interruption) however caused
joeverbout 0:ea44dc9ed014 37 // and on any theory of liability, whether in contract, strict liability,
joeverbout 0:ea44dc9ed014 38 // or tort (including negligence or otherwise) arising in any way out of
joeverbout 0:ea44dc9ed014 39 // the use of this software, even if advised of the possibility of such damage.
joeverbout 0:ea44dc9ed014 40 //
joeverbout 0:ea44dc9ed014 41 //M*/
joeverbout 0:ea44dc9ed014 42
joeverbout 0:ea44dc9ed014 43 #ifndef __OPENCV_STITCHING_STITCHER_HPP__
joeverbout 0:ea44dc9ed014 44 #define __OPENCV_STITCHING_STITCHER_HPP__
joeverbout 0:ea44dc9ed014 45
joeverbout 0:ea44dc9ed014 46 #include "opencv2/core.hpp"
joeverbout 0:ea44dc9ed014 47 #include "opencv2/features2d.hpp"
joeverbout 0:ea44dc9ed014 48 #include "opencv2/stitching/warpers.hpp"
joeverbout 0:ea44dc9ed014 49 #include "opencv2/stitching/detail/matchers.hpp"
joeverbout 0:ea44dc9ed014 50 #include "opencv2/stitching/detail/motion_estimators.hpp"
joeverbout 0:ea44dc9ed014 51 #include "opencv2/stitching/detail/exposure_compensate.hpp"
joeverbout 0:ea44dc9ed014 52 #include "opencv2/stitching/detail/seam_finders.hpp"
joeverbout 0:ea44dc9ed014 53 #include "opencv2/stitching/detail/blenders.hpp"
joeverbout 0:ea44dc9ed014 54 #include "opencv2/stitching/detail/camera.hpp"
joeverbout 0:ea44dc9ed014 55
joeverbout 0:ea44dc9ed014 56 /**
joeverbout 0:ea44dc9ed014 57 @defgroup stitching Images stitching
joeverbout 0:ea44dc9ed014 58
joeverbout 0:ea44dc9ed014 59 This figure illustrates the stitching module pipeline implemented in the Stitcher class. Using that
joeverbout 0:ea44dc9ed014 60 class it's possible to configure/remove some steps, i.e. adjust the stitching pipeline according to
joeverbout 0:ea44dc9ed014 61 the particular needs. All building blocks from the pipeline are available in the detail namespace,
joeverbout 0:ea44dc9ed014 62 one can combine and use them separately.
joeverbout 0:ea44dc9ed014 63
joeverbout 0:ea44dc9ed014 64 The implemented stitching pipeline is very similar to the one proposed in @cite BL07 .
joeverbout 0:ea44dc9ed014 65
joeverbout 0:ea44dc9ed014 66 ![image](StitchingPipeline.jpg)
joeverbout 0:ea44dc9ed014 67
joeverbout 0:ea44dc9ed014 68 @{
joeverbout 0:ea44dc9ed014 69 @defgroup stitching_match Features Finding and Images Matching
joeverbout 0:ea44dc9ed014 70 @defgroup stitching_rotation Rotation Estimation
joeverbout 0:ea44dc9ed014 71 @defgroup stitching_autocalib Autocalibration
joeverbout 0:ea44dc9ed014 72 @defgroup stitching_warp Images Warping
joeverbout 0:ea44dc9ed014 73 @defgroup stitching_seam Seam Estimation
joeverbout 0:ea44dc9ed014 74 @defgroup stitching_exposure Exposure Compensation
joeverbout 0:ea44dc9ed014 75 @defgroup stitching_blend Image Blenders
joeverbout 0:ea44dc9ed014 76 @}
joeverbout 0:ea44dc9ed014 77 */
joeverbout 0:ea44dc9ed014 78
joeverbout 0:ea44dc9ed014 79 namespace cv {
joeverbout 0:ea44dc9ed014 80
joeverbout 0:ea44dc9ed014 81 //! @addtogroup stitching
joeverbout 0:ea44dc9ed014 82 //! @{
joeverbout 0:ea44dc9ed014 83
joeverbout 0:ea44dc9ed014 84 /** @brief High level image stitcher.
joeverbout 0:ea44dc9ed014 85
joeverbout 0:ea44dc9ed014 86 It's possible to use this class without being aware of the entire stitching pipeline. However, to
joeverbout 0:ea44dc9ed014 87 be able to achieve higher stitching stability and quality of the final images at least being
joeverbout 0:ea44dc9ed014 88 familiar with the theory is recommended.
joeverbout 0:ea44dc9ed014 89
joeverbout 0:ea44dc9ed014 90 @note
joeverbout 0:ea44dc9ed014 91 - A basic example on image stitching can be found at
joeverbout 0:ea44dc9ed014 92 opencv_source_code/samples/cpp/stitching.cpp
joeverbout 0:ea44dc9ed014 93 - A detailed example on image stitching can be found at
joeverbout 0:ea44dc9ed014 94 opencv_source_code/samples/cpp/stitching_detailed.cpp
joeverbout 0:ea44dc9ed014 95 */
joeverbout 0:ea44dc9ed014 96 class CV_EXPORTS_W Stitcher
joeverbout 0:ea44dc9ed014 97 {
joeverbout 0:ea44dc9ed014 98 public:
joeverbout 0:ea44dc9ed014 99 enum { ORIG_RESOL = -1 };
joeverbout 0:ea44dc9ed014 100 enum Status
joeverbout 0:ea44dc9ed014 101 {
joeverbout 0:ea44dc9ed014 102 OK = 0,
joeverbout 0:ea44dc9ed014 103 ERR_NEED_MORE_IMGS = 1,
joeverbout 0:ea44dc9ed014 104 ERR_HOMOGRAPHY_EST_FAIL = 2,
joeverbout 0:ea44dc9ed014 105 ERR_CAMERA_PARAMS_ADJUST_FAIL = 3
joeverbout 0:ea44dc9ed014 106 };
joeverbout 0:ea44dc9ed014 107
joeverbout 0:ea44dc9ed014 108 // Stitcher() {}
joeverbout 0:ea44dc9ed014 109 /** @brief Creates a stitcher with the default parameters.
joeverbout 0:ea44dc9ed014 110
joeverbout 0:ea44dc9ed014 111 @param try_use_gpu Flag indicating whether GPU should be used whenever it's possible.
joeverbout 0:ea44dc9ed014 112 @return Stitcher class instance.
joeverbout 0:ea44dc9ed014 113 */
joeverbout 0:ea44dc9ed014 114 static Stitcher createDefault(bool try_use_gpu = false);
joeverbout 0:ea44dc9ed014 115
joeverbout 0:ea44dc9ed014 116 CV_WRAP double registrationResol() const { return registr_resol_; }
joeverbout 0:ea44dc9ed014 117 CV_WRAP void setRegistrationResol(double resol_mpx) { registr_resol_ = resol_mpx; }
joeverbout 0:ea44dc9ed014 118
joeverbout 0:ea44dc9ed014 119 CV_WRAP double seamEstimationResol() const { return seam_est_resol_; }
joeverbout 0:ea44dc9ed014 120 CV_WRAP void setSeamEstimationResol(double resol_mpx) { seam_est_resol_ = resol_mpx; }
joeverbout 0:ea44dc9ed014 121
joeverbout 0:ea44dc9ed014 122 CV_WRAP double compositingResol() const { return compose_resol_; }
joeverbout 0:ea44dc9ed014 123 CV_WRAP void setCompositingResol(double resol_mpx) { compose_resol_ = resol_mpx; }
joeverbout 0:ea44dc9ed014 124
joeverbout 0:ea44dc9ed014 125 CV_WRAP double panoConfidenceThresh() const { return conf_thresh_; }
joeverbout 0:ea44dc9ed014 126 CV_WRAP void setPanoConfidenceThresh(double conf_thresh) { conf_thresh_ = conf_thresh; }
joeverbout 0:ea44dc9ed014 127
joeverbout 0:ea44dc9ed014 128 CV_WRAP bool waveCorrection() const { return do_wave_correct_; }
joeverbout 0:ea44dc9ed014 129 CV_WRAP void setWaveCorrection(bool flag) { do_wave_correct_ = flag; }
joeverbout 0:ea44dc9ed014 130
joeverbout 0:ea44dc9ed014 131 detail::WaveCorrectKind waveCorrectKind() const { return wave_correct_kind_; }
joeverbout 0:ea44dc9ed014 132 void setWaveCorrectKind(detail::WaveCorrectKind kind) { wave_correct_kind_ = kind; }
joeverbout 0:ea44dc9ed014 133
joeverbout 0:ea44dc9ed014 134 Ptr<detail::FeaturesFinder> featuresFinder() { return features_finder_; }
joeverbout 0:ea44dc9ed014 135 const Ptr<detail::FeaturesFinder> featuresFinder() const { return features_finder_; }
joeverbout 0:ea44dc9ed014 136 void setFeaturesFinder(Ptr<detail::FeaturesFinder> features_finder)
joeverbout 0:ea44dc9ed014 137 { features_finder_ = features_finder; }
joeverbout 0:ea44dc9ed014 138
joeverbout 0:ea44dc9ed014 139 Ptr<detail::FeaturesMatcher> featuresMatcher() { return features_matcher_; }
joeverbout 0:ea44dc9ed014 140 const Ptr<detail::FeaturesMatcher> featuresMatcher() const { return features_matcher_; }
joeverbout 0:ea44dc9ed014 141 void setFeaturesMatcher(Ptr<detail::FeaturesMatcher> features_matcher)
joeverbout 0:ea44dc9ed014 142 { features_matcher_ = features_matcher; }
joeverbout 0:ea44dc9ed014 143
joeverbout 0:ea44dc9ed014 144 const cv::UMat& matchingMask() const { return matching_mask_; }
joeverbout 0:ea44dc9ed014 145 void setMatchingMask(const cv::UMat &mask)
joeverbout 0:ea44dc9ed014 146 {
joeverbout 0:ea44dc9ed014 147 CV_Assert(mask.type() == CV_8U && mask.cols == mask.rows);
joeverbout 0:ea44dc9ed014 148 matching_mask_ = mask.clone();
joeverbout 0:ea44dc9ed014 149 }
joeverbout 0:ea44dc9ed014 150
joeverbout 0:ea44dc9ed014 151 Ptr<detail::BundleAdjusterBase> bundleAdjuster() { return bundle_adjuster_; }
joeverbout 0:ea44dc9ed014 152 const Ptr<detail::BundleAdjusterBase> bundleAdjuster() const { return bundle_adjuster_; }
joeverbout 0:ea44dc9ed014 153 void setBundleAdjuster(Ptr<detail::BundleAdjusterBase> bundle_adjuster)
joeverbout 0:ea44dc9ed014 154 { bundle_adjuster_ = bundle_adjuster; }
joeverbout 0:ea44dc9ed014 155
joeverbout 0:ea44dc9ed014 156 Ptr<WarperCreator> warper() { return warper_; }
joeverbout 0:ea44dc9ed014 157 const Ptr<WarperCreator> warper() const { return warper_; }
joeverbout 0:ea44dc9ed014 158 void setWarper(Ptr<WarperCreator> creator) { warper_ = creator; }
joeverbout 0:ea44dc9ed014 159
joeverbout 0:ea44dc9ed014 160 Ptr<detail::ExposureCompensator> exposureCompensator() { return exposure_comp_; }
joeverbout 0:ea44dc9ed014 161 const Ptr<detail::ExposureCompensator> exposureCompensator() const { return exposure_comp_; }
joeverbout 0:ea44dc9ed014 162 void setExposureCompensator(Ptr<detail::ExposureCompensator> exposure_comp)
joeverbout 0:ea44dc9ed014 163 { exposure_comp_ = exposure_comp; }
joeverbout 0:ea44dc9ed014 164
joeverbout 0:ea44dc9ed014 165 Ptr<detail::SeamFinder> seamFinder() { return seam_finder_; }
joeverbout 0:ea44dc9ed014 166 const Ptr<detail::SeamFinder> seamFinder() const { return seam_finder_; }
joeverbout 0:ea44dc9ed014 167 void setSeamFinder(Ptr<detail::SeamFinder> seam_finder) { seam_finder_ = seam_finder; }
joeverbout 0:ea44dc9ed014 168
joeverbout 0:ea44dc9ed014 169 Ptr<detail::Blender> blender() { return blender_; }
joeverbout 0:ea44dc9ed014 170 const Ptr<detail::Blender> blender() const { return blender_; }
joeverbout 0:ea44dc9ed014 171 void setBlender(Ptr<detail::Blender> b) { blender_ = b; }
joeverbout 0:ea44dc9ed014 172
joeverbout 0:ea44dc9ed014 173 /** @overload */
joeverbout 0:ea44dc9ed014 174 CV_WRAP Status estimateTransform(InputArrayOfArrays images);
joeverbout 0:ea44dc9ed014 175 /** @brief These functions try to match the given images and to estimate rotations of each camera.
joeverbout 0:ea44dc9ed014 176
joeverbout 0:ea44dc9ed014 177 @note Use the functions only if you're aware of the stitching pipeline, otherwise use
joeverbout 0:ea44dc9ed014 178 Stitcher::stitch.
joeverbout 0:ea44dc9ed014 179
joeverbout 0:ea44dc9ed014 180 @param images Input images.
joeverbout 0:ea44dc9ed014 181 @param rois Region of interest rectangles.
joeverbout 0:ea44dc9ed014 182 @return Status code.
joeverbout 0:ea44dc9ed014 183 */
joeverbout 0:ea44dc9ed014 184 Status estimateTransform(InputArrayOfArrays images, const std::vector<std::vector<Rect> > &rois);
joeverbout 0:ea44dc9ed014 185
joeverbout 0:ea44dc9ed014 186 /** @overload */
joeverbout 0:ea44dc9ed014 187 CV_WRAP Status composePanorama(OutputArray pano);
joeverbout 0:ea44dc9ed014 188 /** @brief These functions try to compose the given images (or images stored internally from the other function
joeverbout 0:ea44dc9ed014 189 calls) into the final pano under the assumption that the image transformations were estimated
joeverbout 0:ea44dc9ed014 190 before.
joeverbout 0:ea44dc9ed014 191
joeverbout 0:ea44dc9ed014 192 @note Use the functions only if you're aware of the stitching pipeline, otherwise use
joeverbout 0:ea44dc9ed014 193 Stitcher::stitch.
joeverbout 0:ea44dc9ed014 194
joeverbout 0:ea44dc9ed014 195 @param images Input images.
joeverbout 0:ea44dc9ed014 196 @param pano Final pano.
joeverbout 0:ea44dc9ed014 197 @return Status code.
joeverbout 0:ea44dc9ed014 198 */
joeverbout 0:ea44dc9ed014 199 Status composePanorama(InputArrayOfArrays images, OutputArray pano);
joeverbout 0:ea44dc9ed014 200
joeverbout 0:ea44dc9ed014 201 /** @overload */
joeverbout 0:ea44dc9ed014 202 CV_WRAP Status stitch(InputArrayOfArrays images, OutputArray pano);
joeverbout 0:ea44dc9ed014 203 /** @brief These functions try to stitch the given images.
joeverbout 0:ea44dc9ed014 204
joeverbout 0:ea44dc9ed014 205 @param images Input images.
joeverbout 0:ea44dc9ed014 206 @param rois Region of interest rectangles.
joeverbout 0:ea44dc9ed014 207 @param pano Final pano.
joeverbout 0:ea44dc9ed014 208 @return Status code.
joeverbout 0:ea44dc9ed014 209 */
joeverbout 0:ea44dc9ed014 210 Status stitch(InputArrayOfArrays images, const std::vector<std::vector<Rect> > &rois, OutputArray pano);
joeverbout 0:ea44dc9ed014 211
joeverbout 0:ea44dc9ed014 212 std::vector<int> component() const { return indices_; }
joeverbout 0:ea44dc9ed014 213 std::vector<detail::CameraParams> cameras() const { return cameras_; }
joeverbout 0:ea44dc9ed014 214 CV_WRAP double workScale() const { return work_scale_; }
joeverbout 0:ea44dc9ed014 215
joeverbout 0:ea44dc9ed014 216 private:
joeverbout 0:ea44dc9ed014 217 //Stitcher() {}
joeverbout 0:ea44dc9ed014 218
joeverbout 0:ea44dc9ed014 219 Status matchImages();
joeverbout 0:ea44dc9ed014 220 Status estimateCameraParams();
joeverbout 0:ea44dc9ed014 221
joeverbout 0:ea44dc9ed014 222 double registr_resol_;
joeverbout 0:ea44dc9ed014 223 double seam_est_resol_;
joeverbout 0:ea44dc9ed014 224 double compose_resol_;
joeverbout 0:ea44dc9ed014 225 double conf_thresh_;
joeverbout 0:ea44dc9ed014 226 Ptr<detail::FeaturesFinder> features_finder_;
joeverbout 0:ea44dc9ed014 227 Ptr<detail::FeaturesMatcher> features_matcher_;
joeverbout 0:ea44dc9ed014 228 cv::UMat matching_mask_;
joeverbout 0:ea44dc9ed014 229 Ptr<detail::BundleAdjusterBase> bundle_adjuster_;
joeverbout 0:ea44dc9ed014 230 bool do_wave_correct_;
joeverbout 0:ea44dc9ed014 231 detail::WaveCorrectKind wave_correct_kind_;
joeverbout 0:ea44dc9ed014 232 Ptr<WarperCreator> warper_;
joeverbout 0:ea44dc9ed014 233 Ptr<detail::ExposureCompensator> exposure_comp_;
joeverbout 0:ea44dc9ed014 234 Ptr<detail::SeamFinder> seam_finder_;
joeverbout 0:ea44dc9ed014 235 Ptr<detail::Blender> blender_;
joeverbout 0:ea44dc9ed014 236
joeverbout 0:ea44dc9ed014 237 std::vector<cv::UMat> imgs_;
joeverbout 0:ea44dc9ed014 238 std::vector<std::vector<cv::Rect> > rois_;
joeverbout 0:ea44dc9ed014 239 std::vector<cv::Size> full_img_sizes_;
joeverbout 0:ea44dc9ed014 240 std::vector<detail::ImageFeatures> features_;
joeverbout 0:ea44dc9ed014 241 std::vector<detail::MatchesInfo> pairwise_matches_;
joeverbout 0:ea44dc9ed014 242 std::vector<cv::UMat> seam_est_imgs_;
joeverbout 0:ea44dc9ed014 243 std::vector<int> indices_;
joeverbout 0:ea44dc9ed014 244 std::vector<detail::CameraParams> cameras_;
joeverbout 0:ea44dc9ed014 245 double work_scale_;
joeverbout 0:ea44dc9ed014 246 double seam_scale_;
joeverbout 0:ea44dc9ed014 247 double seam_work_aspect_;
joeverbout 0:ea44dc9ed014 248 double warped_image_scale_;
joeverbout 0:ea44dc9ed014 249 };
joeverbout 0:ea44dc9ed014 250
joeverbout 0:ea44dc9ed014 251 CV_EXPORTS_W Ptr<Stitcher> createStitcher(bool try_use_gpu = false);
joeverbout 0:ea44dc9ed014 252
joeverbout 0:ea44dc9ed014 253 //! @} stitching
joeverbout 0:ea44dc9ed014 254
joeverbout 0:ea44dc9ed014 255 } // namespace cv
joeverbout 0:ea44dc9ed014 256
joeverbout 0:ea44dc9ed014 257 #endif // __OPENCV_STITCHING_STITCHER_HPP__
joeverbout 0:ea44dc9ed014 258