|
发表于 2016-11-2 22:15:27
|
显示全部楼层
本帖最后由 jennifer-jl 于 2016-11-2 22:20 编辑
- #include<opencv2\core.hpp>
- #include<opencv2\highgui.hpp>
- #include<opencv2/imgproc.hpp>
- #include<opencv2/xfeatures2d.hpp>
- int main()
- {
- cv::Mat image = cv::imread("church01.jpg",0);
- cv::Ptr<cv::xfeatures2d::SURF> surf;
- surf=cv::xfeatures2d::SURF::create(2500.);
- std::vector<cv::KeyPoint> keyPoint;
- surf->detect(image,keyPoint);
- cv::Mat result1;
- cv::drawKeypoints(image, keyPoint, result1,cv::Scalar(255,255,255),cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
- cv::Mat image2 = cv::imread("church03.jpg", 0);
- cv::Ptr<cv::xfeatures2d::SURF> surf3;
- surf3 = cv::xfeatures2d::SURF::create(2500.);
- std::vector<cv::KeyPoint> keyPoint3;
- surf->detect(image2, keyPoint3);
- cv::Mat result3;
- cv::drawKeypoints(image2, keyPoint3, result3, cv::Scalar(255, 255, 255), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
- cv::Mat description;
- surf->compute(image, keyPoint, description);
- cv::Mat description3;
- surf3->compute(image2, keyPoint3, description3);
- cv::Ptr<cv::BFMatcher> matcher =new cv::BFMatcher();
- std::vector<cv::DMatch> matchs;
- matcher->match(description, description3, matchs);
- std::nth_element(matchs.begin(), matchs.begin() + 24, matchs.end());
- matchs.erase(matchs.begin() + 25, matchs.end());
- cv::Mat MatchPicture;
- cv::drawMatches(image, keyPoint, image2, keyPoint3, matchs, MatchPicture);
- return 0;
- }</div>
复制代码
我今天也是研究了一整天,代码终于正确了。下面,我把代码粘贴下来:
//opencv3.1.0
//opencv_contrib
}
|
|