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


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