资源简介
这段代码是自己写的,会比opencv的简单易懂。提取了特征点后,进行了暴力匹配。暴力匹配的代码也是自己写的,看完后应该对特征点的提取和匹配有个直观的认识。
代码片段和文件信息
//
// Created by 高翔 on 2017/12/19.
// 本程序演示ORB是如何提取、计算和匹配的
//
#include
#include
#include
#include
#include
//#include
//#include
#include
#include
using namespace std;
using namespace cv;
// global variables
string first_file = “1.png“;
string second_file = “2.png“;
typedef vector DescType;
vector good_keypoints1;
vector good_desc;
vector good_keypoints2;
vector good_desc2;
const double pi = 3.1415926; // pi
void computeAngle(const cv::Mat &image vector &keypointsvector &good_points);
typedef vector DescType; // type of descriptor 256 bools
void computeORBDesc(const cv::Mat &image vector &keypoints vector &descvector &out_keypointsvector &out_desc);
void bfMatch(const vector &desc1 const vector &desc2 vector &matches);
int get_distance(const DescType &desc_1 const DescType &desc_2);
void bfMatch(const vector &desc1 const vector &desc2 vector &matches);
int get_distance(const DescType &desc_1 const DescType &desc_2);
vector good_points1;
vector good_points2;
int main(int argc char **argv) {
// load image
cv::Mat first_image = cv::imread(first_file 0); // load grayscale image
cv::Mat second_image = cv::imread(second_file 0); // load grayscale image
// detect FAST keypoints using threshold=40
vector keypoints;
cv::FAST(first_image keypoints 40);
cout << “Fastkeypoints: “ << keypoints.size() << endl;
// compute angle for each keypoint
computeAngle(first_image keypointsgood_points1);//
cout << “keyPoints = “ << keypoints.size() << endl;
cout << “good_Points = “ << good_points1.size() << endl;
vector descriptors1;
computeORBDesc(first_image good_points1 descriptors1good_keypoints1good_desc);
cout << “descriptor1 = “ << good_desc.size() << endl;
vector keypoints2;
cv::FAST(second_image keypoints2 40);
cout << “Fastkeypoints: “ << keypoints2.size() << endl;
// compute angle for each keypoint
computeAngle(second_image keypoints2good_points2);//
cout << “keyPoints = “ << keypoints2.size() << endl;
cout << “good_Points = “ << good_points2.size() << endl;
vector descriptors2;
computeORBDesc(second_image good_points2 descriptors2good_keypoints2good_desc2);
cout << “descriptor2 = “ << good_desc2.size() << endl;
vector matches;
bfMatch(good_desc good_desc2 matches);
cout << “matchrs = “ << matches.size() << endl;
Mat img_mathes;
//for (int i = 0 ; i< matches.size()-1; i++)
//{
// cout << “image1_index = “ << matches[i].queryIdx << endl;
// c
- 上一篇:台湾林智仁开发的libsvm-3.0.1
- 下一篇:成绩管理系统VC++6.0
评论
共有 条评论