3 #include "SiftGPU_Extractor.h"
6 SiftGPU_Extractor::SiftGPU_Extractor()
8 SiftGPU* (*pCreateNewSiftGPU)(int) = NULL;
9 SiftMatchGPU* (*pCreateNewSiftMatchGPU)(int) = NULL;
12 pPath = getenv (
"SIFTGPU_DIR");
16 #ifdef SIFTGPU_DLL_RUNTIME
19 str.append(
"/bin/SIFTGPU.dll");
21 HMODULE hsiftgpu = LoadLibrary(str.c_str());
23 HMODULE hsiftgpu = LoadLibrary(str.c_str());
26 str.append(
"/bin/libsiftgpu.so");
27 void * hsiftgpu = dlopen(str.c_str(), RTLD_LAZY);
31 ComboSiftGPU* (*pCreateRemoteSiftGPU) (int,
char*) = NULL;
32 pCreateRemoteSiftGPU = (ComboSiftGPU* (*) (
int,
char*)) GET_MYPROC(hsiftgpu,
"CreateRemoteSiftGPU");
33 combo = pCreateRemoteSiftGPU(REMOTE_SERVER_PORT, REMOTE_SERVER);
39 pCreateNewSiftGPU = (SiftGPU* (*) (
int)) GET_MYPROC(hsiftgpu,
"CreateNewSiftGPU");
40 pCreateNewSiftMatchGPU = (SiftMatchGPU* (*)(
int)) GET_MYPROC(hsiftgpu,
"CreateNewSiftMatchGPU");
41 sift = pCreateNewSiftGPU(1);
42 matcher = pCreateNewSiftMatchGPU(4096);
45 #elif defined(REMOTE_SIFTGPU)
46 combo = CreateRemoteSiftGPU(REMOTE_SERVER_PORT, REMOTE_SERVER);
52 matcher =
new SiftMatchGPU(4096);
55 char * argv[] = {(
char*)
"-fo", (
char*)
"-1", (
char*)
"-v",(
char*)
"1", (
char*)
"-winpos",(
char*)
"-maxd", (
char*)
"1024"};
56 int argc =
sizeof(argv)/
sizeof(
char*);
59 sift->ParseParam(argc, argv);
64 if(sift->CreateContextGL() != SiftGPU::SIFTGPU_FULL_SUPPORTED)
65 fprintf(stdout,
"boh, some error\n");
67 matcher->VerifyContextGL();
74 bool SiftGPU_Extractor::setDenseGrid(
int width,
int height,
int step,
int scale)
76 int widthNodes=(int)(width-step)/step;
77 int heightNodes=(int)(height-step)/step;
79 keypoints_grid.resize(widthNodes*heightNodes);
81 for(
int row=step; row<=height-step; row+=step)
83 for(
int col=step; col<=width-step; col+=step)
86 keypoints_grid[idx].x=col;
87 keypoints_grid[idx].y=row;
88 keypoints_grid[idx].s=scale;
89 keypoints_grid[idx].o=0.0f;
99 bool SiftGPU_Extractor::setDenseGrid(IplImage *img,
int step,
int scale)
101 setDenseGrid(img->width,img->height,step,scale);
107 bool SiftGPU_Extractor::extractSift(IplImage *img,vector<SiftGPU::SiftKeypoint> *keypoints, vector<float> *descriptors,
int feature_size)
109 if(img->nChannels==1)
110 sift->RunSIFT(img->width,img->height,img->imageData,GL_LUMINANCE,GL_UNSIGNED_BYTE );
111 else if(img->nChannels==3)
112 sift->RunSIFT(img->width,img->height,img->imageData,GL_RGB,GL_UNSIGNED_BYTE );
116 if(feature_size!=128)
117 fprintf(stdout,
"Error! wrong feature size!\n");
119 int feature_num=sift->GetFeatureNum();
124 if(keypoints!=NULL && descriptors!=NULL)
126 keypoints->resize(feature_num);
127 descriptors->resize(feature_size*feature_num);
128 sift->GetFeatureVector(&(keypoints->at(0)),&(descriptors->at(0)));
136 bool SiftGPU_Extractor::extractDenseSift(IplImage *img,vector<SiftGPU::SiftKeypoint> *keypoints, vector<float> *descriptors,
int feature_size)
138 if(keypoints_grid.size()==0)
141 sift->SetKeypointList(keypoints_grid.size(),&keypoints_grid[0],0);
142 return this->extractSift(img,keypoints,descriptors,feature_size);
146 int SiftGPU_Extractor::getFeatureNum()
148 return sift->GetFeatureNum();
152 bool SiftGPU_Extractor::getFeatureVector(vector<SiftGPU::SiftKeypoint> *keypoints, vector<float> *descriptors,
int feature_size)
154 if(feature_size!=128)
155 fprintf(stdout,
"Error! wrong feature size!\n");
157 int feature_num=sift->GetFeatureNum();
159 keypoints->resize(feature_num);
160 descriptors->resize(feature_size*feature_num);
161 sift->GetFeatureVector(&(keypoints->at(0)),&(descriptors->at(0)));