pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PCDReader reader;
if (pcl::io::loadPCDFile("D:\\desktop_tempfile\\pcd\\apple_0.pcd", *cloud))
{
PCL_ERROR ("Couldn't read file pcd \n");
return (false);
}
Eigen::Matrix4f transform = Eigen::Matrix4f::Identity(); //4×4变换矩阵
float theta = M_PI; //绕x轴旋转180°,平移1.0
transform (1,1) = cos (theta);
transform (1,2) = -sin(theta);
transform (2,1) = sin (theta);
transform (2,2) = cos (theta);
transform (0,3) = 1.0;
pcl::PointCloud<pcl::PointXYZ>::Ptr transformed_cloud (new pcl::PointCloud<pcl::PointXYZ> ());
pcl::transformPointCloud (*cloud, *transformed_cloud, transform);//刚性变换的核心函数
pcl::visualization::PCLVisualizer viewer ("Matrix transformation example");
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> source_cloud_color_handler (cloud, 255, 255, 255);
viewer.addPointCloud (cloud, source_cloud_color_handler, "original_cloud");
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> transformed_cloud_color_handler (transformed_cloud, 230, 0, 0);
viewer.addPointCloud (transformed_cloud, transformed_cloud_color_handler, "transformed_cloud");
viewer.addCoordinateSystem (1.0, 0);
viewer.setBackgroundColor(0.1, 0.1, 0.1, 0);
viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "original_cloud");
viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "transformed_cloud");
while (!viewer.wasStopped ()) {
viewer.spinOnce ();
}
点云的刚性变换[微记]
最新推荐文章于 2023-12-17 22:30:14 发布