ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Convert PointCloud2ConstPtr to PointCloud2

asked 2019-07-02 04:37:37 -0600

A_YIng gravatar image

updated 2019-07-02 04:37:58 -0600

Hello,

I would like to know how to convert convert PointCloud2ConstPtr to PointCloud2. I use these code:

  sensor_msgs::PointCloud2ConstPtr kinect_pointcloud_ptr;
  kinect_pointcloud_ptr = ros::topic::waitForMessage<sensor_msgs::PointCloud2> ("/voxel_output", ros::Duration (5.0));
  std::cerr << "Pointcloud points number: "<< kinect_pointcloud_ptr->width * kinect_pointcloud_ptr->height <<"";

  sensor_msgs::PointCloud2ConstPtr p_pointcloud_ptr;
  tf2_ros::Buffer tfBuffer;
  tf2_ros::TransformListener tfListener(tfBuffer);
  geometry_msgs::TransformStamped p_frame_to_kinect2_link;      
  p_frame_to_kinect2_link = tfBuffer.lookupTransform("kinect2_link", "p_frame", ros::Time::now(), ros::Duration(3.0));
  tf2::doTransform(kinect_pointcloud_ptr, p_pointcloud_ptr, p_frame_to_kinect2_link);

And I get some error:

Undefined reference to 「void tf2::doTransform<boost::shared_ptr<sensor_msgs::PointCloud2_<std::allocator<void> > const> >(boost::shared_ptr<sensor_msgs::PointCloud2_<std::allocator<void> > const> const&, boost::shared_ptr<sensor_msgs::PointCloud2_<std::allocator<void> > const>&, geometry_msgs::TransformStamped_<std::allocator<void> > const&)」

If anyone has good solution to suggest me. It will be nice. Thank!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2019-07-02 06:05:02 -0600

You'll need to use the pcl_ros::transformPointCloud to transform a point cloud, as far as I know it cannot be done using the doTransform method.

You'll also need to make a non const point cloud to store the result. Whenever you see a const type in C++ it means that its value cannot be changed. So you'll need to define a variable like sensor_msgs::PointCloud2 p_output_pointcloud_ptr; for the result.

Hope this helps.

edit flag offensive delete link more

Comments

Thank for your reply, it works for me. Here is my example code to provide to someone have the same question!

sensor_msgs::PointCloud2 pc;
sensor_msgs::PointCloud2 t_pc; 
pc = *(ros::topic::waitForMessage<sensor_msgs::PointCloud2>("/Topic_name",ros::Duration(3.0)));
pc.header.frame_id = "Source_frame";
pcl_ros::transformPointCloud("Target_frame", pc, t_pc, *tf_listener);
A_YIng gravatar image A_YIng  ( 2019-07-02 09:08:12 -0600 )edit

Great, glad you got it working.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-07-02 10:41:09 -0600 )edit
1

But why would you need to use pcl_ros::transformPointCloud if there are no PCL types involved? That seems to make no sense. Why wouldn't you use the transform method of the tf2_ros::Buffer object?

alexe gravatar image alexe  ( 2020-03-27 19:25:24 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-07-02 04:37:37 -0600

Seen: 1,584 times

Last updated: Jul 02 '19