getRelevantClasses.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. int counter = 0;
  37. int nbclasses = 0;
  38. LOOP_ALL_S(*testFiles)
  39. {
  40. EACH_INFO(classno, info);
  41. std::string file = info.img();
  42. NICE::Image lm;
  43. GenericImage<double> probabilities;
  44. if (info.hasLocalizationInfo())
  45. {
  46. const LocalizationResult *l_gt = info.localization();
  47. lm.resize(l_gt->xsize, l_gt->ysize);
  48. lm.set(0);
  49. l_gt->calcLabeledImage(lm, classNames.getBackgroundClass());
  50. }
  51. //semseg->semanticseg(file, lm, probabilities);
  52. NICE::Image lm_gt;
  53. if (info.hasLocalizationInfo())
  54. {
  55. const LocalizationResult *l_gt = info.localization();
  56. lm_gt.resize(l_gt->xsize, l_gt->ysize);
  57. lm_gt.set(0);
  58. fprintf(stderr, "testSemanticSegmentation: Generating Labeled NICE::Image (Ground-Truth)\n");
  59. l_gt->calcLabeledImage(lm_gt, classNames.getBackgroundClass());
  60. }
  61. set<int> classes;
  62. for(int x = 0; x < lm_gt.width(); x++)
  63. {
  64. for(int y = 0; y < lm_gt.height(); y++)
  65. {
  66. classes.insert(lm_gt.getPixel(x,y));
  67. }
  68. }
  69. // write allowed classes
  70. string cndir = conf.gS("SemSegCsurka", "cndir", "");
  71. std::vector< std::string > list;
  72. StringTools::split (file, '/', list);
  73. cout << cndir<< "/" << list.back() << ".dat" << endl;
  74. string cname = list.back();
  75. if(cndir != "")
  76. {
  77. string fname = cndir+"/"+cname+".dat";
  78. cout << fname << endl;
  79. ofstream outfile(fname.c_str());
  80. set<int>::iterator theIterator;
  81. for( theIterator = classes.begin(); theIterator != classes.end(); theIterator++ ) {
  82. outfile << *theIterator << endl;
  83. }
  84. }
  85. else
  86. {
  87. cerr << "please define directory for writing filenames in config: SemSegCsurka::cndir" << endl;
  88. exit(-1);
  89. }
  90. }
  91. return 0;
  92. }