void OpenCVHandle::pashSurf(std::string fixjpg, std::string armjpg)
{
Mat image01 = imread(fixjpg, 1);
Mat image02 = imread(armjpg, 1);
//提取特征点
cv::Ptr<cv::xfeatures2d::SURF> surf = cv::xfeatures2d::SURF::create(); // 海塞矩阵阈值,在这里调整精度,值越大点越少,越精准
vector<KeyPoint> keyPoint1, keyPoint2;
surf->detect(image01, keyPoint1);
surf->detect(image02, keyPoint2);
//特征点描述,为下边的特征点匹配做准备
cv::Ptr<cv::xfeatures2d::SURF> surf2 = cv::xfeatures2d::SURF::create();
Mat imageDesc1, imageDesc2;
surf2->compute(image01, keyPoint1, imageDesc1);
surf2->compute(image02, keyPoint2, imageDesc2);
FlannBasedMatcher matcher;
vector<vector<DMatch> > matchePoints;
vector<DMatch> GoodMatchePoints;
vector<Mat> train_desc(1, imageDesc1);
matcher.add(train_desc);
matcher.train();
matcher.knnMatch(imageDesc2, matchePoints, 2);
cout << "total match points: " << matchePoints.size() << endl;
// Lowe's algorithm,获取优秀匹配点
for (int i = 0; i < matchePoints.size(); i++)
{
if (matchePoints[i][0].distance < 0.39 * matchePoints[i][1].distance)
{
GoodMatchePoints.push_back(matchePoints[i][0]);
}
}
Mat first_match;
drawMatches(image02, keyPoint2, image01, keyPoint1, GoodMatchePoints, first_match);
imshow("first_match ", first_match);
waitKey();
}
通过SURF进行特征点提取并进行特征匹配