当前位置:网站首页>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(一)-基础入门
Rabbitmq (1) - basic introduction
关于update操作并发问题
Essential for back-end programmers: distributed transaction Basics
Recurrence of Apache kylin Remote Code Execution Vulnerability (cve-2020-1956)
2020-11-05
markdown使用
[open source]. Net uses ORM to access Huawei gaussdb database
How to cooperate with people in software development? |Daily anecdotes
佛萨奇forsage以太坊智能合约是什么?以太坊全球滑落是怎么回事
随机推荐
DeepMind 最新论文解读:首次提出离散概率树中的因果推理算法
svg究竟是什么?
Improvement of maintenance mode of laravel8 update
How does Alibaba cloud's maxcompute add (original ODPs) work?
Flink: from introduction to Zhenxiang (6. Flink implements UDF function - realizes more fine-grained control flow)
How does the system response time and throughput change with the increase of concurrency pressure during performance pressure testing
啥是数据库范式
Huawei has an absolute advantage in the 5g mobile phone market, and the market share of Xiaomi is divided by the market survey organization
Android Basics - check box
10个常见的软件架构模式
Interpretation of deepmind's latest paper: the causal reasoning algorithm in discrete probability tree is proposed for the first time
CSP考试须知与各种小技巧
On the software of express delivery cabinet and deposit cabinet under Windows
契约式设计(Dbc)以及其在C语言中的应用
laravel8更新之速率限制改进
Talking about, check the history of which famous computer viruses, 80% of the people do not know!
二叉树的四种遍历方应用
SQL quick query
喜获蚂蚁offer,定级p7,面经分享,万字长文带你走完面试全过程
Learn to record and analyze