1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
11 // For Open Source Computer Vision Library
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.
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
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.
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.
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.
43 #ifndef __OPENCV_STITCHING_MATCHERS_HPP__
44 #define __OPENCV_STITCHING_MATCHERS_HPP__
46 #include "opencv2/core.hpp"
47 #include "opencv2/features2d.hpp"
49 #include "opencv2/opencv_modules.hpp"
51 #ifdef HAVE_OPENCV_XFEATURES2D
52 # include "opencv2/xfeatures2d/cuda.hpp"
58 struct CV_EXPORTS ImageFeatures
62 std::vector<KeyPoint> keypoints;
67 class CV_EXPORTS FeaturesFinder
70 virtual ~FeaturesFinder() {}
71 void operator ()(InputArray image, ImageFeatures &features);
72 void operator ()(InputArray image, ImageFeatures &features, const std::vector<cv::Rect> &rois);
73 virtual void collectGarbage() {}
76 virtual void find(InputArray image, ImageFeatures &features) = 0;
80 class CV_EXPORTS SurfFeaturesFinder : public FeaturesFinder
83 SurfFeaturesFinder(double hess_thresh = 300., int num_octaves = 3, int num_layers = 4,
84 int num_octaves_descr = /*4*/3, int num_layers_descr = /*2*/4);
87 void find(InputArray image, ImageFeatures &features);
89 Ptr<FeatureDetector> detector_;
90 Ptr<DescriptorExtractor> extractor_;
94 class CV_EXPORTS OrbFeaturesFinder : public FeaturesFinder
97 OrbFeaturesFinder(Size _grid_size = Size(3,1), int nfeatures=1500, float scaleFactor=1.3f, int nlevels=5);
100 void find(InputArray image, ImageFeatures &features);
107 #ifdef HAVE_OPENCV_XFEATURES2D
108 class CV_EXPORTS SurfFeaturesFinderGpu : public FeaturesFinder
111 SurfFeaturesFinderGpu(double hess_thresh = 300., int num_octaves = 3, int num_layers = 4,
112 int num_octaves_descr = 4, int num_layers_descr = 2);
114 void collectGarbage();
117 void find(InputArray image, ImageFeatures &features);
120 cuda::GpuMat gray_image_;
121 cuda::SURF_CUDA surf_;
122 cuda::GpuMat keypoints_;
123 cuda::GpuMat descriptors_;
124 int num_octaves_, num_layers_;
125 int num_octaves_descr_, num_layers_descr_;
130 struct CV_EXPORTS MatchesInfo
133 MatchesInfo(const MatchesInfo &other);
134 const MatchesInfo& operator =(const MatchesInfo &other);
136 int src_img_idx, dst_img_idx; // Images indices (optional)
137 std::vector<DMatch> matches;
138 std::vector<uchar> inliers_mask; // Geometrically consistent matches mask
139 int num_inliers; // Number of geometrically consistent matches
140 Mat H; // Estimated homography
141 double confidence; // Confidence two images are from the same panorama
145 class CV_EXPORTS FeaturesMatcher
148 virtual ~FeaturesMatcher() {}
150 void operator ()(const ImageFeatures &features1, const ImageFeatures &features2,
151 MatchesInfo& matches_info) { match(features1, features2, matches_info); }
153 void operator ()(const std::vector<ImageFeatures> &features, std::vector<MatchesInfo> &pairwise_matches,
154 const cv::UMat &mask = cv::UMat());
156 bool isThreadSafe() const { return is_thread_safe_; }
158 virtual void collectGarbage() {}
161 FeaturesMatcher(bool is_thread_safe = false) : is_thread_safe_(is_thread_safe) {}
163 virtual void match(const ImageFeatures &features1, const ImageFeatures &features2,
164 MatchesInfo& matches_info) = 0;
166 bool is_thread_safe_;
170 class CV_EXPORTS BestOf2NearestMatcher : public FeaturesMatcher
173 BestOf2NearestMatcher(bool try_use_gpu = false, float match_conf = 0.3f, int num_matches_thresh1 = 6,
174 int num_matches_thresh2 = 6);
176 void collectGarbage();
179 void match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo &matches_info);
181 int num_matches_thresh1_;
182 int num_matches_thresh2_;
183 Ptr<FeaturesMatcher> impl_;
186 class CV_EXPORTS BestOf2NearestRangeMatcher : public BestOf2NearestMatcher
189 BestOf2NearestRangeMatcher(int range_width = 5, bool try_use_gpu = false, float match_conf = 0.3f,
190 int num_matches_thresh1 = 6, int num_matches_thresh2 = 6);
192 void operator ()(const std::vector<ImageFeatures> &features, std::vector<MatchesInfo> &pairwise_matches,
193 const cv::UMat &mask = cv::UMat());
200 } // namespace detail
203 #endif // __OPENCV_STITCHING_MATCHERS_HPP__