点云技术相关产学研社区

 找回密码
 立即注册加入PCL中国点云技术相关产学研社区

扫一扫,访问微社区

查看: 2239|回复: 1

ROS下点云转换和存储

[复制链接]
发表于 2017-10-3 11:52:25 | 显示全部楼层 |阅读模式
一些全局变量:
typedef pcl::PointXYZRGB PointT;typedef pcl::PointCloud<PointT> PointCloudT;

PointCloudT::Ptr cloud(new PointCloudT);
PointCloudT cloud_out;
tf::TransformListener* tf_listener;
std::string world_frame_id;
std::string frame_id;
std::string path;

回调函数:
void
cloud_cb (const PointCloudT::ConstPtr& callback_cloud)
{
  *cloud = *callback_cloud;
  frame_id = cloud->header.frame_id;
  std::stringstream ss;
  std::string s1;
  ss<<ros::Time::now();
  s1=ss.str();
       
  //获取转换信息
  tf::StampedTransform transform;
  try
  {
    tf_listener->lookupTransform(world_frame_id, frame_id, ros::Time(0), transform);
  }
  catch (tf::TransformException ex)
  {
     ROS_ERROR("transform exception: %s", ex.what());
  }
       

  //4*4 transform matrix:

  Eigen::Affine3d pcl_transform;
  tf::transformTFToEigen(transform, pcl_transform);

  //transform:
pcl::transformPointCloud(*cloud,cloud_out,pcl_transform);

  // cloud saving:
  std::string file_name=path+"cloud_"+frame_id.substr(1, frame_id.length()-1)+s1+".pcd";
pcl::io::savePCDFileBinary(file_name,cloud_out);        
}


主函数:
int
main (int argc, char** argv)
{
  ros::init(argc, argv, "cloudtf");
  ros::NodeHandle nh("~");

  std::string pointcloud_topic;
  nh.param("pointcloud_topic", pointcloud_topic, std::string("/camera/depth_registered/points"));
  nh.param("world_frame_id", world_frame_id, std::string("/odom"));
  nh.param("path", path, std::string("/home/ubuntu1/pointtest/"));
  std::cout << "Read some parameters from launch file." << std::endl;
       
  tf_listener = new tf::TransformListener();
       
  // Subscribers:
ros::Subscriber sub = nh.subscribe(pointcloud_topic, 1, cloud_cb);

  ros::spin();

  return 0;
}




回复

使用道具 举报

发表于 2017-10-12 23:18:02 | 显示全部楼层
:)不错,希望有帮助
回复 支持 反对

使用道具 举报

本版积分规则

QQ|小黑屋|点云技术相关产学研社区 ( 陕ICP备13001629号 )

GMT+8, 2024-5-6 01:46 , Processed in 2.190434 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表