Browse Source

reading labels from csv file (experimental)

Sven Sickert 8 năm trước cách đây
mục cha
commit
359f36b626
2 tập tin đã thay đổi với 38 bổ sung1 xóa
  1. 35 1
      cbaselib/LabeledFileList.cpp
  2. 3 0
      cbaselib/LabeledFileList.h

+ 35 - 1
cbaselib/LabeledFileList.cpp

@@ -31,6 +31,27 @@ LabeledFileList::~LabeledFileList()
 {
 }
 
+int LabeledFileList::getClassFromNumber (
+    const std::string & lfile,
+    const int exampleID ) const
+{
+  int cvalue = -1;
+
+  std::ifstream file( lfile.c_str() );
+  std::string str;
+  while ( std::getline(file, str) )
+  {
+    NICE::Vector valList(2,0);
+    NICE::StringTools::splitVector( str, ',', valList );
+    if ( (int)valList[0] == exampleID )
+    {
+      cvalue = (int)valList[1];
+      break;
+    }
+  }
+
+  return cvalue;
+}
 
 /**
  * @brief Loads the label information according to a given label file format.
@@ -107,6 +128,19 @@ LocalizationResult *LabeledFileList::getLocalizationInfo ( const ClassNames & cl
     lr = new LocalizationResult ( &classnames, mask );
 
   }
+  else if ( format == "csv" ) {
+      // CAUTION! This is for experimental use only and needs a certain configuration of
+      // the csv file and scheme for the image file names!
+      NICE::ColorImage mask;
+      mask.read( file );
+      int exampleID = -1;
+      std::size_t found = file.find( "ID" );
+      std::string exampleIDStr = file.substr(found+2,found+8);
+      exampleID = std::atoi(exampleIDStr.c_str());
+      int g = getClassFromNumber( lfile, exampleID );
+      mask.set((uchar)g,(uchar)g,(uchar)g);
+      lr = new LocalizationResult ( &classnames, mask );
+  }
   else if ( format == "polygon" ) {
       lr = new LocalizationResult ( &classnames );
 
@@ -131,7 +165,7 @@ LocalizationResult *LabeledFileList::getLocalizationInfo ( const ClassNames & cl
   else {
     fthrow(Exception, "Localization format not yet supported !!\n");
   }
-   
+
   if ( debug_dataset )
 	if ( lr != NULL )
       fprintf (stderr, "%s (%d objects)\n", lfile.c_str(), (int)lr->size() );

+ 3 - 0
cbaselib/LabeledFileList.h

@@ -53,6 +53,9 @@ class LabeledFileList
     * ( ::setFactory() ). [Johannes Ruehle]
     * @see LabeledSetFactory
     */
+        int getClassFromNumber( const std::string & lfile,
+                                const int exampleID ) const;
+
 	void get ( const std::string & dir,
 		   const NICE::Config & datasetconf,
 		   const ClassNames & classnames,