Ask Your Question
0

Convert PointCloud2ConstPtr to PointCloud2

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

A_YIng gravatar image

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

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 -0500

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 imageA_YIng ( 2019-07-02 09:08:12 -0500 )edit

Great, glad you got it working.

PeteBlackerThe3rd gravatar imagePeteBlackerThe3rd ( 2019-07-02 10:41:09 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 57 times

Last updated: Jul 02