123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- // Beispielhafter Aufruf: BUILD_x86_64/progs/testSemanticSegmentation -config <CONFIGFILE>
- /**
- * @file testSemanticSegmentation.cpp
- * @brief test semantic segmentation routines
- * @author Erik Rodner
- * @date 03/20/2008
- */
- #ifdef NICE_USELIB_OPENMP
- #include <omp.h>
- #endif
- #include "core/basics/Config.h"
- #include <core/basics/StringTools.h>
- #include <vislearning/baselib/ICETools.h>
- #include "vislearning/cbaselib/MultiDataset.h"
- #include "core/image/MultiChannelImageT.h"
- #include <fstream>
- using namespace OBJREC;
- using namespace NICE;
- using namespace std;
- /**
- test semantic segmentation routines
- */
- int main( int argc, char **argv )
- {
- Config conf( argc, argv );
- MultiDataset md( &conf );
- const ClassNames & classNames = md.getClassNames( "train" );
- const LabeledSet *testFiles = md["test"];
- set<int> forbidden_classes;
- std::string forbidden_classes_s = conf.gS( "analysis", "forbidden_classes", "" );
- classNames.getSelection( forbidden_classes_s, forbidden_classes );
- LOOP_ALL_S( *testFiles )
- {
- EACH_INFO( classno, info );
- std::string file = info.img();
- NICE::Image lm;
- NICE::MultiChannelImageT<double> probabilities;
- if ( info.hasLocalizationInfo() )
- {
- const LocalizationResult *l_gt = info.localization();
- lm.resize( l_gt->xsize, l_gt->ysize );
- lm.set( 0 );
- l_gt->calcLabeledImage( lm, classNames.getBackgroundClass() );
- }
- NICE::Image lm_gt;
- if ( info.hasLocalizationInfo() )
- {
- const LocalizationResult *l_gt = info.localization();
- lm_gt.resize( l_gt->xsize, l_gt->ysize );
- lm_gt.set( 0 );
- fprintf( stderr, "testSemanticSegmentation: Generating Labeled NICE::Image (Ground-Truth)\n" );
- l_gt->calcLabeledImage( lm_gt, classNames.getBackgroundClass() );
- }
- set<int> classes;
- for ( int x = 0; x < lm_gt.width(); x++ )
- {
- for ( int y = 0; y < lm_gt.height(); y++ )
- {
- classes.insert( lm_gt.getPixel( x, y ) );
- }
- }
- // write allowed classes
- string cndir = conf.gS( "SemSegCsurka", "cndir", "" );
- std::vector< std::string > list;
- StringTools::split( file, '/', list );
- cout << cndir << "/" << list.back() << ".dat" << endl;
- string cname = list.back();
- if ( cndir != "" )
- {
- string fname = cndir + "/" + cname + ".dat";
- cout << fname << endl;
- ofstream outfile( fname.c_str() );
- set<int>::iterator theIterator;
- for ( theIterator = classes.begin(); theIterator != classes.end(); theIterator++ ) {
- outfile << *theIterator << endl;
- }
- }
- else
- {
- cerr << "please define directory for writing filenames in config: SemSegCsurka::cndir" << endl;
- exit( -1 );
- }
- }
- return 0;
- }
|