ply_to_pcd.cpp
Go to the documentation of this file.
00001 
00064 #include <pcl/io/pcd_io.h>
00065 #ifdef GICP_ENABLE
00066 #include <pcl/io/ply_io.h>
00067 #endif
00068 #include <pcl/point_types.h>
00069 #include <sys/stat.h>
00070 #include <ros/assert.h>
00071 #include <ros/console.h>
00072 #include <iostream>
00073 #include <fstream>
00074 
00075 int main(int argc, char **argv) {
00076   if(argc<4) {
00077     std::cerr<<"please specify *.img *.img -> *.pcd\n";
00078     return 1;
00079   }
00080 
00081   sensor_msgs::Image img,depth;
00082 
00083   {
00084     FILE *fp = fopen(argv[2], "rb");
00085     if(!fp) {
00086       ROS_ERROR("couldn't open image file");
00087       return 0;
00088     }
00089 
00090     struct stat filestatus;
00091     stat(argv[2], &filestatus );
00092 
00093     uint8_t *up = new uint8_t[filestatus.st_size];
00094     fread(up,filestatus.st_size,1,fp);
00095 //    img.deserialize(up);
00096     delete up;
00097 
00098     fclose(fp);
00099   }
00100 
00101   {
00102     FILE *fp = fopen(argv[1], "rb");
00103     if(!fp) {
00104       ROS_ERROR("couldn't open depth file");
00105       return 0;
00106     }
00107 
00108     struct stat filestatus;
00109     stat(argv[2], &filestatus );
00110 
00111     uint8_t *up = new uint8_t[filestatus.st_size];
00112     fread(up,filestatus.st_size,1,fp);
00113 //    depth.deserialize(up);
00114     delete up;
00115 
00116     fclose(fp);
00117   }
00118 
00119   pcl::PointCloud<pcl::PointXYZRGB> pc;
00120 
00121   float focalLength = 525.0;
00122   float centerX = 319.5;
00123   float centerY = 239.5;
00124   float scalingFactor = 5000.0;
00125 
00126   depth.step/=depth.width;
00127   img.step/=img.width;
00128 
00129   ROS_ASSERT(depth.width==img.width);
00130   ROS_ASSERT(depth.height==img.height);
00131 
00132   for(int y=0; y<img.height; y++) {
00133     for(int x=0; x<img.width; x++) {
00134       pcl::PointXYZRGB p;
00135 
00136       p.z = *(uint16_t*)&depth.data[ (x+y*depth.width)*depth.step + 0] / scalingFactor;
00137       p.x = (x - centerX) * p.z / focalLength;
00138       p.y = (y - centerY) * p.z / focalLength;
00139 
00140       if(p.z==0) {
00141         p.z=p.y=p.x=std::numeric_limits<float>::quiet_NaN();
00142       }
00143 
00144       p.b = img.data[ (x+y*img.width)*img.step + 0];
00145       p.g = img.data[ (x+y*img.width)*img.step + 1];
00146       p.r = img.data[ (x+y*img.width)*img.step + 2];
00147 
00148       pc.points.push_back(p);
00149     }
00150   }
00151 
00152   pc.width  = img.width;
00153   pc.height = img.height;
00154 
00155   pcl::io::savePCDFileASCII(argv[3],pc);
00156 
00157   return 0;
00158 }


cob_3d_registration
Author(s): Joshua Hampp
autogenerated on Wed Aug 26 2015 11:02:36