之前查读取pcd的文件,大多数是用python的open3d来进行读取,但是这样读取到的信息,好像只能够得到 pcd.points,和pcd.colors, 但是如果想要把pcd中的信息都拿到呢,比如我保存的时候,pcd中的点云的类型是下面这样的
struct PointXYZIRPYT
{
PCL_ADD_POINT4D
PCL_ADD_INTENSITY; // preferred way of adding a XYZ+padding
float roll;
float pitch;
float yaw;
double time;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW // make sure our new allocators are aligned
} EIGEN_ALIGN16; // enforce SSE padding for correct memory alignment
POINT_CLOUD_REGISTER_POINT_STRUCT (PointXYZIRPYT,
(float, x, x) (float, y, y)
(float, z, z) (float, intensity, intensity)
(float, roll, roll) (float, pitch, pitch) (float, yaw, yaw)
(double, time, time))
typedef PointXYZIRPYT PointT;
下面是一种用c++能够正确读取到pcd中所用维度信息的一种方法.
这里我的 pcd文件实际上就是存储了 pose信息,x,y,z就相当于平移,基于roll, pitch, yaw
又可以算出来旋转矩阵,而时间信息可以对应到具体的是哪一桢.
完整的读取自定义的pcd的文件代码如图所示.
#include <iostream>
#include <string>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h>
using namespace std;
//需要自己定义一个类型来实现读取
struct PointXYZIRPYT
{
PCL_ADD_POINT4D
PCL_ADD_INTENSITY; // preferred way of adding a XYZ+padding
float roll;
float pitch;
float yaw;
double time;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW // make sure our new allocators are aligned
} EIGEN_ALIGN16; // enforce SSE padding for correct memory alignment
POINT_CLOUD_REGISTER_POINT_STRUCT (PointXYZIRPYT,
(float, x, x) (float, y, y)
(float, z, z) (float, intensity, intensity)
(float, roll, roll) (float, pitch, pitch) (float, yaw, yaw)
(double, time, time))
typedef PointXYZIRPYT PointT;
int main (int argc, char** argv){
pcl::PointCloud<PointT>::Ptr cloud (new pcl::PointCloud<PointT>);
std::string dir = "/home/qiaofeng/";
std::string filename = "transformations.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+=1)
printf("%8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f %8.3f \n",
cloud->points[i].x,
cloud->points[i].y,
cloud->points[i].z,
cloud->points[i].intensity,
cloud->points[i].roll,
cloud->points[i].pitch,
cloud->points[i].yaw,
cloud->points[i].time
);
//pcl::visualization::PCLVisualizer viewer("Cloud viewer");
//viewer.setCameraPosition(0,0,-3.0,0,-1,0);
//viewer.addCoordinateSystem(0.3);
//viewer.addPointCloud(cloud);
//while(!viewer.wasStopped())
//viewer.spinOnce(100);
return (0);
}
这里我的 CMake如下
cmake_minimum_required(VERSION 2.8)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_FLAGS "-std=c++11 -O2")
# opencv
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
# eigen
include_directories("/usr/include/eigen3/")
# pcl
find_package(PCL REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(read_pcd read_pcd.cpp)
target_link_libraries(read_pcd ${OpenCV_LIBS} ${PCL_LIBRARIES})
按照正常的编译,然后 ./read_pcd
运行出来如下所示,这里我并没有进行可视化.
-178.142 83.001 -0.183 143.000 0.052 0.028 2.696 1317275787.240
-179.187 83.493 -0.197 144.000 0.054 0.029 2.698 1317275787.448
-180.181 83.969 -0.207 145.000 0.057 0.026 2.700 1317275787.655
-181.120 84.399 -0.210 146.000 0.054 0.026 2.702 1317275787.863
-182.849 85.200 -0.230 147.000 0.058 0.026 2.705 1317275788.278
-184.476 85.941 -0.247 148.000 0.053 0.023 2.707 1317275788.694
-186.083 86.675 -0.255 149.000 0.051 0.023 2.709 1317275789.109
-187.638 87.390 -0.265 150.000 0.054 0.023 2.710 1317275789.524
-189.146 88.069 -0.278 151.000 0.051 0.022 2.709 1317275789.940
-190.583 88.737 -0.286 152.000 0.052 0.023 2.706 1317275790.355
-191.982 89.385 -0.297 153.000 0.053 0.026 2.704 1317275790.770
-193.345 90.032 -0.316 154.000 0.059 0.028 2.701 1317275791.185
-194.698 90.662 -0.330 155.000 0.055 0.028 2.698 1317275791.600
-196.044 91.309 -0.352 156.000 0.059 0.027 2.696 1317275792.015
-197.389 91.940 -0.377 157.000 0.056 0.031 2.693 1317275792.430
-198.741 92.587 -0.394 158.000 0.055 0.030 2.691 1317275792.845
-200.086 93.235 -0.418 159.000 0.054 0.027 2.690 1317275793.261
-201.435 93.871 -0.432 160.000 0.052 0.025 2.693 1317275793.676
-202.720 94.490 -0.457 161.000 0.054 0.029 2.695 1317275794.091
-203.777 94.967 -0.457 162.000 0.050 0.029 2.696 1317275794.506
-204.819 95.474 -0.474 163.000 0.050 0.025 2.697 1317275795.129
-205.753 95.926 -0.481 164.000 0.050 0.025 2.695 1317275795.959
-206.734 96.374 -0.504 165.000 0.043 0.024 2.694 1317275797.205