opencv2中SurfFeatureDetector、SurfDescriptorExtractor、BruteForceMatcher在opencv3中發生了改變。具體如何完成特征點匹配呢?示例如下:
//尋找關鍵點
int minHessian = 700;
Ptr<SURF>detector = SURF::create(minHessian);
detector->detect( srcImage1, keyPoint1 );
detector->detect( srcImage2, keyPoints2 );
//繪制特征關鍵點
Mat img_keypoints_1; Mat img_keypoints_2;
drawKeypoints( srcImage1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
drawKeypoints( srcImage2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
//顯示效果圖
imshow("特征點檢測效果圖1", img_keypoints_1 );
imshow("特征點檢測效果圖2", img_keypoints_2 );
//計算特征向量
Ptr<SURF>extractor = SURF::create();
Mat descriptors1, descriptors2;
extractor->compute( srcImage1, keyPoint1, descriptors1 );
extractor->compute( srcImage2, keyPoints2, descriptors2 );
//使用BruteForce進行匹配
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce");
std::vector< DMatch > matches;
matcher->match( descriptors1, descriptors2, matches );
//繪制從兩個圖像中匹配出的關鍵點
Mat imgMatches;
drawMatches( srcImage1, keyPoint1, srcImage2, keyPoints2, matches, imgMatches );//進行繪制
//顯示
imshow("匹配圖", imgMatches );
3.x的特征檢測:
- 算法:SURF,SIFT,BRIEF,FREAK
- 類:cv::xfeatures2d::SURF
- cv::xfeatures2d::SIFT
- cv::xfeatures::BriefDescriptorExtractor
- cv::xfeatures2d::FREAK
- cv::xfeatures2d::StarDetector
- 需要進行以下幾步
- 加入opencv_contrib
- 包含opencv2/xfeatures2d.hpp
- using namepsace cv::xfeatures2d
- 使用create(),detect(),compute(),detectAndCompute()