image_grabber_saver.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2011, Willow Garage, Inc.
00006  *  Copyright (c) 2012-, Open Perception, Inc.
00007  *  
00008  *  All rights reserved.
00009  *
00010  *  Redistribution and use in source and binary forms, with or without
00011  *  modification, are permitted provided that the following conditions
00012  *  are met:
00013  *
00014  *   * Redistributions of source code must retain the above copyright
00015  *     notice, this list of conditions and the following disclaimer.
00016  *   * Redistributions in binary form must reproduce the above
00017  *     copyright notice, this list of conditions and the following
00018  *     disclaimer in the documentation and/or other materials provided
00019  *     with the distribution.
00020  *   * Neither the name of the copyright holder(s) nor the names of its
00021  *     contributors may be used to endorse or promote products derived
00022  *     from this software without specific prior written permission.
00023  *
00024  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  *  POSSIBILITY OF SUCH DAMAGE.
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 //boost::mutex mutex_;
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   //print_info ("\t-fps frequency           = frames per second\n");
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; // 0 means only if triggered!
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   //grabber->setFocalLength(focal_length); // FIXME
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(); // Attempt to process the last frame
00146   grabber->stop ();
00147 }
00148 /* ]--- */


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:24:55