DetectGPUSIFT.cc
Go to the documentation of this file.
00001 
00008 #include <blort/Recognizer3D/DetectGPUSIFT.hh>
00009 #include <blort/Recognizer3D/SDraw.hh>
00010 
00011 namespace P 
00012 {
00013 
00014 DetectGPUSIFT::DetectGPUSIFT()
00015 {
00016 
00017   //init sift
00018   //char * argv[] = {"-m", "-s", "-v", "1"};
00019   char * argv[] = {"-m", "-fo","-1", "-s", "-v", "0", "-pack"};
00020   //char * argv[] = {"-m", "-s", "-w", "3", "-fo", "-1", "-loweo"};
00021   //char * argv[] = {"-fo","-1","-v", "1"};
00022 
00023   int argc = sizeof(argv)/sizeof(char*);
00024   sift = new SiftGPU;
00025   sift->ParseParam(argc, argv);
00026 
00027   //create an OpenGL context for computation
00028   if(sift->CreateContextGL() != SiftGPU::SIFTGPU_FULL_SUPPORTED)
00029     throw Except(__HERE__,"SiftGPU is not fully supported");
00030 }
00031 
00032 DetectGPUSIFT::~DetectGPUSIFT()
00033 {
00034   delete sift;
00035 }
00036 
00037 
00038 
00039 
00040 /************************************** PRIVATE ************************************/
00041 
00042 
00043 
00044 
00045 
00046 
00047 /************************************** PUBLIC ************************************/
00048 
00049 void DetectGPUSIFT::Operate(IplImage *img, Array<KeypointDescriptor*> &keys)
00050 {
00051   for (unsigned i=0; i<keys.Size(); i++)
00052     delete keys[i];
00053   keys.Clear();
00054 
00055   if (img->depth != IPL_DEPTH_8U && img->nChannels!=1)
00056     throw Except(__HERE__,"Wrong image type!");
00057 
00058   if(sift->RunSIFT(img->width, img->height,(unsigned char *)img->imageData,GL_LUMINANCE,GL_UNSIGNED_BYTE))
00059   {
00060     KeypointDescriptor *k;
00061 
00062     int num = sift->GetFeatureNum();
00063     if (num>0)
00064     {
00065       Array<SiftGPU::SiftKeypoint> ks(num);
00066       Array<SIFTDescriptor> desc(num);
00067 
00068       sift->GetFeatureVector(&ks[0], (float*)&desc[0]);
00069 
00070       //copy sift
00071       for (unsigned i=0; i<desc.Size(); i++)
00072       {
00073         k = new KeypointDescriptor(KeypointDescriptor::DOG_SIFT, ks[i].x,ks[i].y,ks[i].s, -ks[i].o);
00074         k->AllocVec(128);
00075         CopyVec((float*)&desc[i], k->vec, 128);
00076 
00077         keys.PushBack(k);
00078       }
00079     }else cout<<"[DetectGPUSIFT::Operate] No SIFT found"<<endl;
00080   }else throw Except(__HERE__, "SiftGPU Error!");
00081 
00082 }
00083 
00087 /*void DetectGPUSIFT::Match(Array<KeypointDescriptor*> &keys, Array<CodebookEntry *> &cb, int (*matches)[2], int buf_size, int &num)
00088 {
00089   if (gpuMemSize < keys.Size()) matcher->SetMaxSift((int)keys.Size());
00090   if (gpuMemSize < cb.Size()) matcher->SetMaxSift((int)cb.Size());
00091 
00092   P::Array<SIFTDescriptor> desc1(cb.Size());
00093   P::Array<SIFTDescriptor> desc2(keys.Size());
00094 
00095   for (unsigned i=0; i<cb.Size(); i++)
00096     CopyVec(cb[i]->model->vec, (float*)&desc1, cb[i]->model->GetSize());  
00097   for (unsigned i=0; i<keys.Size(); i++)
00098     CopyVec(keys[i]->vec, (float*)&desc2, keys[i]->GetSize());  
00099 
00100   matcher->SetDescriptors(0, (int)desc1.Size(), (float*)&(desc1)[0]); //codebook
00101   matcher->SetDescriptors(1, (int)desc2.Size(), (float*)&(desc2)[0]); //keys
00102 
00103   num = matcher->GetSiftMatch(buf_size, matches);
00104 }*/
00105 
00106 
00107 
00108 /***
00109  * Draw tracks
00110  */
00111 void DetectGPUSIFT::Draw(IplImage *img, Array<KeypointDescriptor*> &keys)
00112 {
00113   for (unsigned i=0; i<keys.Size(); i++)
00114   {
00115       keys[i]->Draw(img,*keys[i],CV_RGB(255,0,0));
00116   }
00117 }
00118 
00119 
00120 
00121 }
00122 


blort
Author(s): Michael Zillich, Thomas Mörwald, Johann Prankl, Andreas Richtsfeld, Bence Magyar (ROS version)
autogenerated on Thu Jan 2 2014 11:38:25