Repository navigation
Expand file tree
/
Copy pathSiftGPU.h
More file actions
executable file
·158 lines (130 loc) · 4.97 KB
/
Copy pathSiftGPU.h
File metadata and controls
executable file
·158 lines (130 loc) · 4.97 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#ifndef GPU_SIFT_H
#define GPU_SIFT_H
#include <vector>
#include "cuda_runtime.h"
#include "GlobalDefines.h"
struct SIFTKeyPoint {
float2 pos;
float scale;
float depth;
};
struct SIFTKeyPointDesc {
unsigned char feature[128];
};
struct SIFTImageGPU {
int* d_keyPointCounter; //single counter value per image (into into global array) 这里我的定义跟原版不同,存储已经提取到的特征点个数
SIFTKeyPoint* d_keyPoints; //array of key points (index into global array)
SIFTKeyPointDesc* d_keyPointDescs; //array of key point descs (index into global array)
};
struct ImagePairMatch {
int* d_numMatches; //single counter value per image, 存储基本参考图像跟索引图像的匹配数目,这只是一个int[1]的数组
float* d_distances; //array of distance (one per match) //
uint2* d_keyPointIndices; //array of index pair (one per match) //存储该参考图像的每个点跟索引图像哪个点最匹配,个数为参考图像的关键点个数
};
//correspondence_idx -> image_Idx_i,j
struct EntryJ {
unsigned int imgIdx_i;
unsigned int imgIdx_j;
float3 pos_i;
float3 pos_j;
__host__ __device__
void setInvalid() {
imgIdx_i = (unsigned int)-1;
imgIdx_j = (unsigned int)-1;
}
__host__ __device__
bool isValid() const {
return imgIdx_i != (unsigned int)-1;
}
};
///////////////////////////////////////////////////////////////////
//clss SiftParam
//description: SIFT parameters SiftParam和GlobalUtil均存储的是sift特征点提取相关信息
////////////////////////////////////////////////////////////////////
class GlobalUtil;
class SiftParam
{
public:
SiftParam();
~SiftParam() {
if (_sigma) { delete[] (_sigma); (_sigma)=NULL; }
}
void ParseSiftParam(); //
float GetLevelSigma(int lev);
float GetInitialSmoothSigma(int octave_min);
std::vector<unsigned int> m_filterWidths;
float* _sigma; //sigma0=1.22627
float _sigma_skip0; // 1.51987
float _sigma_skip1; //0
//sigma of the first level
float _sigma0; //2.01587
float _sigman; //0.5
int _sigma_num; //5
//how many dog_level in an octave
int _dog_level_num; //3
int _level_num; //6
//starting level in an octave
int _level_min; //-1
int _level_max; //4
int _level_ds; //2
//dog threshold
float _dog_threshold; //0.006666667
//edge elimination
float _edge_threshold; //10
};
class SiftPyramid;
////////////////////////////////////////////////////////////////
//class SIftGPU
//description: Interface of SiftGPU lib
////////////////////////////////////////////////////////////////
class SiftGPU:public SiftParam
{
public:
typedef struct SiftKeypoint
{
float x, y, s, o; //x, y, scale, orientation.
}SiftKeypoint;
public:
//constructor, the parameter np is ignored..
SiftGPU();
//destructor
~SiftGPU();
//Initialize OpenGL and SIFT paremeters, and create the shaders accordingly
void InitSiftGPU();
//get the number of SIFT features in current image
int GetFeatureNum();
//get sift keypoints & descriptors (compute into provided d_keypoints, d_descriptors)
unsigned int GetKeyPointsAndDescriptorsCUDA(SIFTImageGPU& siftImage, const float* d_depthData, unsigned int maxNumKeyPoints = (unsigned int)-1);
//get sift keypoints (compute into provided d_keypoints)
void GetKeyPointsCUDA(SiftKeypoint* d_keypoints, float* d_depthData, unsigned int maxNumKeyPoints = (unsigned int)-1);
//get sift descriptors (compute into provided d_descriptors)
void GetDescriptorsCUDA(unsigned char* d_descriptors, unsigned int maxNumKeyPoints = (unsigned int)-1);
//Copy the SIFT result to two vectors
// void CopyFeatureVectorToCPU(SiftKeypoint * keys, float * descriptors);
//parse SiftGPU parameters
void SetParams(unsigned int siftWidth, unsigned int siftHeight, bool enableTiming, unsigned int featureCountThreshold, float siftDepthMin, float siftDepthMax);
int RunSIFT(float* d_colorData, const float* d_depthData);
//set the active pyramid...dropped function
void SetActivePyramid(int index) {}
//allocate pyramid for a given size of image
int AllocatePyramid(int width, int height);
//none of the texture in processing can be larger
//automatic down-sample is used if necessary.
void SetMaxDimension(int sz);
void EvaluateTimings();
private:
//when more than one images are specified
//_current indicates the active one
int _current;
//_initialized indicates if the shaders and OpenGL/SIFT parameters are initialized 标示是否已经初始化
//they are initialized only once for one SiftGPU inistance 只初始化一次
//that is, SIFT parameters will not be changed
int _initialized;
//_image_loaded indicates if the current images are loaded
int _image_loaded;
//the SiftPyramid
SiftPyramid * _pyramid;
//print out the command line options
static void PrintUsage();
};
#endif