createLocalFeatures.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * @file createLocalFeatures.cpp
  3. * @brief create local feature files
  4. * @author Erik Rodner
  5. * @date 02/14/2008
  6. */
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <unistd.h>
  10. #include <core/basics/Config.h>
  11. #include <vislearning/baselib/Globals.h>
  12. #include <vislearning/baselib/Preprocess.h>
  13. #include <vislearning/features/localfeatures/GenericLFSelection.h>
  14. #include <vislearning/features/localfeatures/LocalFeatureRepresentation.h>
  15. #include <vislearning/features/localfeatures/LFWriteCache.h>
  16. #include <vislearning/cbaselib/MultiDataset.h>
  17. #include <vislearning/baselib/ProgressBar.h>
  18. #ifdef NOVISUAL
  19. #include <vislearning/nice_nonvis.h>
  20. #else
  21. #include <vislearning/nice.h>
  22. #endif
  23. using namespace OBJREC;
  24. using namespace NICE;
  25. using namespace std;
  26. /**
  27. create local feature files
  28. */
  29. int main (int argc, char **argv)
  30. {
  31. std::set_terminate(__gnu_cxx::__verbose_terminate_handler);
  32. Config conf ( argc, argv );
  33. string setname;
  34. try {
  35. setname = conf.gS("main", "set");
  36. } catch ( Exception ) {
  37. fprintf (stderr, "usage: %s -config <configfn> -ds <dataset>\n", argv[0]);
  38. exit(-1);
  39. }
  40. bool useColor = conf.gB("main", "color", true );
  41. Preprocess::Init ( &conf );
  42. MultiDataset md ( &conf );
  43. LabeledSet ls = *(md[setname]);
  44. LocalFeatureRepresentation *lfrep = GenericLFSelection::selectLocalFeatureRep ( &conf );
  45. LFWriteCache lfw ( &conf, lfrep );
  46. std::string cachedir = conf.gS("cache", "root");
  47. int cachemode = Globals::getCacheMode ( conf.gS("cache", "mode", "cat") );
  48. ProgressBar pb ("Local Feature Extraction" );
  49. LOOP_ALL_S(ls)
  50. {
  51. EACH_S(classno,filename);
  52. pb.update ( ls.count() );
  53. NICE::Image img;
  54. NICE::ColorImage imgColor;
  55. if ( !useColor )
  56. img = Preprocess::ReadImgAdv ( filename );
  57. else
  58. imgColor = Preprocess::ReadImgAdvRGB ( filename );
  59. Globals::setCurrentImgFN ( filename );
  60. std::string cache_filename = Globals::getCacheFilename( cachedir, cachemode );
  61. std::string cache_filename_desc = cache_filename + ".desc";
  62. struct stat dummy;
  63. if ( stat ( cache_filename_desc.c_str(), &dummy ) < 0 )
  64. {
  65. VVector features;
  66. VVector positions;
  67. cerr << "creating features for file " << filename << " ..." << endl;
  68. cerr << "writing features to file " << cache_filename_desc << " ..." << endl;
  69. if ( !useColor ) {
  70. lfw.extractFeatures ( img, features, positions );
  71. } else {
  72. lfw.extractFeatures ( imgColor, features, positions );
  73. }
  74. cerr << "pos: " << positions.size() << " feat:" << features.size() << endl;
  75. } else {
  76. cerr << "description file " << cache_filename_desc << " exists !" << endl;
  77. }
  78. }
  79. delete lfrep;
  80. return 0;
  81. }