当前位置:网站首页>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
边栏推荐
- Rabbitmq (1) - basic introduction
- . net large data concurrency solution
- 漫画:寻找股票买入卖出的最佳时机(整合版)
- 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
- Dev-c++在windows环境下无法debug(调试)的解决方案
- 软件开发中如何与人协作? | 每日趣闻
- Learn to record and analyze
- 关于update操作并发问题
- 佛萨奇forsage以太坊智能合约是什么?以太坊全球滑落是怎么回事
- What are the necessary laws and regulations to know when entering the Internet?
猜你喜欢
Interpretation of deepmind's latest paper: the causal reasoning algorithm in discrete probability tree is proposed for the first time
B站stm32视频学习
Eight ways to optimize if else code
大龄程序员没有出路吗?
Recurrence of Apache kylin Remote Code Execution Vulnerability (cve-2020-1956)
阿里云加速增长,进一步巩固领先优势
[open source]. Net uses ORM to access Huawei gaussdb database
Learn to record and analyze
一分钟全面看懂forsage智能合约全球共享以太坊矩阵计划
学习记录并且简单分析
随机推荐
华为在5G手机市场占据绝对优势,市调机构对小米的市占出现分歧
Golang ICMP Protocol detects viable hosts
C + + things: from rice cookers to rockets, C + + is everywhere
谷歌开源能翻译101种语言的AI模型,只比Facebook多一种
Blockchain weekly: the development of digital currency is written into the 14th five year plan; Biden invited senior adviser of MIT digital currency program to join the presidential transition team; V
Talking about, check the history of which famous computer viruses, 80% of the people do not know!
Builder pattern
苏州游记
阿里云的MaxCompute数加(原ODPS)用的怎样?
模板引擎的整理归纳
LeanCloud 十月变化
Tencent, which is good at to C, how to take advantage of Tencent's cloud market share in these industries?
机械硬盘随机IO慢的超乎你的想象
啥是数据库范式
Examples of unconventional aggregation
jsliang 求职系列 - 07 - Promise
How to solve the conflict when JD landed on Devops platform?
打工人,打工魂,抽终身会员,成为人上人!
这几个C++的坑,一旦踩中了,加班是肯定避免不了了!
markdown使用