-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
54 lines (42 loc) · 1.32 KB
/
main.cpp
File metadata and controls
54 lines (42 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include "sift/sift.h"
#include <opencv2/opencv.hpp>
#include <opencv2/xfeatures2d.hpp>
using namespace cv; //包含cv命名空间
using namespace std;
#define TIME 0
int main()
{
#if TIME
double t, tf = getTickFrequency();
t = (double)getTickCount();
#endif
//Create SIFT class pointer
Ptr<Feature2D> f2d = xfeatures2d::q::SIFT::create();
//读入图片
Mat img_1 = imread("../data/img2.ppm");
Mat img_2 = imread("../data/img3.ppm");
//Detect the keypoints
vector<KeyPoint> keypoints_1, keypoints_2;
f2d->detect(img_1, keypoints_1);
f2d->detect(img_2, keypoints_2);
//Calculate descriptors (feature vectors)
Mat descriptors_1, descriptors_2;
f2d->compute(img_1, keypoints_1, descriptors_1);
f2d->compute(img_2, keypoints_2, descriptors_2);
//Matching descriptor vector using BFMatcher
BFMatcher matcher;
vector<DMatch> matches;
matcher.match(descriptors_1, descriptors_2, matches);
//绘制匹配出的关键点
Mat img_matches;
drawMatches(img_1, keypoints_1, img_2, keypoints_2, matches, img_matches);
cvNamedWindow("match",CV_WINDOW_NORMAL);
imshow("match", img_matches);
//等待任意按键按下
#if TIME
t = (double)getTickCount() - t;
printf("time cost: %g\n", t*1000./tf);
#endif
waitKey(0);
}