在pcl中使用矩阵进行点云变换

在自己项目中创建一个cpp文件

复制以下代码:

#include <iostream>

#include <pcl/io/pcd_io.h>
#include <pcl/io/ply_io.h>
#include <pcl/point_cloud.h>
#include <pcl/console/parse.h>
#include <pcl/common/transforms.h>
#include <pcl/visualization/pcl_visualizer.h>

 // This function displays the help
 void
 showHelp(char * program_name)
 {
   std::cout << std::endl;
   std::cout << "Usage: " << program_name << " cloud_filename.[pcd|ply]" << std::endl;
   std::cout << "-h:  Show this help." << std::endl;
 }
 
 // This is the main function
 int
 main (int argc, char** argv)
 {
 
   // Show help
   if (pcl::console::find_switch (argc, argv, "-h") || pcl::console::find_switch (argc, argv, "--help")) {
     showHelp (argv[0]);
     return 0;
   }
 
   // Fetch point cloud filename in arguments | Works with PCD and PLY files
   std::vector<int> filenames;
   bool file_is_pcd = false;
 
   filenames = pcl::console::parse_file_extension_argument (argc, argv, ".ply");
 
   if (filenames.size () != 1)  {
     filenames = pcl::console::parse_file_extension_argument (argc, argv, ".pcd");
 
     if (filenames.size () != 1) {
       showHelp (argv[0]);
       return -1;
     } else {
       file_is_pcd = true;
     }
   }
 
   // Load file | Works with PCD and PLY files
   pcl::PointCloud<pcl::PointXYZ>::Ptr source_cloud (new pcl::PointCloud<pcl::PointXYZ> ());
 
   if (file_is_pcd) {
     if (pcl::io::loadPCDFile (argv[filenames[0]], *source_cloud) < 0)  {
       std::cout << "Error loading point cloud " << argv[filenames[0]] << std::endl << std::endl;
       showHelp (argv[0]);
       return -1;
     }
   } else {
     if (pcl::io::loadPLYFile (argv[filenames[0]], *source_cloud) < 0)  {
       std::cout << "Error loading point cloud " << argv[filenames[0]] << std::endl << std::endl;
       showHelp (argv[0]);
       return -1;
     }
   }
 
   /* Reminder: how transformation matrices work :
 
            |-------> This column is the translation
     | 1 0 0 x |  \
     | 0 1 0 y |   }-> The identity 3x3 matrix (no rotation) on the left
     | 0 0 1 z |  /
     | 0 0 0 1 |    -> We do not use this line (and it has to stay 0,0,0,1)
 
     METHOD #1: Using a Matrix4f
     This is the "manual" method, perfect to understand but error prone !
   */
   Eigen::Matrix4f transform_1 = Eig
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

目标成为slam大神

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值