当前位置:网站首页>How to use normal distribution transformation for registration
How to use normal distribution transformation for registration
2022-07-21 21:05:00 【Amelie_ eleven】
(11.1.3 PCL Study ) How to use normal distribution transformation for registration
Code : The first 11 Chapter one 3 Folder
Report errors 1:
Assertion failed: point_representation_->isValid (point) && “Invalid (NaN, Inf) point coordinates given to radiusSearch!”, file C:\BuildAgent\work\1cb946cef51fc766\tags\pcl-1.6.0\kdtree\include\pcl/kdtree/impl/kdtree_flann.hpp, line 119
resolvent :
Find the problem :https://ask.csdn.net/questions/252527
Did not remove the NaN spot , You need to add two sentences after loading the point cloud file to remove the NaN Point code
Reference resources :https://blog.csdn.net/qq_36501182/article/details/79170438
removeNaNFromPointCloud The use of the class
pcl::removeNaNFromPointCloud(laserCloudIn, laserCloudIn, indices); The function has three arguments , Input point clouds , Output the point cloud and the corresponding reserved index .
load pcd Add... After the file :
std::vector<int>indices;
pcl::removeNaNFromPointCloud(*target_cloud, *target_cloud, indices);
Be careful target_cloud Corresponding to the named file name
Error reporting solution .
The complete code is as follows :
#include <iostream>
#include <thread>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/registration/ndt.h>//NDT The registration class corresponds to the header file
#include <pcl/filters/approximate_voxel_grid.h>// The filter class corresponds to the header file
#include <pcl/visualization/pcl_visualizer.h>
using namespace std::chrono_literals;
int
main(int argc, char** argv)
{
// Loading first scan of room.
pcl::PointCloud<pcl::PointXYZ>::Ptr target_cloud(new pcl::PointCloud<pcl::PointXYZ>);
if (pcl::io::loadPCDFile<pcl::PointXYZ>("room_scan1.pcd", *target_cloud) == -1)
{
PCL_ERROR("Couldn't read file room_scan1.pcd \n");
return (-1);
}
std::vector<int>indices;
pcl::removeNaNFromPointCloud(*target_cloud, *target_cloud, indices);
std::cout << "Loaded " << target_cloud->size() << " data points from room_scan1.pcd" << std::endl;
// Loading second scan of room from new perspective.
pcl::PointCloud<pcl::PointXYZ>::Ptr input_cloud(new pcl::PointCloud<pcl::PointXYZ>);
if (pcl::io::loadPCDFile<pcl::PointXYZ>("room_scan2.pcd", *input_cloud) == -1)
{
PCL_ERROR("Couldn't read file room_scan2.pcd \n");
return (-1);
}
/* std::vector<int>indices;*/
pcl::removeNaNFromPointCloud(*input_cloud, *input_cloud, indices);
std::cout << "Loaded " << input_cloud->size() << " data points from room_scan2.pcd" << std::endl;
// Filtering input scan to roughly 10% of original size to increase speed of registration.
pcl::PointCloud<pcl::PointXYZ>::Ptr filtered_cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::ApproximateVoxelGrid<pcl::PointXYZ> approximate_voxel_filter;
approximate_voxel_filter.setLeafSize(0.2, 0.2, 0.2);
approximate_voxel_filter.setInputCloud(input_cloud);
approximate_voxel_filter.filter(*filtered_cloud);
std::cout << "Filtered cloud contains " << filtered_cloud->size()
<< " data points from room_scan2.pcd" << std::endl;
// Initializing Normal Distributions Transform (NDT).
pcl::NormalDistributionsTransform<pcl::PointXYZ, pcl::PointXYZ> ndt;
// Setting scale dependent NDT parameters
// Setting minimum transformation difference for termination condition.
ndt.setTransformationEpsilon(0.01);
// Setting maximum step size for More-Thuente line search.
ndt.setStepSize(0.1);
//Setting Resolution of NDT grid structure (VoxelGridCovariance).
ndt.setResolution(1.0);
// Setting max number of registration iterations.
ndt.setMaximumIterations(35);// Set the maximum number of matching iterations , Before reaching this limit, the optimization program will be in epsilon Terminate at the transformation threshold
// Setting point cloud to be aligned.
ndt.setInputSource(filtered_cloud);// Set source point cloud
// Setting point cloud to be aligned to.
ndt.setInputTarget(target_cloud);// Set the target point cloud
// Set initial alignment estimate found using robot odometry.
Eigen::AngleAxisf init_rotation(0.6931, Eigen::Vector3f::UnitZ());
Eigen::Translation3f init_translation(1.79387, 0.720047, 0);
Eigen::Matrix4f init_guess = (init_translation * init_rotation).matrix();
// Calculating required rigid transform to align the input cloud to the target cloud.
pcl::PointCloud<pcl::PointXYZ>::Ptr output_cloud(new pcl::PointCloud<pcl::PointXYZ>);
ndt.align(*output_cloud, init_guess);
std::cout << "Normal Distributions Transform has converged:" << ndt.hasConverged()
<< " score: " << ndt.getFitnessScore() << std::endl;
// Transforming unfiltered, input cloud using found transform.
pcl::transformPointCloud(*input_cloud, *output_cloud, ndt.getFinalTransformation());
// Saving transformed input cloud.
pcl::io::savePCDFileASCII("room_scan2_transformed.pcd", *output_cloud);
// Initializing point cloud visualizer
pcl::visualization::PCLVisualizer::Ptr
viewer_final(new pcl::visualization::PCLVisualizer("3D Viewer"));
viewer_final->setBackgroundColor(0, 0, 0);
// Coloring and visualizing target cloud (red).
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>
target_color(target_cloud, 255, 0, 0);
viewer_final->addPointCloud<pcl::PointXYZ>(target_cloud, target_color, "target cloud");
viewer_final->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,
1, "target cloud");
// Coloring and visualizing transformed input cloud (green).
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>
output_color(output_cloud, 0, 255, 0);
viewer_final->addPointCloud<pcl::PointXYZ>(output_cloud, output_color, "output cloud");
viewer_final->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,
1, "output cloud");
// Starting visualizer
viewer_final->addCoordinateSystem(1.0, "global");
viewer_final->initCameraParameters();
// Wait until visualizer window is closed.
while (!viewer_final->wasStopped())
{
viewer_final->spinOnce(100);
std::this_thread::sleep_for(100ms);
}
return (0);
}
Running results :
Obviously, the registration of two point cloud files is unsuccessful
边栏推荐
- ECSHOP vulnerability recurrence
- TP5 import Excel to database
- PHP Baidu face detection API face value scoring (source code is directly available)
- Compile and run typescript with vscode plug-in coderunner. When the output has Chinese, there is garbled code
- Redis(五) - Redis企业实战之短信登录
- Web security -- file upload middleware parsing vulnerability
- DVWA [SQL injection] error injection learning record
- 2021-10-23
- Vulnhub-dc-4 target penetration record
- Solana项目学习(二): Escrow
猜你喜欢
随机推荐
Personal applet: Dream fate
攻防世界web题-shrine
SushiSwap的SushiMaker和SushiBar解读
PHP環境搭建(推薦寶塔面板)
2021-10-23
PHP basic syntax
Using curl to realize the requests of local and remote devices
MasterChef interpretation of sushiswap
【权限提升】 MSSQL提权方法
[reverse analysis] static analysis of malicious code
MetaForce原力元宇宙之我见,教你迅速搞懂滑落机制
Accelerate the large-scale application of UAV intelligent inspection, and speed up the intelligent construction of Fujian power transmission operation inspection
攻防世界web区 难度等级:2(upload1,web2,Web_php_include,supersqli,warmup)
墨者学院-WebShell文件上传分析(第3-5题)
WAP green legend building (pure version)
TP5 docking visa free FM payment interface
Web security -- file upload middleware parsing vulnerability
Typescript basic learning record
Buuctf n1book [Chapter 2 advanced web] file upload
[intranet penetration] cobaltstrike traffic encryption