1 // 定義相關變量 2 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_ptr (new pcl::PointCloud<pcl::PointXYZ>); 3 pcl::PointCloud<pcl::PointXYZ>& cloud = *cloud_ptr; //點雲 4 //初始化點雲數據PCD文件頭 5 cloud.width = depthHeight * depthWidth; 6 cloud.height = 1; 7 cloud.is_dense = false; 8 cloud.points.resize (cloud.width * cloud.height); 9 10 //顯示重建得到的點雲數據 11 pcl::visualization::CloudViewer viewer("Cloud Viewer"); 12 viewer.showCloud(cloud_ptr); 13 14 //保存點雲數據 15 pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud); 16 std::cerr << "Saved " << cloud.points.size () << " data points to test_pcd.pcd." << std::endl;