当前位置:网站首页>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
边栏推荐
- Workers, workers soul, draw lifelong members, become a person!
- DeepMind 最新论文解读:首次提出离散概率树中的因果推理算法
- jsliang 求职系列 - 07 - Promise
- Travel notes of Suzhou
- 漫画:寻找股票买入卖出的最佳时机(整合版)
- Windows下快递投递柜、寄存柜的软件初探
- TypeScript(1-2-2)
- AI周报:允许“员工自愿降薪”;公司回应:员工内心高兴满意;虎牙HR将员工抬出公司;瑞典禁用华为中兴5G设备
- 小青台正式踏上不归路的第3天
- . net large data concurrency solution
猜你喜欢
B站stm32视频学习
DeepMind 最新论文解读:首次提出离散概率树中的因果推理算法
Application of four ergodic square of binary tree
The birth of a new integrated memory and computing chip is conducive to the application of artificial intelligence~
阿里云视频云技术专家 LVS 演讲全文:《“云端一体”的智能媒体生产制作演进之路》
Learn to record and analyze
API生命周期的5个阶段
Summary of template engine
Flink的sink实战之一:初探
Builder pattern
随机推荐
On the concurrency of update operation
Welcome to offer, grade P7, face-to-face sharing, 10000 words long text to take you through the interview process
Liteos message queuing actual combat
Elasticsearch 学习一(基础入门).
Solution of DEV-C + + unable to debug in Windows Environment
Summary of rendering of water wave and caustics (etching) in webgl
我用 Python 找出了删除我微信的所有人并将他们自动化删除了
Golang ICMP Protocol detects viable hosts
[开源] .Net 使用 ORM 访问 华为GaussDB数据库
WebGL 水波及焦散(刻蚀)的渲染总结
Arduino ide build esp8266 development environment, slow file download solution | esp-01 make WiFi switch tutorial, transform dormitory lights
How to solve the conflict when JD landed on Devops platform?
基于阿里云日志服务快速打造简版业务监控看板
Examples of unconventional aggregation
Arduino IDE搭建ESP8266开发环境,文件下载过慢解决方法 | ESP-01制作WiFi开关教程,改造宿舍灯
vim-配置教程+源码
Station B STM32 video learning
阿里云的MaxCompute数加(原ODPS)用的怎样?
Essential for back-end programmers: distributed transaction Basics
Gopherchina 2020 Conference