getRelevantClasses.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // Beispielhafter Aufruf: BUILD_x86_64/progs/testSemanticSegmentation -config <CONFIGFILE>
  2. /**
  3. * @file testSemanticSegmentation.cpp
  4. * @brief test semantic segmentation routines
  5. * @author Erik Rodner
  6. * @date 03/20/2008
  7. */
  8. #ifdef NICE_USELIB_OPENMP
  9. #include <omp.h>
  10. #endif
  11. #include <objrec/baselib/Config.h>
  12. #include <objrec/baselib/StringTools.h>
  13. #include <objrec/baselib/ICETools.h>
  14. #include <objrec/semanticsegmentation/SemanticSegmentation.h>
  15. #include <objrec/semanticsegmentation/SemSegLocal.h>
  16. #include <objrec/semanticsegmentation/SemSegSTF.h>
  17. #include <objrec/semanticsegmentation/SemSegCsurka.h>
  18. #include <objrec/semanticsegmentation/SemSegCsurka2.h>
  19. #include <objrec/semanticsegmentation/SemSegRegionBased.h>
  20. #include <fstream>
  21. using namespace OBJREC;
  22. using namespace NICE;
  23. using namespace std;
  24. /**
  25. test semantic segmentation routines
  26. */
  27. int main(int argc, char **argv)
  28. {
  29. Config conf(argc, argv);
  30. MultiDataset md(&conf);
  31. const ClassNames & classNames = md.getClassNames("train");
  32. const LabeledSet *testFiles = md["test"];
  33. set<int> forbidden_classes;
  34. std::string forbidden_classes_s = conf.gS("analysis", "forbidden_classes", "");
  35. classNames.getSelection(forbidden_classes_s, forbidden_classes);
  36. LOOP_ALL_S(*testFiles)
  37. {
  38. EACH_INFO(classno, info);
  39. std::string file = info.img();
  40. NICE::Image lm;
  41. GenericImage<double> probabilities;
  42. if (info.hasLocalizationInfo())
  43. {
  44. const LocalizationResult *l_gt = info.localization();
  45. lm.resize(l_gt->xsize, l_gt->ysize);
  46. lm.set(0);
  47. l_gt->calcLabeledImage(lm, classNames.getBackgroundClass());
  48. }
  49. //semseg->semanticseg(file, lm, probabilities);
  50. NICE::Image lm_gt;
  51. if (info.hasLocalizationInfo())
  52. {
  53. const LocalizationResult *l_gt = info.localization();
  54. lm_gt.resize(l_gt->xsize, l_gt->ysize);
  55. lm_gt.set(0);
  56. fprintf(stderr, "testSemanticSegmentation: Generating Labeled NICE::Image (Ground-Truth)\n");
  57. l_gt->calcLabeledImage(lm_gt, classNames.getBackgroundClass());
  58. }
  59. set<int> classes;
  60. for(int x = 0; x < lm_gt.width(); x++)
  61. {
  62. for(int y = 0; y < lm_gt.height(); y++)
  63. {
  64. classes.insert(lm_gt.getPixel(x,y));
  65. }
  66. }
  67. // write allowed classes
  68. string cndir = conf.gS("SemSegCsurka", "cndir", "");
  69. std::vector< std::string > list;
  70. StringTools::split (file, '/', list);
  71. cout << cndir<< "/" << list.back() << ".dat" << endl;
  72. string cname = list.back();
  73. if(cndir != "")
  74. {
  75. string fname = cndir+"/"+cname+".dat";
  76. cout << fname << endl;
  77. ofstream outfile(fname.c_str());
  78. set<int>::iterator theIterator;
  79. for( theIterator = classes.begin(); theIterator != classes.end(); theIterator++ ) {
  80. outfile << *theIterator << endl;
  81. }
  82. }
  83. else
  84. {
  85. cerr << "please define directory for writing filenames in config: SemSegCsurka::cndir" << endl;
  86. exit(-1);
  87. }
  88. }
  89. return 0;
  90. }