53 if(_existing_keypoints & SIFT_SKIP_FILTERING)
61 _timing[0] = GetElapsedTime();
65 if(_existing_keypoints)
69 if(!(_existing_keypoints & SIFT_SKIP_FILTERING)) ComputeGradient();
70 GenerateFeatureListTex();
72 _timing[2] = GetElapsedTime();
79 _timing[1] = GetElapsedTime();
84 GenerateFeatureList();
90 GenerateFeatureListCPU();
94 _timing[2] = GetElapsedTime();
99 if(_existing_keypoints& SIFT_SKIP_ORIENTATION)
106 GetFeatureOrientations();
108 _timing[3] = GetElapsedTime();
114 ReshapeFeatureListCPU();
115 LimitFeatureCount(1);
117 _timing[4] = GetElapsedTime();
122 GetSimplifiedOrientation();
124 _timing[3] = GetElapsedTime();
129 if(_existing_keypoints & SIFT_SKIP_ORIENTATION)
135 #ifdef NO_DUPLICATE_DOWNLOAD
140 _timing[5] = GetElapsedTime();
149 GetFeatureDescriptors();
151 _timing[6] = GetElapsedTime();
155 _existing_keypoints = 0;
156 _keypoint_index.resize(0);
161 GenerateFeatureDisplayVBO();
170 void SiftPyramid::LimitFeatureCount(
int have_keylist)
179 int i = 0, new_feature_num = 0, level_num = param._dog_level_num * _octave_num;
180 for(; new_feature_num < _FeatureCountThreshold && i < level_num; ++i) new_feature_num += _levelFeatureNum[i];
181 for(; i < level_num; ++i) _levelFeatureNum[i] = 0;
183 if(new_feature_num < _featureNum)
185 _featureNum = new_feature_num;
188 std::cout<<
"#Features Reduced:\t"<<_featureNum<<
endl;
193 int i = 0, num_to_erase = 0;
194 while(_featureNum - _levelFeatureNum[i] > _FeatureCountThreshold)
196 num_to_erase += _levelFeatureNum[i];
197 _featureNum -= _levelFeatureNum[i];
198 _levelFeatureNum[i++] = 0;
200 if(num_to_erase > 0 && have_keylist)
202 _keypoint_buffer.erase(_keypoint_buffer.begin(), _keypoint_buffer.begin() + num_to_erase * 4);
206 std::cout<<
"#Features Reduced:\t"<<_featureNum<<
endl;
213 void SiftPyramid::PrepareBuffer()
217 if(!(_existing_keypoints & SIFT_SKIP_ORIENTATION))
235 return num <= 0 ? 1 : num;
240 if(keys) memcpy(keys, &_keypoint_buffer[0], 4*_featureNum*
sizeof(
float));
251 _keypoint_buffer.resize(num * 4);
252 memcpy(&_keypoint_buffer[0], keys, 4 * num *
sizeof(
float));
254 _existing_keypoints = SIFT_SKIP_DETECTION;
256 if(run_on_current) _existing_keypoints |= SIFT_SKIP_FILTERING;
258 if(skip_orientation) _existing_keypoints |= SIFT_SKIP_ORIENTATION;
260 if(skip_orientation == -1) _existing_keypoints |= SIFT_RECT_DESCRIPTION;
266 if (_featureNum <=0)
return;
267 float * pk = &_keypoint_buffer[0];
271 std::ofstream out(szFileName, ios::binary);
272 out.write((
char* )(&_featureNum),
sizeof(
int));
277 out.write((
char* )(&dim),
sizeof(
int));
278 float * pd = &_descriptor_buffer[0] ;
279 for(
int i = 0; i < _featureNum; i++, pk+=4, pd +=128)
281 out.write((
char* )(pk +1),
sizeof(
float));
282 out.write((
char* )(pk),
sizeof(
float));
283 out.write((
char* )(pk+2), 2 *
sizeof(
float));
284 out.write((
char* )(pd), 128 *
sizeof(
float));
289 out.write((
char* )(&dim),
sizeof(
int));
290 for(
int i = 0; i < _featureNum; i++, pk+=4)
292 out.write((
char* )(pk +1),
sizeof(
float));
293 out.write((
char* )(pk),
sizeof(
float));
294 out.write((
char* )(pk+2), 2 *
sizeof(
float));
299 std::ofstream out(szFileName);
300 out.flags(ios::fixed);
304 float * pd = &_descriptor_buffer[0] ;
305 out<<_featureNum<<
" 128"<<
endl;
307 for(
int i = 0; i < _featureNum; i++)
310 out<<setprecision(2) << pk[1]<<
" "<<setprecision(2) << pk[0]<<
" "
311 <<setprecision(3) << pk[2]<<
" " <<setprecision(3) << pk[3]<<
endl;
315 for(
int k = 0; k < 128; k ++, pd++)
318 out<< ((
unsigned int)
floor(0.5+512.0f*(*pd)))<<
" ";
320 out << setprecision(8) << pd[0] <<
" ";
322 if ( (k+1)%20 == 0 ) out<<
endl;
331 out<<_featureNum<<
" 0"<<
endl;
332 for(
int i = 0; i < _featureNum; i++, pk+=4)
334 out<<pk[1]<<
" "<<pk[0]<<
" "<<pk[2]<<
" " << pk[3]<<
endl;
341 void SiftPyramid::BeginDEBUG(
const char *imagepath)
343 if(imagepath && imagepath[0])
345 strcpy(_debug_path, imagepath);
346 strcat(_debug_path,
".debug");
349 strcpy(_debug_path,
".debug");
353 chmod(_debug_path, _S_IREAD | _S_IWRITE);
356 void SiftPyramid::StopDEBUG()
362 void SiftPyramid::WriteTextureForDEBUG(
GLTexImage * tex,
const char *namet, ...)
365 char * p =
name, * ps = _debug_path;
366 while(*ps) *p++ = *ps ++;
369 va_start(marker, namet);
370 vsprintf(p, namet, marker);
379 glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
382 glReadPixels(0, 0,
width,
height, GL_RGBA , GL_FLOAT, buffer1);
385 for(
int i = 0; i <
height; i++)
387 memcpy(buffer2 + i *
width * 4,
389 width * 4 *
sizeof(
float));
393 ilGenImages(1, &imID);
395 ilEnable(IL_FILE_OVERWRITE);
396 ilTexImage(
width,
height, 1, 4, IL_RGBA, IL_FLOAT, buffer2);
397 ilSave(IL_TIF,
name);
398 ilDeleteImages(1, &imID);
402 glReadBuffer(GL_NONE);
static int _TruncateMethod
static int _FixedOrientation
static int _FeatureCountThreshold
static int _NormalizedSIFT
static int _DescriptorPPT
static int _MaxOrientation
static float GetElapsedTime()
static void StartTimer(const char *event)
virtual void CopyFeatureVector(float *keys, float *descriptors)
virtual void RunSIFT(GLTexInput *input)
static int GetRequiredOctaveNum(int inputsz)
virtual void SetKeypointList(int num, const float *keys, int run_on_current, int skip_orientation)
virtual void SaveSIFT(const char *szFileName)
QTextStream & endl(QTextStream &stream)
MiniVec< float, N > floor(const MiniVec< float, N > &a)