label_results.h
Go to the documentation of this file.
00001 
00060 #ifndef __COB_3D_MAPPING_COMMON_LABEL_RESULTS_H__
00061 #define __COB_3D_MAPPING_COMMON_LABEL_RESULTS_H__
00062 
00063 #include <ostream>
00064 #include <fstream>
00065 #include <sstream>
00066 #include <limits>
00067 #include <string>
00068 #include "cob_3d_mapping_common/label_defines.h"
00069 
00070 #define NUM_LBL 7
00071 
00072 namespace cob_3d_mapping_common
00073 {
00074   class LabelResults
00075   {
00076     public:
00077     LabelResults(const std::string &rn,
00078                  const std::string &rf,
00079                  const bool mls) : rn_(rn), rf_(rf), mls_(mls), undef(0)
00080     {
00081       for (size_t i = 0; i < NUM_LBL; ++i)
00082       {
00083         exp[i] = 0;
00084         fp[i] = 0;
00085         fn[i] = 0;
00086         tp[i] = 0;
00087         tn[i] = 0;
00088         prec[i] = 0.0;
00089         rec[i] = 0.0;
00090         f1[i] = 0.0;
00091       }
00092     }
00093 
00094     void calcResults()
00095     {
00096       all = 0;
00097       for(size_t i = 0; i < NUM_LBL; ++i)
00098       {
00099         all = exp[EVAL_PLANE]+exp[EVAL_EDGE]+exp[EVAL_SPH]+exp[EVAL_CYL]+exp[EVAL_COR];
00100       }
00101       for(size_t i = 0; i < NUM_LBL; ++i)
00102       {
00103         tp[i] = exp[i] - fn[i];
00104         tn[i] = all - exp[i] - fp[i];
00105         prec[i] = (float)tp[i] / (tp[i] + fp[i]);
00106         rec[i] = (float)tp[i] / (tp[i] + fn[i]);
00107         f1[i] = 2.0f * prec[i] * rec[i] / (prec[i] + rec[i]);
00108       }
00109     }
00110 
00111     std::string writeToFile(const std::string &file,
00112                             const std::string &p1 = "",
00113                             const std::string &p2 = "",
00114                             const std::string &p3 = "",
00115                             const std::string &p4 = "") const
00116     {
00117       std::stringstream f;
00118       f << rn_ <<";"<< rf_ <<";"<< mls_ <<";";
00119       if (p1 == "")
00120         f << all <<";"<< undef <<";";
00121       else if (p2 == "")
00122         f << p1 <<";"<< all <<";"<< undef <<";";
00123       else if (p3 == "")
00124         f << p1 <<";"<< p2 <<";"<< all <<";"<< undef <<";";
00125       else if (p4 == "")
00126         f << p1 <<";"<< p2 <<";"<< p3 <<";"<< all <<";"<< undef <<";";
00127       else
00128         f << p1 <<";"<< p2 <<";"<< p3 <<";"<< p4 <<";"<< all <<";"<< undef <<";";
00129 
00130       for(size_t i = 0; i < NUM_LBL; ++i)
00131       {
00132         f << exp[i] <<";"<< tp[i] <<";"<< fp[i] <<";"<< fn[i] <<";"
00133           << prec[i] <<";"<< rec[i] <<";"<< f1[i] <<";";
00134       }
00135       if (file != "")
00136       {
00137         std::fstream ffile;
00138         ffile.open(file.c_str(), std::fstream::out | std::fstream::app);
00139         ffile << f << std::endl;
00140         ffile.close();
00141       }
00142       return f.str();
00143     }
00144 
00145     std::string writeToFile(const std::string &file,
00146                             const float p1 = std::numeric_limits<float>::quiet_NaN(),
00147                             const float p2 = std::numeric_limits<float>::quiet_NaN(),
00148                             const float p3 = std::numeric_limits<float>::quiet_NaN(),
00149                             const float p4 = std::numeric_limits<float>::quiet_NaN()) const
00150     {
00151       std::stringstream f;
00152       f << rn_ <<";"<< rf_ <<";"<< mls_ <<";";
00153       if (p1 != p1)
00154         f << all <<";"<< undef <<";";
00155       else if (p2 != p2)
00156         f << p1 <<";"<< all <<";"<< undef <<";";
00157       else if (p3 != p3)
00158         f << p1 <<";"<< p2 <<";"<< all <<";"<< undef <<";";
00159       else if (p4 != p4)
00160         f << p1 <<";"<< p2 <<";"<< p3 <<";"<< all <<";"<< undef <<";";
00161       else
00162         f << p1 <<";"<< p2 <<";"<< p3 <<";"<< p4 <<";"<< all <<";"<< undef <<";";
00163 
00164       for(size_t i = 0; i < NUM_LBL; ++i)
00165       {
00166         f << exp[i] <<";"<< tp[i] <<";"<< fp[i] <<";"<< fn[i] <<";"
00167           << prec[i] <<";"<< rec[i] <<";"<< f1[i] <<";";
00168       }
00169       if (file != "")
00170       {
00171         std::fstream ffile;
00172         ffile.open(file.c_str(), std::fstream::out | std::fstream::app);
00173         ffile << f.str() << std::endl;
00174         ffile.close();
00175       }
00176       return f.str();
00177     }
00178 
00179     std::string writeToFile(const std::string &file = "") const
00180     {
00181       std::stringstream f;
00182       f << rn_ <<";"<< rf_ <<";"<< mls_ <<";"<< all <<";"<< undef <<";";
00183 
00184 
00185       for(size_t i = 0; i < NUM_LBL; ++i)
00186       {
00187         f << exp[i] <<";"<< tp[i] <<";"<< fp[i] <<";"<< fn[i] <<";"
00188           << prec[i] <<";"<< rec[i] <<";"<< f1[i] <<";";
00189       }
00190       if (file != "")
00191       {
00192         std::fstream ffile;
00193         ffile.open(file.c_str(), std::fstream::out | std::fstream::app);
00194         ffile << f.str() << std::endl;
00195         ffile.close();
00196       }
00197       return f.str();
00198     }
00199 
00200 
00201     friend std::ostream& operator<< (std::ostream &os,const LabelResults &obj);
00202 
00203     public:
00204     int exp [NUM_LBL];
00205     int fp [NUM_LBL];
00206     int fn [NUM_LBL];
00207     int tp [NUM_LBL];
00208     int tn [NUM_LBL];
00209     int undef;
00210     int all;
00211     float prec [NUM_LBL];
00212     float rec [NUM_LBL];
00213     float f1 [NUM_LBL];
00214 
00215     private:
00216     std::string rn_;
00217     std::string rf_;
00218     bool mls_;
00219   };
00220 
00221   std::ostream& operator<< (std::ostream &os, LabelResults &obj)
00222   {
00223     obj.calcResults();
00224     os << obj.writeToFile();
00225     return os;
00226   }
00227 
00228   std::string writeHeader(const std::string &file = "",
00229                           const std::string &p1 = "",
00230                           const std::string &p2 = "",
00231                           const std::string &p3 = "",
00232                           const std::string &p4 = "")
00233   {
00234     std::stringstream f;
00235     f << "rn;"<<"rf;"<<"mls;";
00236     if (p1 != "")
00237     {
00238       if (p2 == "")
00239         f << p1 <<";";
00240       else if (p3 == "")
00241         f << p1 <<";" << p2 <<";";
00242       else if (p4 == "")
00243         f << p1 <<";" << p2 <<";" << p3 <<";";
00244       else
00245         f << p1 <<";" << p2 <<";" << p3 <<";" << p4 <<";";
00246     }
00247 
00248     f << "all;"<<"undef;"
00249       << "exp(Plane);"<<"TP;"<<"FP;"<<"FN;"<<"Prec.;"<<"Rec.;"<<"F1;"
00250       << "exp(Edge);"<<"TP;"<<"FP;"<<"FN;"<<"Prec.;"<<"Rec.;"<<"F1;"
00251       << "exp(Sphere);"<<"TP;"<<"FP;"<<"FN;"<<"Prec.;"<<"Rec.;"<<"F1;"
00252       << "exp(Cylinder);"<<"TP;"<<"FP;"<<"FN;"<<"Prec.;"<<"Rec.;"<<"F1;"
00253       << "exp(Corner);"<<"TP;"<<"FP;"<<"FN;"<<"Prec.;"<<"Rec.;"<<"F1;"
00254       << "exp(EdgeCorner);"<<"TP;"<<"FP;"<<"FN;"<<"Prec.;"<<"Rec.;"<<"F1;"
00255       << "exp(Curved);"<<"TP;"<<"FP;"<<"FN;"<<"Prec.;"<<"Rec.;"<<"F1;";
00256 
00257     if (file != "")
00258     {
00259       std::fstream ffile;
00260       ffile.open(file.c_str(), std::fstream::out);
00261       ffile << f.str() << std::endl;
00262       ffile.close();
00263     }
00264     return f.str();
00265   }
00266 
00267   std::string createTimestamp()
00268   {
00269     struct tm *t;
00270     time_t rawtime;
00271     time(&rawtime);
00272     t = localtime(&rawtime);
00273     std::stringstream stamp;
00274     stamp << (t->tm_year+1900);
00275     if (t->tm_mon+1 < 10) stamp << "0";
00276     stamp << t->tm_mon+1;
00277     if (t->tm_mday < 10) stamp << "0";
00278     stamp << t->tm_mday << "_";
00279     if (t->tm_hour < 10) stamp << "0";
00280     stamp << t->tm_hour;
00281     if (t->tm_min < 10) stamp << "0";
00282     stamp << t->tm_min;
00283     if (t->tm_sec < 10) stamp << "0";
00284     stamp << t->tm_sec;
00285 
00286     return stamp.str();
00287   }
00288 
00289   void parseFileName(const std::string &file,
00290                      std::string &rn,
00291                      std::string &rf,
00292                      bool &is_mls)
00293   {
00294     std::string tmp = "";
00295     if (std::string::npos != file.rfind("rnmls_"))
00296     {
00297       is_mls = true;
00298       rn = tmp + file[file.length() - 18] + file[file.length() - 17] + file[file.length() - 16];
00299     }
00300     else
00301     {
00302       is_mls = false;
00303       rn = tmp + file[file.length() - 15] + file[file.length() - 14] + file[file.length() - 13];
00304     }
00305     rf = tmp + file[file.length() - 9] + file[file.length() - 8] + file[file.length() - 7];
00306 
00307     return;
00308   }
00309 }
00310 
00311 #endif


cob_3d_evaluation_features
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:04:38