标签:include PCL back pcl NDT2D model PointType ndt
正态分布变换基于统计的方法估计变换矩阵。
代码如下:
#include <pcl/console/parse.h>
#include <pcl/console/print.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/registration/ndt_2d.h>
#include <pcl/registration/transformation_estimation_lm.h>
#include <pcl/registration/warp_point_rigid_3d.h>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
typedef pcl::PointXYZ PointType;
typedef pcl::PointCloud<PointType> Cloud;
typedef Cloud::ConstPtr CloudConstPtr;
typedef Cloud::Ptr CloudPtr;
void
selfTest ()
{
CloudPtr model (new Cloud);
model->points.push_back (PointType (1,1,0));
model->points.push_back (PointType (4,4,0));
model->points.push_back (PointType (5,6,0));
model->points.push_back (PointType (3,3,0));
model->points.push_back (PointType (6,7,0));
model->points.push_back (PointType (7,11,0));
model->points.push_back (PointType (12,15,0));
model->points.push_back (PointType (7,12,0));
CloudPtr data (new Cloud);
data->points.push_back (PointType (3,1,0));
data->points.push_back (PointType (7,4,0));
data->points.push_back (PointType (9,6,0));
pcl::console::setVerbosityLevel (pcl::console::L_DEBUG);
pcl::NormalDistributionsTransform2D<PointType, PointType> ndt;
ndt.setMaximumIterations (40);
ndt.setGridCentre (Eigen::Vector2f (0,0));
ndt.setGridExtent (Eigen::Vector2f (20,20));
ndt.setGridStep (Eigen::Vector2f (20,20));
ndt.setOptimizationStepSize (Eigen::Vector3d (0.4,0.4,0.1));
ndt.setTransformationEpsilon (1e-9);
ndt.setInputTarget (model);
ndt.setInputSource (data);
CloudPtr tmp (new Cloud);
ndt.align (*tmp);
std::cout << ndt.getFinalTransformation () << std::endl;
}
int
main (int argc, char **argv)
{
int iter = 10;
double grid_step = 3.0;
double grid_extent = 25.0;
double optim_step = 1.0;
pcl::console::parse_argument (argc, argv, "-i", iter);
pcl::console::parse_argument (argc, argv, "-g", grid_step);
pcl::console::parse_argument (argc, argv, "-e", grid_extent);
pcl::console::parse_argument (argc, argv, "-s", optim_step);
std::vector<int> pcd_indices;
pcd_indices = pcl::console::parse_file_extension_argument (argc, argv, ".pcd");
CloudPtr model (new Cloud);
if (pcl::io::loadPCDFile (argv[pcd_indices[0]], *model) == -1)
{
std::cout << "Could not read file" << std::endl;
return -1;
}
std::cout << argv[pcd_indices[0]] << " width: " << model->width << " height: " << model->height << std::endl;
std::string result_filename (argv[pcd_indices[0]]);
result_filename = result_filename.substr (result_filename.rfind ("/") + 1);
try
{
pcl::io::savePCDFile (result_filename.c_str (), *model);
std::cout << "saving first model to " << result_filename << std::endl;
}
catch(pcl::IOException& e)
{
std::cerr << e.what() << std::endl;
}
Eigen::Matrix4f t (Eigen::Matrix4f::Identity ());
for (size_t i = 1; i < pcd_indices.size (); i++)
{
CloudPtr data (new Cloud);
if (pcl::io::loadPCDFile (argv[pcd_indices[i]], *data) == -1)
{
std::cout << "Could not read file" << std::endl;
return -1;
}
std::cout << argv[pcd_indices[i]] << " width: " << data->width << " height: " << data->height << std::endl;
//pcl::console::setVerbosityLevel(pcl::console::L_DEBUG);
pcl::NormalDistributionsTransform2D<PointType, PointType> ndt;
ndt.setMaximumIterations (iter);
ndt.setGridCentre (Eigen::Vector2f (15,0));
ndt.setGridExtent (Eigen::Vector2f (grid_extent,grid_extent));
ndt.setGridStep (Eigen::Vector2f (grid_step,grid_step));
ndt.setOptimizationStepSize (optim_step);
ndt.setTransformationEpsilon (1e-5);
ndt.setInputTarget (model);
ndt.setInputSource (data);
CloudPtr tmp (new Cloud);
ndt.align (*tmp);
t = t* ndt.getFinalTransformation ();
pcl::transformPointCloud (*data, *tmp, t);
std::cout << ndt.getFinalTransformation () << std::endl;
*model = *data;
try
{
std::string result_filename (argv[pcd_indices[i]]);
result_filename = result_filename.substr (result_filename.rfind ("/") + 1);
pcl::io::savePCDFileBinary (result_filename.c_str (), *tmp);
std::cout << "saving result to " << result_filename << std::endl;
}
catch(pcl::IOException& e)
{
std::cerr << e.what() << std::endl;
}
}
return 0;
}
来源:PCL官方示例
标签:include,PCL,back,pcl,NDT2D,model,PointType,ndt 来源: https://blog.csdn.net/com1098247427/article/details/120705309
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。