当前位置:网站首页>C + + opencv4.3 sift matching
C + + opencv4.3 sift matching
2020-11-08 16:17:00 【Spiritual】
c++ opencv4.3 sift matching
main.cpp
int main()
{
vector<KeyPoint> keypoints1, keypoints2;
Mat img1,img2,descriptors1, descriptors2;
int numFeatures = 500;// The maximum number of feature points
int numlines = 50;// front 20 The best match
string path1 = "1.jpg";// picture 1
string path2 = "2.jpg";// picture 2
getDescriptors(numFeatures, path1, keypoints1, descriptors1, img1);// Drawing pictures 1 Characteristic point
getDescriptors(numFeatures, path2, keypoints2, descriptors2, img2);// Drawing pictures 2 Characteristic point
drawMatch(img1, keypoints1, descriptors1, img2, keypoints2, descriptors2, numlines);// Draw match points
return 0;
}
utils.cpp
#include "utils.h"
// Get feature point information
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 Feature description extraction
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);
}
// Draw matching feature points to
void drawMatch(Mat img1, vector<KeyPoint> keypoints1, Mat descriptors1, Mat img2, vector<KeyPoint> keypoints2, Mat descriptors2, int numlines) {
// Violent match
Ptr<DescriptorMatcher> descriptor_matcher = DescriptorMatcher::create("BruteForce");
vector<DMatch> matches;
descriptor_matcher->match(descriptors1, descriptors2, matches);
// Pick the best match before 20 individual
nth_element(matches.begin(), matches.begin() + numlines-1, matches.end());
matches.erase(matches.begin() + numlines-1, matches.end());
// Draw a match point line
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 Download address
https://download.csdn.net/download/qq_26696715/12459477
There is a problem adding QQ Group :686070107
版权声明
本文为[Spiritual]所创,转载请带上原文链接,感谢
边栏推荐
- Tips and skills of CSP examination
- Arduino ide build esp8266 development environment, slow file download solution | esp-01 make WiFi switch tutorial, transform dormitory lights
- Elasticsearch 学习一(基础入门).
- Alibaba cloud accelerates its growth and further consolidates its leading edge
- 习题五
- Arduino IDE搭建ESP8266开发环境,文件下载过慢解决方法 | ESP-01制作WiFi开关教程,改造宿舍灯
- Liteos message queuing actual combat
- 金融领域首个开源中文BERT预训练模型,熵简科技推出FinBERT 1.0
- Elasticsearch learning one (basic introduction)
- TypeScript(1-2-2)
猜你喜欢
随机推荐
C + + things: from rice cookers to rockets, C + + is everywhere
What are the necessary laws and regulations to know when entering the Internet?
Examples of unconventional aggregation
Your random IO hard disk
WebGL 水波及焦散(刻蚀)的渲染总结
laravel8更新之速率限制改进
非常规聚合问题举例
第五章编程题
Elasticsearch learning one (basic introduction)
API生命周期的5个阶段
金融领域首个开源中文BERT预训练模型,熵简科技推出FinBERT 1.0
LeanCloud 十月变化
jsliang 求职系列 - 07 - Promise
vim-配置教程+源码
SQL quick query
The network adapter could not establish the connection
三、函数的参数
习题五
Golang ICMP协议探测存活主机
学习记录并且简单分析