face_detection_apps_utils.h
Go to the documentation of this file.
00001 /*
00002  * face_detection_apps_utils.h
00003  *
00004  *  Created on: 22 Sep 2012
00005  *      Author: ari
00006  */
00007 
00008 #ifndef FACE_DETECTION_APPS_UTILS_H_
00009 #define FACE_DETECTION_APPS_UTILS_H_
00010 
00011 namespace face_detection_apps_utils
00012 {
00013   inline bool readMatrixFromFile(std::string file, Eigen::Matrix4f & matrix)
00014   {
00015 
00016     std::ifstream in;
00017     in.open (file.c_str (), std::ifstream::in);
00018     if (!in.is_open ())
00019     {
00020       return false;
00021     }
00022 
00023     char linebuf[1024];
00024     in.getline (linebuf, 1024);
00025     std::string line (linebuf);
00026     std::vector < std::string > strs_2;
00027     boost::split (strs_2, line, boost::is_any_of (" "));
00028 
00029     for (int i = 0; i < 16; i++)
00030     {
00031       matrix (i / 4, i % 4) = static_cast<float> (atof (strs_2[i].c_str ()));
00032     }
00033 
00034     return true;
00035   }
00036 
00037   inline bool sortFiles(const std::string & file1, const std::string & file2)
00038   {
00039     std::vector < std::string > strs1;
00040     boost::split (strs1, file1, boost::is_any_of ("/"));
00041 
00042     std::vector < std::string > strs2;
00043     boost::split (strs2, file2, boost::is_any_of ("/"));
00044 
00045     std::string id_1 = strs1[strs1.size () - 1];
00046     std::string id_2 = strs2[strs2.size () - 1];
00047 
00048     {
00049       std::vector < std::string > strs1;
00050       boost::split (strs1, id_1, boost::is_any_of ("_"));
00051 
00052       std::vector < std::string > strs2;
00053       boost::split (strs2, id_2, boost::is_any_of ("_"));
00054 
00055       std::string id_1 = strs1[strs1.size () - 1];
00056       std::string id_2 = strs2[strs2.size () - 1];
00057 
00058       size_t pos1 = id_1.find (".pcd");
00059       size_t pos2 = id_2.find (".pcd");
00060 
00061       id_1 = id_1.substr (0, pos1);
00062       id_2 = id_2.substr (0, pos2);
00063 
00064       return atoi (id_1.c_str ()) < atoi (id_2.c_str ());
00065     }
00066   }
00067 
00068   inline
00069   void getFilesInDirectory(bf::path & dir, std::string & rel_path_so_far, std::vector<std::string> & relative_paths, std::string & ext)
00070   {
00071     bf::directory_iterator end_itr;
00072     for (bf::directory_iterator itr (dir); itr != end_itr; ++itr)
00073     {
00074       //check if its a directory, then get models in it
00075       if (bf::is_directory (*itr))
00076       {
00077 #if BOOST_FILESYSTEM_VERSION == 3
00078         std::string so_far = rel_path_so_far + (itr->path().filename()).string() + "/";
00079 #else
00080         std::string so_far = rel_path_so_far + (itr->path ()).filename () + "/";
00081 #endif
00082 
00083         bf::path curr_path = itr->path ();
00084         getFilesInDirectory (curr_path, so_far, relative_paths, ext);
00085       } else
00086       {
00087         //check that it is a ply file and then add, otherwise ignore..
00088         std::vector < std::string > strs;
00089 #if BOOST_FILESYSTEM_VERSION == 3
00090         std::string file = (itr->path().filename()).string();
00091 #else
00092         std::string file = (itr->path ()).filename ();
00093 #endif
00094 
00095         boost::split (strs, file, boost::is_any_of ("."));
00096         std::string extension = strs[strs.size () - 1];
00097 
00098         if (extension.compare (ext) == 0)
00099         {
00100 #if BOOST_FILESYSTEM_VERSION == 3
00101           std::string path = rel_path_so_far + (itr->path().filename()).string();
00102 #else
00103           std::string path = rel_path_so_far + (itr->path ()).filename ();
00104 #endif
00105 
00106           relative_paths.push_back (path);
00107         }
00108       }
00109     }
00110   }
00111 
00112   void displayHeads(std::vector<Eigen::VectorXf> & heads, pcl::visualization::PCLVisualizer & vis)
00113   {
00114     for (size_t i = 0; i < heads.size (); i++)
00115     {
00116       std::stringstream name;
00117       name << "sphere" << i;
00118       pcl::PointXYZ center_point;
00119       center_point.x = heads[i][0];
00120       center_point.y = heads[i][1];
00121       center_point.z = heads[i][2];
00122       vis.addSphere (center_point, 0.02, 0, 255, 0, name.str ());
00123 
00124       pcl::ModelCoefficients cylinder_coeff;
00125       cylinder_coeff.values.resize (7); // We need 7 values
00126       cylinder_coeff.values[0] = center_point.x;
00127       cylinder_coeff.values[1] = center_point.y;
00128       cylinder_coeff.values[2] = center_point.z;
00129 
00130       Eigen::Vector3f vec = Eigen::Vector3f::UnitZ () * -1.f;
00131       Eigen::Matrix3f matrixxx;
00132 
00133       matrixxx = Eigen::AngleAxisf (heads[i][3], Eigen::Vector3f::UnitX ()) * Eigen::AngleAxisf (heads[i][4], Eigen::Vector3f::UnitY ())
00134           * Eigen::AngleAxisf (heads[i][5], Eigen::Vector3f::UnitZ ());
00135 
00136       vec = matrixxx * vec;
00137 
00138       cylinder_coeff.values[3] = vec[0];
00139       cylinder_coeff.values[4] = vec[1];
00140       cylinder_coeff.values[5] = vec[2];
00141 
00142       cylinder_coeff.values[6] = 0.01f;
00143       name << "cylinder";
00144       vis.addCylinder (cylinder_coeff, name.str ());
00145     }
00146   }
00147 }
00148 
00149 #endif /* FACE_DETECTION_APPS_UTILS_H_ */


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:23:56