evaluate_test_data.cpp
Go to the documentation of this file.
00001 
00063 #include <fstream>
00064 #include <boost/program_options.hpp>
00065 
00066 #include <pcl/io/pcd_io.h>
00067 #include <pcl/common/file_io.h>
00068 #include <pcl/point_types.h>
00069 
00070 #include <cob_3d_evaluation_features/label_results.h>
00071 
00072 using namespace pcl;
00073 using namespace std;
00074 
00075 vector<string> scenes_;
00076 string folder_, config_file_;
00077 bool en_pc, en_rsd;
00078 
00079 float c_low_min, c_low_max, c_low_steps, c_high_min, c_high_max, c_high_steps;
00080 float c_r1_min, c_r1_max, c1_steps, c_r2_min, c_r2_max, c2_steps;
00081 
00082 float r_low_min, r_low_max, r_low_steps, r_high_min, r_high_max, r_high_steps;
00083 float r_r1_min, r_r1_max, r1_steps, r_r2_min, r_r2_max, r2_steps;
00084 
00085 void readOptions(int argc, char* argv[])
00086 {
00087   using namespace boost::program_options;
00088   options_description options("Options");
00089   options.add_options()
00090     ("help", "produce help message")
00091     ("config,c", value<string>(&config_file_), "cfg file")
00092     ("folder", value<string>(&folder_), "set folder")
00093     ("scenes", value<vector<string> >(&scenes_), "name of used scenes")
00094     ("pc,P", "enable PC")
00095     ("rsd,R", "enable RSD")
00096 
00097     ("c_low_min", value<float>(&c_low_min), "")
00098     ("c_low_max", value<float>(&c_low_max), "")
00099     ("c_low_steps", value<float>(&c_low_steps), "")
00100     ("c_high_min", value<float>(&c_high_min), "")
00101     ("c_high_max", value<float>(&c_high_max), "")
00102     ("c_high_steps", value<float>(&c_high_steps), "")
00103     ("c_r1_min", value<float>(&c_r1_min), "")
00104     ("c_r1_max", value<float>(&c_r1_max), "")
00105     ("c_r2_min", value<float>(&c_r2_min), "")
00106     ("c_r2_max", value<float>(&c_r2_max), "")
00107     ("c1_steps", value<float>(&c1_steps), "")
00108     ("c2_steps", value<float>(&c2_steps), "")
00109 
00110     ("r_low_min", value<float>(&r_low_min), "")
00111     ("r_low_max", value<float>(&r_low_max), "")
00112     ("r_low_steps", value<float>(&r_low_steps), "")
00113     ("r_high_min", value<float>(&r_high_min), "")
00114     ("r_high_max", value<float>(&r_high_max), "")
00115     ("r_high_steps", value<float>(&r_high_steps), "")
00116     ("r_r1_min", value<float>(&r_r1_min), "")
00117     ("r_r1_max", value<float>(&r_r1_max), "")
00118     ("r_r2_min", value<float>(&r_r2_min), "")
00119     ("r_r2_max", value<float>(&r_r2_max), "")
00120     ("r1_steps", value<float>(&r1_steps), "")
00121     ("r2_steps", value<float>(&r2_steps), "")
00122     ;
00123 
00124   positional_options_description p_opt;
00125   p_opt.add("folder", 1);
00126   variables_map vm;
00127   store(command_line_parser(argc, argv).options(options).positional(p_opt).run(), vm);
00128   notify(vm);
00129 
00130   if (vm.count("help") || !vm.count("folder"))
00131   {
00132     cout << options << endl;
00133     exit(0);
00134   }
00135   ifstream ifs(config_file_.c_str());
00136   if (!ifs)
00137   {
00138     ifstream ifs2( (folder_ + "evaluate_settings.cfg").c_str() );
00139     if (!ifs2)
00140     {
00141       cout << "cannot open config file!" << endl;
00142     }
00143     else
00144     {
00145       store(parse_config_file(ifs2, options), vm);
00146       notify(vm);
00147     }
00148   }
00149   else
00150   {
00151     store(parse_config_file(ifs, options), vm);
00152     notify(vm);
00153   }
00154   if (vm.count("pc")) en_pc = true;
00155   if (vm.count("rsd")) en_rsd = true;
00156 }
00157 
00158 int main (int argc, char** argv)
00159 {
00160   readOptions(argc, argv);
00161   PointCloud<PointXYZRGB>::Ptr p(new PointCloud<PointXYZRGB>);
00162   PointCloud<PrincipalCurvatures>::Ptr pc(new PointCloud<PrincipalCurvatures>);
00163   PointCloud<PrincipalRadiiRSD>::Ptr rsd(new PointCloud<PrincipalRadiiRSD>);
00164 
00165   for (size_t i = 0; i < scenes_.size(); i++)
00166   {
00167     vector<string> pc_pcds, rsd_pcds;
00168     getAllPcdFilesInDirectory(folder_ + "0_pc/" + scenes_[i] + "/", pc_pcds);
00169     getAllPcdFilesInDirectory(folder_ + "0_rsd/" + scenes_[i] + "/", rsd_pcds);
00170 
00171     cout << "Scene " << scenes_[i] << ": Found " << pc_pcds.size() << " pcd files for PC" << endl;
00172     cout << "Scene " << scenes_[i] << ": Found " << rsd_pcds.size() << " pcd files for RSD" << endl;
00173 
00174     if (en_pc)
00175     {
00176       string logfile = folder_ + "results/" + scenes_[i] + "/res_pc_" +
00177         cob_3d_mapping_common::createTimestamp() + ".csv";
00178 
00179       cob_3d_mapping_common::writeHeader(logfile,"c_low","c_high","c_r1(cyl/sph)","c_r2(cor/edge)");
00180 
00181       for (size_t j = 0; j < pc_pcds.size(); j++)
00182       {
00183         bool is_mls;
00184         string rn, rf;
00185         cob_3d_mapping_common::parseFileName(pc_pcds[j], rn, rf, is_mls);
00186         io::loadPCDFile<PointXYZRGB>(folder_+"normals/"+scenes_[i]+"/mls_"+scenes_[i]+
00187                                      "_"+rn+"rn.pcd",*p);
00188         rn = "0."+rn;
00189         rf = "0."+rf;
00190         cout << scenes_[i] <<";"<< rn <<";"<< rf <<";"<< is_mls << endl;
00191         io::loadPCDFile<PrincipalCurvatures>(folder_+"0_pc/"+scenes_[i]+"/"+pc_pcds[j], *pc);
00192 
00193 
00194         int exp_rgb, pre_rgb;
00195         float c_max,c_min;
00196 
00197         for (float c_low = c_low_min; c_low <= c_low_max; c_low += c_low_steps)
00198         {
00199           for (float c_high = c_high_min; c_high <= c_high_max; c_high += c_high_steps)
00200           {
00201             for (float c_r1 = c_r1_min; c_r1 <= c_r1_max; c_r1 += c1_steps)
00202             {
00203               for (float c_r2 = c_r2_min; c_r2 <= c_r2_max; c_r2 += c2_steps)
00204               {
00205                 cout << c_low <<" | "<< c_high <<" | "<< c_r1 <<" | "<< c_r2 <<endl;
00206                 // new instance class for holding evaluation results:
00207                 cob_3d_mapping_common::LabelResults stats(rn,rf,is_mls);
00208                 for (size_t idx = 0; idx < p->points.size(); idx++)
00209                 {
00210                   exp_rgb = *reinterpret_cast<int*>(&p->points[idx].rgb); // expected label
00211                   c_max = pc->points[idx].pc1;
00212                   c_min = pc->points[idx].pc2;
00213 
00214                   if ( c_max < c_low )
00215                   {
00216                     pre_rgb = LBL_PLANE;
00217                     if (exp_rgb != LBL_PLANE && exp_rgb != LBL_UNDEF) stats.fp[EVAL_PLANE]++;
00218                   }
00219                   else if (c_max > c_high)
00220                   {
00221                     if (c_max < c_r2 * c_min)
00222                     {
00223                       pre_rgb = LBL_COR;
00224                       if (exp_rgb != LBL_COR && exp_rgb != LBL_UNDEF) stats.fp[EVAL_COR]++;
00225                     }
00226                     else
00227                     {
00228                       pre_rgb = LBL_EDGE;
00229                       if (exp_rgb != LBL_EDGE && exp_rgb != LBL_UNDEF) stats.fp[EVAL_EDGE]++;
00230                     }
00231                     // special case:  combined class for corner and edge
00232                     if (exp_rgb != LBL_COR && exp_rgb != LBL_EDGE && exp_rgb != LBL_UNDEF)
00233                       stats.fp[EVAL_EDGECORNER]++;
00234                   }
00235                   else
00236                   {
00237                     if (c_max < c_r1 * c_min)
00238                     {
00239                       pre_rgb = LBL_SPH;
00240                       if (exp_rgb != LBL_SPH && exp_rgb != LBL_UNDEF) stats.fp[EVAL_SPH]++;
00241                     }
00242                     else
00243                     {
00244                       pre_rgb = LBL_CYL;
00245                       if (exp_rgb != LBL_CYL && exp_rgb != LBL_UNDEF) stats.fp[EVAL_CYL]++;
00246                     }
00247                     // special case:  combined class for sphere and cylinder
00248                     if (exp_rgb != LBL_SPH && exp_rgb != LBL_CYL && exp_rgb != LBL_UNDEF)
00249                       stats.fp[EVAL_CURVED]++;
00250                   }
00251 
00252                   switch(exp_rgb)
00253                   {
00254                   case LBL_PLANE:
00255                     if (pre_rgb != exp_rgb) stats.fn[EVAL_PLANE]++;
00256                     stats.exp[EVAL_PLANE]++;
00257                     break;
00258                   case LBL_EDGE:
00259                     if (pre_rgb != exp_rgb)
00260                     {
00261                       stats.fn[EVAL_EDGE]++;
00262                       if (pre_rgb != LBL_COR) stats.fn[EVAL_EDGECORNER]++;
00263                     }
00264                     stats.exp[EVAL_EDGE]++;
00265                     stats.exp[EVAL_EDGECORNER]++;
00266                     break;
00267                   case LBL_COR:
00268                     if (pre_rgb != exp_rgb)
00269                     {
00270                       stats.fn[EVAL_COR]++;
00271                       if (pre_rgb != LBL_EDGE) stats.fn[EVAL_EDGECORNER]++;
00272                     }
00273                     stats.exp[EVAL_COR]++;
00274                     stats.exp[EVAL_EDGECORNER]++;
00275                     break;
00276                   case LBL_SPH:
00277                     if (pre_rgb != exp_rgb)
00278                     {
00279                       stats.fn[EVAL_SPH]++;
00280                       if (pre_rgb != LBL_CYL) stats.fn[EVAL_CURVED]++;
00281                     }
00282                     stats.exp[EVAL_SPH]++;
00283                     stats.exp[EVAL_CURVED]++;
00284                     break;
00285                   case LBL_CYL:
00286                     if (pre_rgb != exp_rgb)
00287                     {
00288                       stats.fn[EVAL_CYL]++;
00289                       if (pre_rgb != LBL_SPH) stats.fn[EVAL_CURVED]++;
00290                     }
00291                     stats.exp[EVAL_CYL]++;
00292                     stats.exp[EVAL_CURVED]++;
00293                     break;
00294                   default:
00295                     stats.undef++;
00296                     break;
00297                   }
00298                 }
00299 
00300                 stats.calcResults();
00301                 stats.writeToFile(logfile, c_low, c_high, c_r1, c_r2);
00302               }
00303             }
00304           }
00305         }
00306       }
00307     }
00308 
00309     if (en_rsd)
00310     {
00311       string logfile = folder_ + "results/" + scenes_[i] + "/res_rsd_" +
00312         cob_3d_mapping_common::createTimestamp() + ".csv";
00313       cob_3d_mapping_common::writeHeader(logfile,"r_low","r_high","r_r1(cyl/sph)","r_r2(cor/edge)");
00314 
00315       for (size_t j = 0; j < pc_pcds.size(); j++)
00316       {
00317         bool is_mls;
00318         string rn, rf;
00319         cob_3d_mapping_common::parseFileName(rsd_pcds[j], rn, rf, is_mls);
00320         io::loadPCDFile<PointXYZRGB>(folder_+"normals/"+scenes_[i]+"/mls_"+scenes_[i]+
00321                                      "_"+rn+"rn.pcd",*p);
00322         rn = "0."+rn;
00323         rf = "0."+rf;
00324         cout << scenes_[i] <<";"<< rn <<";"<< rf <<";"<< is_mls << endl;
00325         io::loadPCDFile<PrincipalRadiiRSD>(folder_+"0_rsd/"+scenes_[i]+"/"+rsd_pcds[j], *rsd);
00326 
00327         int exp_rgb, pre_rgb;
00328         float r_max,r_min;
00329 
00330         for (float r_low = r_low_min; r_low <= r_low_max; r_low += r_low_steps)
00331         {
00332           for (float r_high = r_high_min; r_high <= r_high_max; r_high += r_high_steps)
00333           {
00334             for (float r_r1 = r_r1_min; r_r1 <= r_r1_max; r_r1 += r1_steps)
00335             {
00336               for (float r_r2 = r_r2_min; r_r2 <= r_r2_max; r_r2 += r2_steps)
00337               {
00338                 cout << r_low <<" | "<< r_high <<" | "<< r_r1 <<" | "<< r_r2 <<endl;
00339                 // new instance class for holding evaluation results:
00340                 cob_3d_mapping_common::LabelResults stats(rn,rf,is_mls);
00341                 for (size_t idx = 0; idx < p->points.size(); idx++)
00342                 {
00343                   exp_rgb = *reinterpret_cast<int*>(&p->points[idx].rgb); // expected label
00344                   r_max = rsd->points[idx].r_max;
00345                   r_min = rsd->points[idx].r_min;
00346 
00347                   if ( r_min > r_high )
00348                   {
00349                     pre_rgb = LBL_PLANE;
00350                     if (exp_rgb != LBL_PLANE && exp_rgb != LBL_UNDEF) stats.fp[EVAL_PLANE]++;
00351                   }
00352                   else if (r_min < r_low)
00353                   {
00354                     if (r_max < r_r2 * r_min)
00355                     {
00356                       pre_rgb = LBL_COR;
00357                       if (exp_rgb != LBL_COR && exp_rgb != LBL_UNDEF) stats.fp[EVAL_COR]++;
00358                     }
00359                     else
00360                     {
00361                       pre_rgb = LBL_EDGE;
00362                       if (exp_rgb != LBL_EDGE && exp_rgb != LBL_UNDEF) stats.fp[EVAL_EDGE]++;
00363                     }
00364                     // special case:  combined class for corner and edge
00365                     if (exp_rgb != LBL_COR && exp_rgb != LBL_EDGE && exp_rgb != LBL_UNDEF)
00366                       stats.fp[EVAL_EDGECORNER]++;
00367                   }
00368                   else
00369                   {
00370                     if (r_max < r_r1 * r_min)
00371                     {
00372                       pre_rgb = LBL_SPH;
00373                       if (exp_rgb != LBL_SPH && exp_rgb != LBL_UNDEF) stats.fp[EVAL_SPH]++;
00374                     }
00375                     else
00376                     {
00377                       pre_rgb = LBL_CYL;
00378                       if (exp_rgb != LBL_CYL && exp_rgb != LBL_UNDEF) stats.fp[EVAL_CYL]++;
00379                     }
00380                     // special case:  combined class for sphere and cylinder
00381                     if (exp_rgb != LBL_SPH && exp_rgb != LBL_CYL && exp_rgb != LBL_UNDEF)
00382                       stats.fp[EVAL_CURVED]++;
00383                   }
00384 
00385                   switch(exp_rgb)
00386                   {
00387                   case LBL_PLANE:
00388                     if (pre_rgb != exp_rgb) stats.fn[EVAL_PLANE]++;
00389                     stats.exp[EVAL_PLANE]++;
00390                     break;
00391                   case LBL_EDGE:
00392                     if (pre_rgb != exp_rgb)
00393                     {
00394                       stats.fn[EVAL_EDGE]++;
00395                       if (pre_rgb != LBL_COR) stats.fn[EVAL_EDGECORNER]++;
00396                     }
00397                     stats.exp[EVAL_EDGE]++;
00398                     stats.exp[EVAL_EDGECORNER]++;
00399                     break;
00400                   case LBL_COR:
00401                     if (pre_rgb != exp_rgb)
00402                     {
00403                       stats.fn[EVAL_COR]++;
00404                       if (pre_rgb != LBL_EDGE) stats.fn[EVAL_EDGECORNER]++;
00405                     }
00406                     stats.exp[EVAL_COR]++;
00407                     stats.exp[EVAL_EDGECORNER]++;
00408                     break;
00409                   case LBL_SPH:
00410                     if (pre_rgb != exp_rgb)
00411                     {
00412                       stats.fn[EVAL_SPH]++;
00413                       if (pre_rgb != LBL_CYL) stats.fn[EVAL_CURVED]++;
00414                     }
00415                     stats.exp[EVAL_SPH]++;
00416                     stats.exp[EVAL_CURVED]++;
00417                     break;
00418                   case LBL_CYL:
00419                     if (pre_rgb != exp_rgb)
00420                     {
00421                       stats.fn[EVAL_CYL]++;
00422                       if (pre_rgb != LBL_SPH) stats.fn[EVAL_CURVED]++;
00423                     }
00424                     stats.exp[EVAL_CYL]++;
00425                     stats.exp[EVAL_CURVED]++;
00426                     break;
00427                   default:
00428                     stats.undef++;
00429                     break;
00430                   }
00431                 }
00432 
00433                 stats.calcResults();
00434                 stats.writeToFile(logfile, r_low, r_high, r_r1, r_r2);
00435               }
00436             }
00437           }
00438         }
00439       }
00440     }
00441   }
00442 
00443   return 0;
00444 }


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