1.pcd file --rabbit.pcd
Links: https://pan.baidu.com/s/1v6mjPjwd7fIqUSjlIGTIGQ
extraction code: zspx
New Project pcl
rabbit.pcd and pcl.cpp in the same directory
2. Read the file
(1) Display Data
#include <the iostream> #include <PCL / IO / pcd_io.h> #include <PCL / point_types.h> int main ( int argc, char ** the argv) { // create a pointer called cloud storage XYZ type of point cloud data PCL PointCloud :: <PCL PointXYZ ::> :: the Ptr cloud ( new new PCL PointCloud :: <PCL :: PointXYZ> ); // // * open file cloud point IF (PCL :: IO :: loadPCDFile <PCL :: PointXYZ> ( " rabbit.pcd " , * Cloud) == - . 1 ) { PCL_ERROR ( " Could Not Read File rabbit.pcd \ n- " ); return(-1
); } std::cout << "Loaded:" << cloud->width*cloud->height<<"data points from test_pcd.pcd with the following fields:"<< std::endl; for (size_t i = 0; i < cloud->points.size(); ++i) { std::cout << " " << cloud->points[i].x << " " << cloud->points[i].y << " " << cloud->points[i].z << " " << std::endl; } system("pause"); return 0; }
File data on a show out
Description:
PointCloud is a base class in PCL, pcl :: PointCloud <pcl :: PointXYZ> :: Ptr is a shared pointer Boost
The data field PointCloud
width (int), if disorganized, unstructured point cloud data indicates the number of point cloud; if there is a point cloud data structure, sets line represents the point cloud data points.
height (int), if unstructured point cloud data, height = 1; if there is a point cloud data structure, height point cloud represents the total number of lines.
points (std :: vector) is stored as a dynamic array PointT type of data.
PointXYZ point is the most common data type, it contains only three-dimensional X, Y, Z coordinate information
X:points[i].x
size_t integer, an integer stored, a record size (size)
points.size () represents the point cloud data size
(2) Data Visualization
#include<iostream> #include<pcl/io/pcd_io.h> #include<pcl/point_types.h> #include <pcl/visualization/cloud_viewer.h> int main(int argc, char** argv) { pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); // //*打开点云文件 if (pcl::io::loadPCDFile<pcl::PointXYZ>("rabbit.pcd", *cloud) == -1) { PCL_ERROR("Couldn't read file rabbit.pcd\n"); return(-1); } std::cout << cloud->points.size() << std::endl; pcl::visualization::CloudViewer viewer("cloud viewer"); viewer.showCloud(cloud); while (!viewer.wasStopped()) { } system("pause"); return 0; }
operation result
Turn at the wheel
Modify the background color
#include<iostream> #include<pcl/io/pcd_io.h> #include<pcl/point_types.h> #include <pcl/visualization/cloud_viewer.h> void viewerOneOff(pcl::visualization::PCLVisualizer& viewer) { viewer.setBackgroundColor(1.0f, 0.5f, 1.0f); } int main(int argc, char** argv) { pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); //*打开点云文件 if (pcl::io::loadPCDFile<pcl::PointXYZ>("rabbit.pcd", *cloud) == -1) { PCL_ERROR("Couldn't read file rabbit.pcd\n"); return(-1); } std::cout << cloud->points.size() << std::endl; pcl::visualization::CloudViewer viewer("cloud viewer"); viewer.showCloud(cloud); viewer.runOnVisualizationThreadOnce(viewerOneOff); system("pause"); return 0; }
输出文字
#include<iostream> #include<pcl/io/pcd_io.h> #include<pcl/point_types.h> #include <pcl/visualization/cloud_viewer.h> int user_data; void viewerOneOff(pcl::visualization::PCLVisualizer& viewer) { viewer.setBackgroundColor(1.0f, 0.5f, 1.0f); } void viewerPsycho(pcl::visualization::PCLVisualizer& viewer) { static unsigned count = 0; std::stringstream ss; ss << "Once per viewer loop: " << count++; viewer.removeShape("text", 0); viewer.addText(ss.str(), 20, 100, "text", 0);//this is to set the coordination of text "Once per viewer loop:" user_data++; } int main(int argc, char** argv) { pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); //*打开点云文件 if (pcl::io::loadPCDFile<pcl::PointXYZ>("rabbit.pcd", *cloud) == -1) { PCL_ERROR("Couldn't read file rabbit.pcd\n"); return(-1); } std::cout << cloud->points.size() << std::endl; pcl::visualization::CloudViewer viewer("cloud viewer"); viewer.showCloud(cloud); viewer.runOnVisualizationThreadOnce(viewerOneOff); viewer.runOnVisualizationThread(viewerPsycho); system("pause"); return 0; }