Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef __OPENCV_STITCHING_MATCHERS_HPP__
00044 #define __OPENCV_STITCHING_MATCHERS_HPP__
00045
00046 #include "opencv2/core/core.hpp"
00047 #include "opencv2/features2d/features2d.hpp"
00048
00049 #include "opencv2/opencv_modules.hpp"
00050 #ifdef HAVE_OPENCV_GPU
00051 #include "opencv2/gpu/gpu.hpp"
00052 #endif
00053
00054 namespace cv {
00055 namespace detail {
00056
00057 struct CV_EXPORTS ImageFeatures
00058 {
00059 int img_idx;
00060 Size img_size;
00061 std::vector<KeyPoint> keypoints;
00062 Mat descriptors;
00063 };
00064
00065
00066 class CV_EXPORTS FeaturesFinder
00067 {
00068 public:
00069 virtual ~FeaturesFinder() {}
00070 void operator ()(const Mat &image, ImageFeatures &features);
00071 void operator ()(const Mat &image, ImageFeatures &features, const std::vector<cv::Rect> &rois);
00072 virtual void collectGarbage() {}
00073
00074 protected:
00075 virtual void find(const Mat &image, ImageFeatures &features) = 0;
00076 };
00077
00078
00079 class CV_EXPORTS SurfFeaturesFinder : public FeaturesFinder
00080 {
00081 public:
00082 SurfFeaturesFinder(double hess_thresh = 300., int num_octaves = 3, int num_layers = 4,
00083 int num_octaves_descr = 3, int num_layers_descr = 4);
00084
00085 private:
00086 void find(const Mat &image, ImageFeatures &features);
00087
00088 Ptr<FeatureDetector> detector_;
00089 Ptr<DescriptorExtractor> extractor_;
00090 Ptr<Feature2D> surf;
00091 };
00092
00093 class CV_EXPORTS OrbFeaturesFinder : public FeaturesFinder
00094 {
00095 public:
00096 OrbFeaturesFinder(Size _grid_size = Size(3,1), int nfeatures=1500, float scaleFactor=1.3f, int nlevels=5);
00097
00098 private:
00099 void find(const Mat &image, ImageFeatures &features);
00100
00101 Ptr<ORB> orb;
00102 Size grid_size;
00103 };
00104
00105
00106 #ifdef HAVE_OPENCV_GPU
00107 class CV_EXPORTS SurfFeaturesFinderGpu : public FeaturesFinder
00108 {
00109 public:
00110 SurfFeaturesFinderGpu(double hess_thresh = 300., int num_octaves = 3, int num_layers = 4,
00111 int num_octaves_descr = 4, int num_layers_descr = 2);
00112
00113 void collectGarbage();
00114
00115 private:
00116 void find(const Mat &image, ImageFeatures &features);
00117
00118 gpu::GpuMat image_;
00119 gpu::GpuMat gray_image_;
00120 gpu::SURF_GPU surf_;
00121 gpu::GpuMat keypoints_;
00122 gpu::GpuMat descriptors_;
00123 int num_octaves_, num_layers_;
00124 int num_octaves_descr_, num_layers_descr_;
00125 };
00126 #endif
00127
00128
00129 struct CV_EXPORTS MatchesInfo
00130 {
00131 MatchesInfo();
00132 MatchesInfo(const MatchesInfo &other);
00133 const MatchesInfo& operator =(const MatchesInfo &other);
00134
00135 int src_img_idx, dst_img_idx;
00136 std::vector<DMatch> matches;
00137 std::vector<uchar> inliers_mask;
00138 int num_inliers;
00139 Mat H;
00140 double confidence;
00141 };
00142
00143
00144 class CV_EXPORTS FeaturesMatcher
00145 {
00146 public:
00147 virtual ~FeaturesMatcher() {}
00148
00149 void operator ()(const ImageFeatures &features1, const ImageFeatures &features2,
00150 MatchesInfo& matches_info) { match(features1, features2, matches_info); }
00151
00152 void operator ()(const std::vector<ImageFeatures> &features, std::vector<MatchesInfo> &pairwise_matches,
00153 const cv::Mat &mask = cv::Mat());
00154
00155 bool isThreadSafe() const { return is_thread_safe_; }
00156
00157 virtual void collectGarbage() {}
00158
00159 protected:
00160 FeaturesMatcher(bool is_thread_safe = false) : is_thread_safe_(is_thread_safe) {}
00161
00162 virtual void match(const ImageFeatures &features1, const ImageFeatures &features2,
00163 MatchesInfo& matches_info) = 0;
00164
00165 bool is_thread_safe_;
00166 };
00167
00168
00169 class CV_EXPORTS BestOf2NearestMatcher : public FeaturesMatcher
00170 {
00171 public:
00172 BestOf2NearestMatcher(bool try_use_gpu = false, float match_conf = 0.3f, int num_matches_thresh1 = 6,
00173 int num_matches_thresh2 = 6);
00174
00175 void collectGarbage();
00176
00177 protected:
00178 void match(const ImageFeatures &features1, const ImageFeatures &features2, MatchesInfo &matches_info);
00179
00180 int num_matches_thresh1_;
00181 int num_matches_thresh2_;
00182 Ptr<FeaturesMatcher> impl_;
00183 };
00184
00185 }
00186 }
00187
00188 #endif // __OPENCV_STITCHING_MATCHERS_HPP__