Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #include <pcl/io/image_grabber.h>
00040 #include <pcl/console/parse.h>
00041 #include <pcl/console/print.h>
00042 #include <pcl/visualization/boost.h>
00043 #include <pcl/visualization/cloud_viewer.h>
00044 #include <pcl/visualization/image_viewer.h>
00045 #include <pcl/io/pcd_io.h>
00046
00047 using pcl::console::print_error;
00048 using pcl::console::print_info;
00049 using pcl::console::print_value;
00050
00051
00052 boost::shared_ptr<pcl::ImageGrabber<pcl::PointXYZRGBA> > grabber;
00053 pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr cloud_;
00054 std::string out_folder;
00055 int counter;
00056
00057 void
00058 printHelp (int, char **argv)
00059 {
00060 print_error ("Syntax is: %s <options>\n", argv[0]);
00061 print_info (" where options are:\n");
00062 print_info ("\t-rgb_dir \t<directory_path> \t= directory path to RGB images to be read from\n");
00063 print_info ("\t-depth_dir \t<directory_path> \t= directory path to Depth images to be read from\n");
00064 print_info ("\t-out_dir \t<directory_path> \t= directory path to put the pcd files\n");
00065
00066 print_info ("\n");
00067 }
00068
00069 struct EventHelper
00070 {
00071 void
00072 cloud_cb (const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr & cloud)
00073 {
00074 std::stringstream ss;
00075 ss << out_folder << "/" << grabber->getPrevDepthFileName() << ".pcd";
00076 pcl::io::savePCDFileASCII (ss.str(), *cloud);
00077 }
00078 };
00079
00080
00081 int
00082 main (int argc, char** argv)
00083 {
00084 counter = 0;
00085 out_folder.clear();
00086
00087 if (argc > 1)
00088 {
00089 for (int i = 1; i < argc; i++)
00090 {
00091 if (std::string (argv[i]) == "-h")
00092 {
00093 printHelp (argc, argv);
00094 return (-1);
00095 }
00096 }
00097 }
00098
00099 float frames_per_second = 0;
00100 pcl::console::parse (argc, argv, "-fps", frames_per_second);
00101 if (frames_per_second < 0)
00102 frames_per_second = 0.0;
00103
00104 float focal_length = 525.0;
00105 pcl::console::parse (argc, argv, "-focal", focal_length);
00106
00107 std::string depth_path = "";
00108 pcl::console::parse_argument (argc, argv, "-depth_dir", depth_path);
00109
00110 std::string rgb_path = "";
00111 pcl::console::parse_argument (argc, argv, "-rgb_dir", rgb_path);
00112
00113 pcl::console::parse_argument (argc, argv, "-out_dir", out_folder);
00114
00115 if (out_folder == "" || !boost::filesystem::exists (out_folder))
00116 {
00117 PCL_INFO("No correct directory was given with the -out_dir flag. Setting to current dir\n");
00118 out_folder = "./";
00119 }
00120 else
00121 PCL_INFO("Using %s as output dir", out_folder.c_str());
00122
00123 if (rgb_path != "" && depth_path != "" && boost::filesystem::exists (rgb_path) && boost::filesystem::exists (depth_path))
00124 {
00125 grabber.reset (new pcl::ImageGrabber<pcl::PointXYZRGBA> (depth_path, rgb_path, frames_per_second, false));
00126 }
00127 else
00128 {
00129 PCL_INFO("No directory was given with the -<rgb/depth>_dir flag.");
00130 printHelp (argc, argv);
00131 return (-1);
00132 }
00133 grabber->setDepthImageUnits (float (1E-3));
00134
00135
00136 EventHelper h;
00137 boost::function<void(const pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr&) > f = boost::bind (&EventHelper::cloud_cb, &h, _1);
00138 boost::signals2::connection c1 = grabber->registerCallback (f);
00139
00140 do
00141 {
00142 grabber->trigger();
00143 }
00144 while (!grabber->atLastFrame());
00145 grabber->trigger();
00146 grabber->stop ();
00147 }
00148