Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include <ros/ros.h>
00008 #include <sensor_msgs/PointCloud2.h>
00009 #include <iostream>
00010 #include <fstream>
00011 #include <sstream>
00012 #include <iomanip>
00013 #include <boost/foreach.hpp>
00014
00015
00016
00017
00018 int nImages = 0;
00019 std::ofstream rimage;
00020
00021 int callback(const sensor_msgs::PointCloud2ConstPtr& msg)
00022 {
00023 int nc=msg->width;
00024 int nr=msg->height;
00025 std::stringstream rimagefilename;
00026 rimagefilename << "frameTOFDepth" << std::setw(2) << std::setfill('0') << nImages << ".txt";
00027 std::cout << rimagefilename.str() << std::endl;
00028 rimage.open (rimagefilename.str().c_str(), std::ios::out);
00029 if (!rimage){
00030 std::cerr << "Unable to open the file:\n\t" << rimagefilename << std::endl;
00031 return 1;
00032 }
00033
00034 for (int ii=0;ii<nr;ii++) {
00035 for (int jj=0;jj<nc;jj++){
00036 int index2 = (ii)*nc +(jj);
00037 float *pstep2 = (float*)&msg->data[(index2) * msg->point_step];
00038
00039 rimage << ii << " " << jj << " " << pstep2[2]*1000 << std::endl;
00040 }
00041 }
00042
00043 rimage.close();
00044
00045
00046 nImages++;
00047 return 0;
00048 }
00049
00050 int main(int argc, char **argv)
00051 {
00052 ros::init(argc, argv, "listener");
00053 ros::NodeHandle nh;
00054
00055 ros::Subscriber sub = nh.subscribe<sensor_msgs::PointCloud2> ("/input", 1, callback);
00056 std::cout << "ini " << std::endl;
00057 ros::spin();
00058 std::cout << "end " << std::endl;
00059 return 0;
00060 }