opencv DMatch
来源:互联网 发布:强化改版数据 编辑:程序博客网 时间:2024/05/22 12:01
特征的匹配大致可以分为3个步骤:
- 特征的提取
- 计算特征向量
- 特征匹配
对于3个步骤,在OpenCV2中都进行了封装。所有的特征提取方法都实现FeatureDetector接口,DescriptorExtractor接口则封装了对特征向量(特征描述符)的提取,而所有特征向量的匹配都继承了DescriptorMatcher接口。
简单的特征匹配
int main(){ const string imgName1 = "x://image//01.jpg"; const string imgName2 = "x://image//02.jpg"; Mat img1 = imread(imgName1); Mat img2 = imread(imgName2); if (!img1.data || !img2.data) return -1; //step1: Detect the keypoints using SURF Detector int minHessian = 400; SurfFeatureDetector detector(minHessian); vector<KeyPoint> keypoints1, keypoints2; detector.detect(img1, keypoints1); detector.detect(img2, keypoints2); //step2: Calculate descriptors (feature vectors) SurfDescriptorExtractor extractor; Mat descriptors1, descriptors2; extractor.compute(img1, keypoints1, descriptors1); extractor.compute(img2, keypoints2, descriptors2); //step3:Matching descriptor vectors with a brute force matcher BFMatcher matcher(NORM_L2); vector<DMatch> matches; matcher.match(descriptors1, descriptors2,matches); //Draw matches Mat imgMatches; drawMatches(img1, keypoints1, img2, keypoints2, matches, imgMatches); namedWindow("Matches"); imshow("Matches", imgMatches); waitKey(); return 0;}
- 实例化了一个特征提取器SurfFeatureDetector,其构造函数参数(minHessian)用来平衡提取到的特征点的数量和特征提取的稳定性的,对于不同的特征提取器改参数具有不同的含义和取值范围。
- 对得到的特征点提取特征向量(特征描述符)
- 匹配,上面代码使用了暴力匹配的方法,最后的匹配结果保存在vector<DMatch>中。
DMatch用来保存匹配后的结果
struct DMatch{ //三个构造函数 DMatch() : queryIdx(-1), trainIdx(-1), imgIdx(-1), distance(std::numeric_limits<float>::max()) {} DMatch(int _queryIdx, int _trainIdx, float _distance) : queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(-1), distance(_distance) {} DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance) : queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(_imgIdx), distance(_distance) {} int queryIdx; //此匹配对应的查询图像的特征描述子索引 int trainIdx; //此匹配对应的训练(模板)图像的特征描述子索引 int imgIdx; //训练图像的索引(若有多个) float distance; //两个特征向量之间的欧氏距离,越小表明匹配度越高。 bool operator < (const DMatch &m) const;};
然后使用drawMatches方法可以匹配后的结构保存为Mat
0 0
- opencv DMatch
- Opencv中的DMatch
- opencv中的KeyPoint和DMatch
- 【杂谈opencv】OpenCV中的KeyPoint与DMatch
- opencv 的 DMatch, keypoint等资料,供项目查阅
- OpenCV特征匹配相关结构(KeyPoint&DMatch)
- OpenCV特征匹配相关结构(KeyPoint&DMatch类型简介)
- openCV中的KeyPoints、DMatch、以及drawMatches函数(sift算法会用到的)
- Opencv Surf算子中keyPoints,描述子Mat矩阵,配对向量DMatch里都包含了哪些好玩的东东?
- KeyPoint&DMatch类型简介
- 关于第7讲3D-2D实践程序中DMatch m:matches的理解
- opencv
- openCV
- openCV
- Opencv
- opencv
- opencv
- opencv
- 关于validate验证框架的学习
- 周内最后一天
- 数组去重的三种方法
- android开发之旅(四)
- Tomcat的8080官方端口号被占用
- opencv DMatch
- HDU 1518 Square
- Android开发---MediaPlayer简单音乐播放器
- 关于LocalBroadcastManager的介绍和优势
- js 复制内容到剪切板
- 背景建模技术(二):BgsLibrary的框架、背景建模的37种算法性能分析、背景建模技术的挑战
- js简单正则 总结
- jsp 数据分页导出下载 显示进度条
- jeecg——修改界面风格