读取pcd文件 c++
//============================================================================
// Name : wgb.cpp
// Author : wgb
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
//#include <mutex>
//#include <thread>
#include <dirent.h>
#include <sys/stat.h>
#include <ros/ros.h>
#include <ros/spinner.h>
#include <sensor_msgs/CameraInfo.h>
#include <sensor_msgs/Image.h>
#include <cv_bridge/cv_bridge.h>
#include <image_transport/image_transport.h>
#include <image_transport/subscriber_filter.h>
#include <message_filters/subscriber.h>
#include <message_filters/synchronizer.h>
#include <message_filters/sync_policies/exact_time.h>
#include <kinect2_calibration/kinect2_calibration_definitions.h>
#include <kinect2_bridge/kinect2_definitions.h>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include "cv.h"
#include <pcl/visualization/cloud_viewer.h>
using namespace std;
int main (int argc, char** argv){
typedef pcl::PointXYZRGBA PointT;
pcl::PointCloud<PointT>::Ptr cloud (new pcl::PointCloud<PointT>);
std::string dir = "/home/wgb/Desktop/wgb_save_pic/color/";
std::string filename = "0010_cloud.pcd";
if (pcl::io::loadPCDFile<PointT> ((dir+filename), *cloud) == -1)
{
//* load the file
PCL_ERROR ("Couldn't read PCD file \n");
return (-1);
}
printf("Loaded %d data points from PCD\n",
cloud->width * cloud->height);
for (size_t i = 0; i < cloud->points.size (); i+=10000)
printf("%8.5f %8.5f %8.5f %5d %5d %5d %5d\n",
cloud->points[i].x,
cloud->points[i].y,
cloud->points[i].z,
cloud->points[i].r,
cloud->points[i].g,
cloud->points[i].b,
cloud->points[i].a
);
pcl::visualization::PCLVisualizer viewer("Cloud viewer");
viewer.setCameraPosition(0,0,-2,0,-1,0);
//viewer.setCameraPosition(0,0,-3.0,0,-1,0);
viewer.addCoordinateSystem(0.3);
viewer.addPointCloud(cloud);
while(!viewer.wasStopped())
viewer.spinOnce(100);
printf("eh");
return (0);
}