1、PCD文件與PLY文件互相轉換
這裏的PCD文件與PLY文件的互相轉換是簡單的將點的xyz座標以及rgb數據轉換,沒有涉及到網格化。如果想從PCD文件生成網格模型可以參考快速三角化:http://www.pclcn.org/study/shownews.php?lang=cn&id=111
a、PCD轉PLY
//PCD轉換爲PLY******************************************************
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include<pcl/PCLPointCloud2.h>
#include<iostream>
#include<string>
using namespace pcl;
using namespace pcl::io;
using namespace std;
int PCDtoPLYconvertor(string & input_filename ,string& output_filename)
{
pcl::PCLPointCloud2 cloud;
if (loadPCDFile(input_filename , cloud) < 0)
{
cout << "Error: 無法加載PCD文件!!!"<< endl;
return -1;
}
PLYWriter writer;
writer.write(output_filename, cloud, Eigen::Vector4f::Zero(), Eigen::Quaternionf::Identity(),true,true);
return 0;
}
int main()
{
string input_filename = "0.pcd";
string output_filename = "cloud_ply.ply";
PCDtoPLYconvertor(input_filename , output_filename);
cout << "pcd->ply轉換完畢!!!"<< endl;
return 0;
}
b、PLY轉PCD
//PLY轉換爲PCD******************************************************
#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/point_types.h>
#include <iostream>
using namespace std;
using namespace pcl;
using namespace io;
using namespace pcl::io;
bool
loadCloud (const std::string &filename, pcl::PCLPointCloud2 &cloud)
{
pcl::PLYReader reader;
if (reader.read (filename, cloud) < 0)
return (false);
return (true);
}
void
saveCloud (const std::string &filename, const pcl::PCLPointCloud2 &cloud, bool format)
{
pcl::PCDWriter writer;
writer.write (filename, cloud, Eigen::Vector4f::Zero (), Eigen::Quaternionf::Identity (), format);
}
int main()
{
pcl::PCLPointCloud2 cloud;
// Load the first file
if (!loadCloud ("bun_zipper.ply", cloud))
return (-1);
bool format = 1;
// Convert to PLY and save
saveCloud ("bun_zipper.pcd", cloud, format);
return (0);
}
2、計算程序運行時間
a、包含頭文件 #include <pcl/console/time.h>
b、定義 pcl::console::TicToc time; //定義對象
time.tic(); //開始記錄時間
/**這裏可以放想要計算時間的程序段**/c、std::cout<<time.toc()<<"ms"<<std::endl;
就可以以hao秒爲單位輸出“程序段”的運行時間。
運行代碼示例:
#include <iostream>
#include <pcl/console/time.h>
#include <windows.h>
int main()
{
pcl::console::TicToc time;
time.tic();
Sleep(1000);
std::cout << time.toc() << "ms" << std::endl;
return 0;
}
運行結果一般比實際程序運行時間大3 ms左右3、ICP算法變種簡介
-
pcl::GeneralizedIterativeClosestPoint< PointSource, PointTarget > Class Template Reference 廣義迭代最近點算法
-
pcl::IterativeClosestPoint< PointSource, PointTarget, Scalar > Class Template Reference 點到點經典迭代最近點算法
-
pcl::IterativeClosestPointWithNormals< PointSource, PointTarget, Scalar > Class Template Reference 點到面迭代最近點算法
-
pcl::IterativeClosestPointNonLinear< PointSource, PointTarget, Scalar > Class Template Reference 非線性迭代最近點算法
-
pcl::JointIterativeClosestPoint< PointSource, PointTarget, Scalar > Class Template Reference 聯合迭代最近點算法
-
pcl::registration::IncrementalICP< PointT, Scalar > Class Template Reference 增量迭代最近點算法
簡介:
a、GeneralizedIterativeClosestPoint是一種ICP變體,它實現了Alex Segal等人描述的廣義迭代最近點算法。在http://www.robots.ox.ac.uk/~avsegal/resources/papers/Generalized_ICP.pdf該方法是基於使用無數成本函數來優化最近的點分配之後的對齊。 原始代碼使用GSL和ANN,而在我們中,我們使用特徵映射的BFGS和FLANN。
b、IterativeClosestPoint基於奇異值分解(SVD)估計變換,點到點的經典ICP算法。
該算法有幾個終止標準:
迭代次數已達到用戶最大次數迭代次數(通過setMaximumIterations)
前一個變換和當前估計變換之間的ε(差)小於用戶強制值(viasetTransformationEpsilon)
歐幾里德平方誤差的總和小於用戶定義的閾值(通過setEuclideanFitnessEpsilon)
c、IterativeClosestPointWithNormals迭代最近點與法線是一個特殊情況,默認情況下使用基於點到平面距離估計的變換。
d、IterativeClosestPointNonLinear是使用Levenberg-Marquardt優化後端的ICP變體。所得到的變換被優化爲四元數。
該算法有幾個終止標準:
迭代次數已達到用戶最大次數迭代次數(通過setMaximumIterations)
前一個變換與當前估計變換之間的ε(差)小於用戶施加的值(通過setTransformationEpsilon)
歐幾里德平方誤差的總和小於用戶定義的閾值(通過setEuclideanFitnessEpsilon)
e、JointIterativeClosestPoint將ICP擴展到共享相同轉換的多個幀。
這在使用多次觀察來解決相機外部特性時特別有用。 當給予一雙雲時,這就是到普通的ICP。
f、IncrementalICP增量迭代最近點類。
這個類提供了一種註冊雲流的方式,每個雲將與之前的雲對齊。