当前位置:网站首页>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
边栏推荐
- 三、函数的参数
- The first open source Chinese Bert pre training model in the financial field
- What are the necessary laws and regulations to know when entering the Internet?
- Recurrence of Apache kylin Remote Code Execution Vulnerability (cve-2020-1956)
- 进入互联网得知道的必备法律法规有哪些?
- 关于update操作并发问题
- 模板引擎的整理归纳
- 浅谈,盘点历史上有哪些著名的电脑病毒,80%的人都不知道!
- Build simple business monitoring Kanban based on Alibaba cloud log service
- 关于adb连接手机offline的问题解决
猜你喜欢

Flink: from introduction to Zhenxiang (3. Reading data from collection and file)

三、函数的参数

Development of uni app imitating wechat app

数据库连接报错之IO异常(The Network Adapter could not establish the connection)

Huawei has an absolute advantage in the 5g mobile phone market, and the market share of Xiaomi is divided by the market survey organization

laravel8更新之维护模式改进

新型存算一体芯片诞生,利好人工智能应用~

Arduino IDE搭建ESP8266开发环境,文件下载过慢解决方法 | ESP-01制作WiFi开关教程,改造宿舍灯

Talking about, check the history of which famous computer viruses, 80% of the people do not know!

第五章编程题
随机推荐
漫画:寻找股票买入卖出的最佳时机(整合版)
Flink from introduction to Zhenxiang (10. Sink data output elasticsearch)
Essential for back-end programmers: distributed transaction Basics
vim-配置教程+源码
Chapter 5 programming
构建者模式(Builder pattern)
Welcome to offer, grade P7, face-to-face sharing, 10000 words long text to take you through the interview process
阿里云的MaxCompute数加(原ODPS)用的怎样?
Golang ICMP Protocol detects viable hosts
“他,程序猿,35岁,被劝退”:不要只懂代码,会说话,胜过10倍默默努力
关于adb连接手机offline的问题解决
Restfulapi learning notes -- father son resources (4)
LeanCloud 十月变化
Flink from introduction to Zhenxiang (7. Sink data output file)
Alibaba cloud accelerates its growth and further consolidates its leading edge
Liteos message queuing actual combat
新型存算一体芯片诞生,利好人工智能应用~
这几个C++的坑,一旦踩中了,加班是肯定避免不了了!
浅谈OpenGL之DSA
What are the necessary laws and regulations to know when entering the Internet?