classify.cpp
Go to the documentation of this file.
00001 /*
00002  * classify_new.cpp
00003  *
00004  *  Created on: Jun 11, 2012
00005  *      Author: vsu
00006  */
00007 
00008 /*
00009  * classify.cpp
00010  *
00011  *  Created on: Apr 25, 2012
00012  *      Author: vsu
00013  */
00014 
00015 #include <pcl17/console/print.h>
00016 #include <pcl17/console/parse.h>
00017 #include <pcl17/sample_consensus/ransac.h>
00018 #include <pcl17/filters/passthrough.h>
00019 #include <pcl17/octree/octree.h>
00020 #include <pcl17/classification/PHVObjectClassifier.h>
00021 #include <pcl17/features/sgfall.h>
00022 #include <sac_3dof.h>
00023 #include <set>
00024 #include <pcl17/io/pcd_io.h>
00025 #include <ransac_simple.h>
00026 #include <pcl17/features/vfh.h>
00027 
00028 template<class FeatureType, class FeatureEstimatorType>
00029   void classify(string database_dir, string scene_file_name)
00030   {
00031 
00032     std::vector<std::string> st;
00033     boost::split(st, scene_file_name, boost::is_any_of("/"), boost::token_compress_on);
00034     std::string scene_name = st.at(st.size() - 1);
00035     scene_name = scene_name.substr(0, scene_name.size() - 4);
00036 
00037     std::string debug_folder = scene_name + "_debug/";
00038     std::string output_dir = scene_name + "_result/";
00039 
00040     pcl17::PHVObjectClassifier<pcl17::PointXYZ, pcl17::PointNormal, FeatureType> oc;
00041 
00042     typename pcl17::Feature<pcl17::PointNormal, FeatureType>::Ptr feature_estimator(new FeatureEstimatorType);
00043     oc.setFeatureEstimator(feature_estimator);
00044 
00045     oc.setDebug(true);
00046     oc.setDatabaseDir(database_dir);
00047     oc.loadFromFile();
00048 
00049     oc.setDebugFolder(debug_folder);
00050 
00051     pcl17::PointCloud<pcl17::PointXYZ>::Ptr cloud(new pcl17::PointCloud<pcl17::PointXYZ>);
00052 
00053     pcl17::io::loadPCDFile(scene_file_name, *cloud);
00054     oc.setScene(cloud, 2.4);
00055 
00056     oc.classify();
00057 
00058     map<string, vector<pcl17::PointCloud<pcl17::PointNormal>::Ptr> > objects = oc.getFoundObjects();
00059 
00060     typedef typename map<string, vector<pcl17::PointCloud<pcl17::PointNormal>::Ptr> >::value_type vt;
00061 
00062     boost::filesystem::path out_path(output_dir);
00063 
00064     if (boost::filesystem::exists(out_path))
00065     {
00066       boost::filesystem::remove_all(out_path);
00067     }
00068 
00069     boost::filesystem::create_directories(out_path);
00070 
00071     BOOST_FOREACH(vt &v, objects)
00072 {    for(size_t i=0; i<v.second.size(); i++)
00073     {
00074       std::stringstream ss;
00075       ss << output_dir << v.first << i << ".pcd";
00076       std::cerr << "Writing to file " << ss.str() << std::endl;
00077       pcl17::io::savePCDFileASCII(ss.str(), *v.second[i]);
00078     }
00079   }
00080 
00081 }
00082 
00083 int main(int argc, char** argv)
00084 {
00085 
00086   if (argc < 5)
00087   {
00088     PCL17_INFO ("Usage %s -scene_file_name /dir/with/pointclouds -database_dir /where/to/put/database [options]\n", argv[0]);
00089     return -1;
00090   }
00091 
00092   std::string database_dir;
00093   std::string scene_file_name;
00094   std::string features = "sgf";
00095 
00096   pcl17::console::parse_argument(argc, argv, "-database_dir", database_dir);
00097   pcl17::console::parse_argument(argc, argv, "-scene_file_name", scene_file_name);
00098 
00099   pcl17::console::parse_argument(argc, argv, "-features", features);
00100 
00101   if (features == "sgf")
00102   {
00103     classify<pcl17::Histogram<pcl17::SGFALL_SIZE>,
00104         pcl17::SGFALLEstimation<pcl17::PointNormal, pcl17::Histogram<pcl17::SGFALL_SIZE> > > (database_dir, scene_file_name
00105 
00106     );
00107   }
00108   else if (features == "esf")
00109   {
00110     classify<pcl17::ESFSignature640, pcl17::ESFEstimation<pcl17::PointNormal, pcl17::ESFSignature640> > (database_dir,
00111                                                                                                  scene_file_name);
00112   }
00113   else if (features == "vfh")
00114   {
00115     classify<pcl17::VFHSignature308, pcl17::VFHEstimation<pcl17::PointNormal, pcl17::PointNormal, pcl17::VFHSignature308> > (
00116                                                                                                                    database_dir,
00117                                                                                                                    scene_file_name);
00118   }
00119   else
00120   {
00121     std::cerr << "Unknown feature type " << features << " specified" << std::endl;
00122   }
00123 
00124   return 0;
00125 }
00126 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


furniture_classification
Author(s): Vladyslav Usenko
autogenerated on Sun Oct 6 2013 12:12:30