1、特征点检测
角点:
传统harris角点检测//有时间加上
改进harris角点检测
不知道opencv下为什么那么慢,matlab下harris检测挺快的
//以下两句不重复
vector<KeyPoint> keypoints_1, keypoints_2;
Mat descriptors_1, descriptors_2;
//
GoodFeaturesToTrackDetector Detector(200); //最大点数,值越大,点越多
//角点最大数目;// 质量等级,这里是0.01*max(min(e1,e2)),e1,e2是harris矩阵的特征值;// 两个角点之间的距离容忍度;
Detector.detect(image, keypoints_1);
Detector.detect(image2, keypoints_2);
Fast快速检测
fast很快,角点特征还算可以
FastFeatureDetector fast(100, true);
fast.detect(image, keypoints_1);
fast.detect(image2, keypoints_2);
std::cout << "keypint_size" << keypoints_1.size() << " " << keypoints_2.size() << endl;
surf检测特征点并提取特征值
SurfFeatureDetector surf(5000);
surf.detect(image, keypoints_1);
surf.detect(image2, keypoints_2);
2、计算描述子
sift、surf、brief等等,这里以sift为例,可以随意使用,但感觉sift效果较好
SiftDescriptorExtractor extractor;
extractor.compute(image, keypoints_1, descriptors_1);
extractor.compute(image2, keypoints_2, descriptors_2);
orb算法=fast 检测+ BriefDescriptorExtractor 描述
ORB orb;
orb(image, Mat(), keypoints_1, descriptors_1);
orb(image2, Mat(), keypoints_2, descriptors_2);
3、匹配 bf matcher
//A-KNN
BruteForceMatcher <L2<float>> matcher;
std::vector< DMatch > matches;
const float minRatio = 1.f / 1.5f;
const int k = 2;
vector<vector<DMatch>> knnMatches;
matcher.knnMatch(descriptors_1, descriptors_2, knnMatches, k);
for (size_t i = 0; i < knnMatches.size(); i++) {
const DMatch& bestMatch = knnMatches[i][0];
const DMatch& betterMatch = knnMatches[i][1];
float distanceRatio = bestMatch.distance / betterMatch.distance;
if (distanceRatio < minRatio)
matches.push_back(bestMatch);
}
std::cout << "match_size" << matches.size() << endl;
4、显示
//-- Show detected matches
Mat img_matches;//把图像点转换到该mat
drawMatches(image, keypoints_1, image2, keypoints_2, matches, img_matches);
imshow("Matches", img_matches);
推荐文章
https://blog.csdn.net/Jack_Sarah/article/details/79548334
https://blog.csdn.net/medal003/article/details/45022331
https://blog.csdn.net/holybin/article/details/48776949