#ifndef FEATURE_MATCHER_H #define FEATURE_MATCHER_H #pragma once #include #include #include #ifdef HAVE_OPENCV_XFEATURES2D #include #endif // 特征检测器类型 enum DetectorType { SIFT, SURF, ORB }; // 匹配器类型 enum MatcherType { FLANN, BF }; class FeatureMatcher { public: // 构造函数 FeatureMatcher(DetectorType detectorType, MatcherType matcherType); // 提取特征点和描述符 void extractFeatures(cv::Mat& image, std::vector& keypoints, cv::Mat& descriptors); // 匹配特征点 void matchFeatures(cv::Mat& descriptors1, cv::Mat& descriptors2, std::vector& matches); // K近邻匹配 void matchKnn(cv::Mat& descriptors1, cv::Mat& descriptors2, std::vector>& matches, int k); // 带初始H监督的匹配 void matchFeatures_WithH(std::vector keypoints1, cv::Mat& descriptors1, std::vector keypoints2, cv::Mat& descriptors2, cv::Mat H1, cv::Mat H2, std::vector& matches); // 计算单应性矩阵 cv::Mat computeHomography(std::vector& keypoints1, std::vector& keypoints2, std::vector& matches, double ransacReprojThreshold = 3.0); private: // 初始化特征检测器 void initDetector(); // 初始化匹配器 void initMatcher(); DetectorType detectorType_; // 特征检测器类型 MatcherType matcherType_; // 匹配器类型 cv::Ptr detector_; // 特征检测器 cv::Ptr flannMatcher_; // FLANN匹配器 cv::Ptr bfMatcher_; // 暴力匹配器 }; #endif // FEATURE_MATCHER_H