Repository navigation
Expand file tree
/
Copy pathSiftPyramid.h
More file actions
executable file
·136 lines (115 loc) · 4.53 KB
/
Copy pathSiftPyramid.h
File metadata and controls
executable file
·136 lines (115 loc) · 4.53 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
#ifndef _SIFT_PYRAMID_H
#define _SIFT_PYRAMID_H
#include <cuda_runtime.h>
class CuTexImage;
class SiftParam;
class GlobalUtil;
class CUDATimer;
/////////////////////////////////////////////////////////////////////////////
//class SiftPyramid
//description: virutal class of SIFT data pyramid
// provides functions for SiftPU to run steps of GPU SIFT
/////////////////////////////////////////////////////////////////////////////
#define NO_DUPLICATE_DOWNLOAD
class SiftPyramid : public GlobalUtil
{
public:
enum{
DATA_GAUSSIAN = 0,
DATA_DOG = 1,
DATA_KEYPOINT = 2,
DATA_GRAD = 3,
DATA_ROT = 4,
DATA_NUM = 5
};
enum{
SIFT_SKIP_FILTERING = 0x01,
SIFT_SKIP_DETECTION = 0x02,
SIFT_SKIP_ORIENTATION = 0x04,
SIFT_RECT_DESCRIPTION = 0x08
};
SiftPyramid(SiftParam&sp);
~SiftPyramid();;
//shared by all implementations
void RunSIFT(float* d_colorData, const float* d_depthData);
void BuildPyramid(float* d_data);
void DestroyPerLevelData();
void DestroyPyramidData();
void GetKeyPointsCUDA(float4* d_keypoints, const float* d_depthData, unsigned int maxNumKeyPoints); //TODO limit in compute instead?
void GetFeatureVectorCUDA(unsigned char* d_descriptor, unsigned int maxNumKeyPoints);
//void CopyFeaturesToCPU(float*keys, float *descriptors);
//implementation-dependent functions
void GetFeatureDescriptors();
void ReshapeFeatureList();
void ResizePyramid(int w, int h);
void InitPyramid(int w, int h);
void DetectKeypoints(const float* d_depthData);
void ComputeGradient();
void GetFeatureOrientations();
////////////////////////////////
int IsUsingRectDescription() { return 0; }
static int GetRequiredOctaveNum(int inputsz);
///inline functions, shared by all implementations
inline int GetFeatureNum(){ return _featureNum; }
inline const int* GetLevelFeatureNum(){ return _levelFeatureNum; }
inline unsigned int getPyramidWidth() const { return _pyramid_width; }
inline unsigned int getPyramidHeight() const { return _pyramid_height; }
inline bool isAllocated() const { return _allocated; }
inline void setOctaveMin(int d) { _octave_min = d; }
//////////
void CopyGradientTex();
void FitPyramid(int w, int h);
int ResizeFeatureStorage();
//void SetLevelFeatureNum(int idx, int fcount);
void SetLevelFinalFeatureNum(int idx, int fcount);
CuTexImage* GetBaseLevel(int octave, int dataName = DATA_GAUSSIAN);
//////////////////////////
//static int CheckCudaDevice(int device);
static int TruncateWidth(int w) { return w & 0xfffffffc; }
void EvaluateTimings();
void SaveTexImage(CuTexImage* TexImage, std::string path);
void LoadTexImage(CuTexImage* TexImage, std::string path);
void SaveImage(const void* d_image, int size, std::string path);
protected:
inline void PrepareBuffer();
inline void LimitFeatureCount(int have_keylist = 0);
void CreateGlobalKeyPointList(float4* d_keypoints, const float* d_depthData, unsigned int maxNumKeyPoints);
SiftParam& param;
int* _levelFeatureNum;
int _featureNum;
//image size related
//first octave
int _octave_min;
//how many octaves
int _octave_num;
//pyramid storage
int _pyramid_octave_num;
int _pyramid_octave_first;
int _pyramid_width;
int _pyramid_height;
bool _allocated;
// data
CuTexImage* _inputTex;
CuTexImage* _allPyramid;
CuTexImage* _featureTexRaw; //raw feature points; may contain zero to two orientations
CuTexImage* _featureTexFinal; //final feature points; only a single orientation per key point
CuTexImage* _orientationTex;
int* d_featureCount; // per dog per level
float* d_outDescriptorList;
CUDATimer* _timer;
};
#define SIFTGPU_ENABLE_REVERSE_ORDER
#ifdef SIFTGPU_ENABLE_REVERSE_ORDER
#define FIRST_OCTAVE(R) (R? _octave_num - 1 : 0)
#define NOT_LAST_OCTAVE(i, R) (R? (i >= 0) : (i < _octave_num))
#define GOTO_NEXT_OCTAVE(i, R) (R? (--i) : (++i))
#define FIRST_LEVEL(R) (R? param._dog_level_num - 1 : 0)
#define GOTO_NEXT_LEVEL(j, R) (R? (--j) : (++j))
#define NOT_LAST_LEVEL(j, R) (R? (j >= 0) : (j < param._dog_level_num))
#define FOR_EACH_OCTAVE(i, R) for(int i = FIRST_OCTAVE(R); NOT_LAST_OCTAVE(i, R); GOTO_NEXT_OCTAVE(i, R))
#define FOR_EACH_LEVEL(j, R) for(int j = FIRST_LEVEL(R); NOT_LAST_LEVEL(j, R); GOTO_NEXT_LEVEL(j, R))
#else
#define FOR_EACH_OCTAVE(i, R) for(int i = 0; i < _octave_num; ++i)
#define FOR_EACH_LEVEL(j, R) for(int j = 0; j < param._dog_level_num; ++j)
#endif
#endif