8 #include <pcl/io/pcd_io.h>
9 #include <pcl/point_types.h>
13 #include <opencv2/highgui/highgui.hpp>
18 int main(
int argc,
char **argv) {
22 std::cout <<
"Usage:\n\n rgbd_to_pcd FILENAME.rgbd [FILENAME2.rgbd ...]\n\n";
26 for (
int i=1; i < argc; ++i)
32 f_in.
open(name.
c_str(), std::ifstream::binary);
45 pcl::PointCloud<pcl::PointXYZRGB> cloud;
50 cloud.is_dense =
false;
51 cloud.resize (cloud.width * cloud.height);
56 double half_height = 0.5 * cloud.height;
57 double half_width = 0.5 * cloud.width;
58 for (uint i=0; i < cloud.height; ++i)
60 for (uint j=0; j < cloud.width; ++j)
62 cv::Vec3b bgr = image.
getRGBImage().at<cv::Vec3b>(i,j);
65 cloud.at(j,i).x = (-half_width+j) * d / fx;
66 cloud.at(j,i).y = (-half_height+i) * d / fy;
68 cloud.at(j,i).r = bgr[2];
69 cloud.at(j,i).g = bgr[1];
70 cloud.at(j,i).b = bgr[0];
75 name = name.
substr(0, lastindex);
79 pcl::io::savePCDFileASCII (pcd_filename, cloud);
80 std::cout <<
"Saved " << cloud.size () <<
" data points to " << pcd_filename <<
std::endl;