00001
00002
00003 #ifndef SIFT_DEMO_WRAPPER_HPP
00004 #define SIFT_DEMO_WRAPPER_HPP
00005
00006 #include <cstdlib>
00007 #include <cmath>
00008
00009 #include <string>
00010 #include <sstream>
00011 #include <fstream>
00012
00013 #include "boost/numeric/ublas/vector.hpp"
00014
00015 #include "kernel/jafarException.hpp"
00016 #include "kernel/jafarDebug.hpp"
00017 #include "kernel/timingTools.hpp"
00018
00019 #include "sift/dataBase.hpp"
00020
00021 namespace jafar {
00022 namespace sift {
00023
00031 template<class Container>
00032 void demoWrapper(std::string const& imageFileName, double scale, Container& siftPointsContainer) {
00033 char tmpPgmFilename[] = "/tmp/jafarPgmXXXXXX";
00034 mktemp(tmpPgmFilename);
00035
00036 std::ostringstream convertCmd;
00037 convertCmd << "convert -resize " << int(round(scale*100)) << "% " << imageFileName << " " << tmpPgmFilename << ".pgm";
00038 system(convertCmd.str().c_str());
00039
00040 char tmpSiftKeyFilename[] = "/tmp/jafarSiftKeyXXXXXX";
00041 mktemp(tmpSiftKeyFilename);
00042
00043 std::ostringstream siftCmd;
00044 siftCmd << "${JAFAR_DIR}/modules/sift/siftDemoV4/sift < " << tmpPgmFilename << ".pgm > " << tmpSiftKeyFilename;
00045 kernel::Chrono c;
00046 system(siftCmd.str().c_str());
00047 JFR_DEBUG("sift process: " << c.elapsed() << " ms");
00048 unlink(tmpPgmFilename);
00049
00050 std::ifstream siftKeyFile(tmpSiftKeyFilename);
00051 JFR_IO_STREAM(siftKeyFile, "computeSIFTPoints: error opening temporary key file");
00052 SiftPoint p;
00053
00054 int nbPoints;
00055 int descriptorSize;
00056
00057 siftKeyFile >> nbPoints >> descriptorSize;
00058 JFR_ASSERT(descriptorSize == 128, "computeSIFTPoints: lenght " << descriptorSize << " of descriptor not supported");
00059
00060 for (int i = 0 ; i < nbPoints ; ++i) {
00061 siftKeyFile >> p.u >> p.v >> p.scale >> p.orientation;
00062 for (int j = 0 ; j < descriptorSize ; ++j) {
00063 siftKeyFile >> p.descriptor(j);
00064 }
00065 siftPointsContainer.push_back(p);
00066 }
00067
00068 siftKeyFile.close();
00069 unlink(tmpSiftKeyFilename);
00070
00071 };
00072
00073 }
00074 }
00075
00076 #endif // SIFT_DEMO_WRAPPER_HPP