DetectSIFT.cc
Go to the documentation of this file.
00001 
00007 #include <errno.h>
00008 #include <blort/Recognizer3D/DetectSIFT.hh>
00009 #include <blort/Recognizer3D/SDraw.hh>
00010 #include <string>
00011 #include <unistd.h>
00012 
00013 namespace P 
00014 {
00015 
00016     DetectSIFT::DetectSIFT()
00017     {
00018     }
00019 
00020     DetectSIFT::~DetectSIFT()
00021     {
00022     }
00023 
00024 
00025 
00026 
00027     /************************************** PRIVATE ************************************/
00031     void DetectSIFT::SavePGMImage(const char *filename, IplImage *grey)
00032     {
00033         if (grey->nChannels!=1 && grey->depth != IPL_DEPTH_8U)
00034             throw Except(__HERE__,"Wrong image format!");
00035 
00036         unsigned storage_size = grey->width*grey->height*grey->depth;
00037 
00038         FILE *file = fopen(filename, "w");
00039         if(file == NULL)
00040             throw Except(__HERE__, "failed to open file %s:", filename,strerror(errno));
00041         fprintf(file,"P5\n%u %u\n255\n", grey->width, grey->height);
00042 
00043         fwrite(grey->imageData, 1, storage_size, file);
00044 
00045         fclose(file);
00046     }
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057     /************************************** PUBLIC ************************************/
00058 
00059     void DetectSIFT::Operate(IplImage *img, Array<KeypointDescriptor*> &keys)
00060     {
00061 #ifndef WIN32 // TODO TODO TODO> DIRTY HACK, cause wait.h not defined in windoof
00062         if (img->depth != IPL_DEPTH_8U && img->nChannels!=1)
00063             throw Except(__HERE__,"Wrong image type!");
00064 
00065         SavePGMImage("./detbin/grey.pgm", img);
00066 
00067         int pid,status;
00068         switch(pid = fork()){
00069         case 0:
00070             execl(std::string("/bin/sh").c_str(),
00071                   std::string("/bin/sh").c_str(),
00072                   std::string("-c").c_str(),
00073                   std::string("./detbin/sift <./detbin/grey.pgm >./detbin/grey.key").c_str(),
00074                   (char*)0);
00075             break;
00076 
00077         default: while(wait(&status) != pid);
00078         }
00079 
00080         LoadLoweKeypoints("./detbin/grey.key", keys, 0);
00081 
00082         //..or only correct type
00083         for (unsigned i=0; i<keys.Size(); i++)
00084             ((KeypointDescriptor*)keys[i])->type = KeypointDescriptor::LOWE_DOG_SIFT;
00085 #else
00086         printf("[Recognizer3D DetectSIFT::Operate] not implemented for WIN32\n");
00087 #endif
00088     }
00089 
00090 
00091     /***
00092  * Draw tracks
00093  */
00094     void DetectSIFT::Draw(IplImage *img, Array<KeypointDescriptor*> &keys)
00095     {
00096         for (unsigned i=0; i<keys.Size(); i++)
00097         {
00098             keys[i]->Draw(img,*keys[i],CV_RGB(255,0,0));
00099         }
00100     }
00101 
00102 
00103 
00104 }
00105 


blort
Author(s): Thomas Mörwald , Michael Zillich , Andreas Richtsfeld , Johann Prankl , Markus Vincze , Bence Magyar
autogenerated on Wed Aug 26 2015 15:24:12