-
Notifications
You must be signed in to change notification settings - Fork 0
/
surfTest.cpp
139 lines (105 loc) · 4.61 KB
/
surfTest.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/legacy/legacy.hpp>
#include <iostream>
using namespace cv;
using namespace std;
//int i=0;
int main( )
{
Mat srcImage = imread("137.jpg");
imshow("original image",srcImage);
Mat grayImage;
cvtColor(srcImage, grayImage, CV_BGR2GRAY);
//------------------detect SURF points and extract descripter ----------------------
int minHessian = 240;
SurfFeatureDetector detector( minHessian );
vector<KeyPoint> keyPoint1, keyPoint2;
detector.detect( grayImage, keyPoint1 );
//
SurfDescriptorExtractor extractor;
Mat descriptors1, descriptors2;
extractor.compute( grayImage, keyPoint1, descriptors1 );
//
BruteForceMatcher< L2<float> > matcher;
vector< DMatch > matches;
//
Mat captureImage, captureImage_gray;//
while(1)
{
double time0 = static_cast<double>(getTickCount( ));//
captureImage = imread("138.jpg");
imshow("image captured",captureImage);
cvtColor(captureImage, captureImage_gray, CV_BGR2GRAY);
detector.detect( captureImage_gray, keyPoint2 );
//
extractor.compute( captureImage_gray, keyPoint2, descriptors2 );
//
matcher.match( descriptors1, descriptors2, matches );
Mat imgMatches;
drawMatches( srcImage, keyPoint1, captureImage_gray, keyPoint2, matches, imgMatches );//
imshow("matched window", imgMatches);
cout << ">帧率= " << getTickFrequency() / (getTickCount() - time0) << endl;
cout << "matches.size()=" << matches.size()<< endl;
cout << "keyPoint2.size()=" << keyPoint2.size()<< endl;
// cout << "matches.distance=" << matches[1].distance<< endl;
//.queryIdx
//vector<int>vecMyHouse;
cv::Point testPoint;
int size = keyPoint1.size(); //获得keyPoint1 已有数据个数
for(int i=0;i<size;i++)
{
//vecMyHouse.push_back(i);
//
cout<<"keyPoint1 第"<<i<<"个 vector数据 "<<keyPoint1[i].pt.y<<"\n"<<endl;
cout << "matches"<<i<<" "<<matches[i].queryIdx<<" "<<matches[i].trainIdx<<" "<<matches[i].distance<< endl;
}
// cout<<"第 %d个 vector数据 ,&i"<<keyPoint1[i].pt.y<<endl;
//testPoint=keyPoint1[i].pt;
// cout<<testPoint.x<<endl;
while(1)
{
if(char(waitKey(1)) == 27) break;
}
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////////
/*
Mat grayImage;
cvtColor(srcImage, grayImage, CV_BGR2GRAY);
double time0 = static_cast<double>(getTickCount( ));//
Mat srcImage1 = imread("51.jpg",1);
Mat srcImage2 = imread("52.jpg",1);
if( !srcImage1.data || !srcImage2.data )
{ printf("¶Áȡ͌ƬŽíÎó£¬ÇëÈ·¶šÄ¿ÂŒÏÂÊÇ·ñÓÐimreadº¯ÊýÖž¶šµÄ͌ƬŽæÔÚ~£¡ \n"); return false; }
//¡Ÿ2¡¿Ê¹ÓÃSURFËã×ÓŒì²â¹ØŒüµã
int minHessian = 400;//SURFËã·šÖеÄhessianãÐÖµ
SurfFeatureDetector detector( minHessian );//¶šÒåÒ»žöSurfFeatureDetector£šSURF£© ÌØÕ÷Œì²âÀà¶ÔÏó
std::vector<KeyPoint> keyPoint1, keyPoints2;//vectorÄ£°åÀ࣬Žæ·ÅÈÎÒâÀàÐ͵Ķ¯Ì¬Êý×é
//¡Ÿ3¡¿µ÷ÓÃdetectº¯ÊýŒì²â³öSURFÌØÕ÷¹ØŒüµã£¬±£ŽæÔÚvectorÈÝÆ÷ÖÐ
detector.detect( srcImage1, keyPoint1 );
detector.detect( srcImage2, keyPoints2 );
//¡Ÿ4¡¿ŒÆËãÃèÊö·û£šÌØÕ÷ÏòÁ¿£©
SurfDescriptorExtractor extractor;
Mat descriptors1, descriptors2;
extractor.compute( srcImage1, keyPoint1, descriptors1 );
extractor.compute( srcImage2, keyPoints2, descriptors2 );
//¡Ÿ5¡¿Ê¹ÓÃBruteForceœøÐÐÆ¥Åä
// ʵÀý»¯Ò»žöÆ¥ÅäÆ÷
BruteForceMatcher< L2<float> > matcher;
std::vector< DMatch > matches;
//Æ¥ÅäÁœ·ùÍŒÖеÄÃèÊö×Ó£šdescriptors£©
matcher.match( descriptors1, descriptors2, matches );
//¡Ÿ6¡¿»æÖÆŽÓÁœžöÍŒÏñÖÐÆ¥Åä³öµÄ¹ØŒüµã
Mat imgMatches;
drawMatches( srcImage1, keyPoint1, srcImage2, keyPoints2, matches, imgMatches );//œøÐлæÖÆ
//¡Ÿ7¡¿ÏÔʟЧ¹ûÍŒ
imshow("Æ¥ÅäÍŒ", imgMatches );
cout << ">Ö¡ÂÊ= " << getTickFrequency() / (getTickCount() - time0) << endl;
waitKey(0);
return 0;
}
*/