当前位置:网站首页>c++ opencv4.3 sift匹配
c++ opencv4.3 sift匹配
2020-11-08 16:17:00 【spiritboy】
c++ opencv4.3 sift匹配
main.cpp
int main()
{
vector<KeyPoint> keypoints1, keypoints2;
Mat img1,img2,descriptors1, descriptors2;
int numFeatures = 500;//特征点最大个数
int numlines = 50;//前20个匹配最好的点
string path1 = "1.jpg";//图片1
string path2 = "2.jpg";//图片2
getDescriptors(numFeatures, path1, keypoints1, descriptors1, img1);//绘制图片1特征点
getDescriptors(numFeatures, path2, keypoints2, descriptors2, img2);//绘制图片2特征点
drawMatch(img1, keypoints1, descriptors1, img2, keypoints2, descriptors2, numlines);//绘制匹配点
return 0;
}
utils.cpp
#include "utils.h"
// 获取特征点信息
void getDescriptors( int numFeatures, string path, vector<KeyPoint>& keypoints, Mat& descriptors, Mat& img) {
img = imread(path);
Ptr<SIFT> detector = SIFT::create(numFeatures);
if (detector.empty())
throw runtime_error("fail to create detector!");
//detect keypoints;
;
detector->detect(img, keypoints);
cout << "img:" << keypoints.size() << endl;
//compute descriptors for keypoints;
//Sift特征描述提取
cout << "< Computing descriptors for keypoints from images..." << endl;
detector->compute(img, keypoints, descriptors);
cout << endl << "Descriptors Size: " << descriptors.size() << " >" << endl;
cout << endl << "Descriptor's Column: " << descriptors.cols << endl << "Descriptor's Row: " << descriptors.rows << endl;
cout << ">" << endl;
//Draw And Match img1,img2 keypoints
Mat img_keypoints;
drawKeypoints(img, keypoints, img_keypoints, Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
imshow(path, img_keypoints);
}
// 画匹配的特征点对
void drawMatch(Mat img1, vector<KeyPoint> keypoints1, Mat descriptors1, Mat img2, vector<KeyPoint> keypoints2, Mat descriptors2, int numlines) {
//暴力匹配
Ptr<DescriptorMatcher> descriptor_matcher = DescriptorMatcher::create("BruteForce");
vector<DMatch> matches;
descriptor_matcher->match(descriptors1, descriptors2, matches);
//挑选匹配的最好的前20个
nth_element(matches.begin(), matches.begin() + numlines-1, matches.end());
matches.erase(matches.begin() + numlines-1, matches.end());
//绘制匹配点连线
Mat img_matches;
drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches, Scalar::all(-1), Scalar::all(-1), vector< char>(), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
imshow("Mathc", img_matches);
waitKey(0);
}
opencv4.3下载地址
https://download.csdn.net/download/qq_26696715/12459477
有问题添加QQ群:686070107
版权声明
本文为[spiritboy]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/3337401/blog/4708236
边栏推荐
- Travel notes of Suzhou
- 浅谈,盘点历史上有哪些著名的电脑病毒,80%的人都不知道!
- Improvement of rate limit for laravel8 update
- Liteos message queuing
- 刚刚好,才是最理想的状态
- 喝汽水,1瓶汽水1元,2个空瓶可以换一瓶汽水,给20元,可以多少汽水
- The birth of a new integrated memory and computing chip is conducive to the application of artificial intelligence~
- 进入互联网得知道的必备法律法规有哪些?
- 三、函数的参数
- 基于阿里云日志服务快速打造简版业务监控看板
猜你喜欢
Liteos message queuing
我们做了一个医疗版MNIST数据集,发现常见AutoML算法没那么好用
Station B STM32 video learning
Drink soda, a bottle of soda water 1 yuan, two empty bottles can change a bottle of soda, give 20 yuan, how much soda can you
一分钟全面看懂forsage智能合约全球共享以太坊矩阵计划
GopherChina 2020大会
Flink的sink实战之一:初探
Xiaoqingtai officially set foot on the third day of no return
Suitable for C / C + + novice learning some projects, do not give me to miss!
awk实现类sql的join操作
随机推荐
Golang ICMP Protocol detects viable hosts
学习记录并且简单分析
Xiaoqingtai officially set foot on the third day of no return
Essential for back-end programmers: distributed transaction Basics
我用 Python 找出了删除我微信的所有人并将他们自动化删除了
Improvement of rate limit for laravel8 update
Golang system ping program to detect the surviving host (any permission)
佛萨奇forsage以太坊智能合约是什么?以太坊全球滑落是怎么回事
I used Python to find out all the people who deleted my wechat and deleted them automatically
区块链周报:数字货币发展写入十四五规划;拜登邀请MIT数字货币计划高级顾问加入总统过渡团队;委内瑞拉推出国营加密交易所
write文件一个字节后何时发起写磁盘IO
聊聊Go代码覆盖率技术与最佳实践
学习记录并且简单分析
Tips and skills of CSP examination
Chapter 5 programming
后端程序员必备:分布式事务基础篇
喜获蚂蚁offer,定级p7,面经分享,万字长文带你走完面试全过程
On the software of express delivery cabinet and deposit cabinet under Windows
WebGL 水波及焦散(刻蚀)的渲染总结
wanxin finance