Ask Your Question

Transforming PointCloud2

asked 2012-02-04 07:07:36 -0500

alfa_80 gravatar image

updated 2012-02-04 07:08:08 -0500

I would like to know if somebody knows what is the substitute for the function of transformPointCloud() for PointCloud2 data type as in this question. I've tried to go to the link provided but it seems to be deprecated(I guess) as I cannot find in my autocompletion mode.

Thanks in advance.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted

answered 2012-02-04 09:07:35 -0500

joq gravatar image

You had found the correct answer: pcl_ros::transformPointCloud() is the function to call.

The generated documentation link may have changed. Try looking for it starting with the main pcl_ros API page.

edit flag offensive delete link more


Why can't I use it? I've already included pcl_ros in the manifest.xml
alfa_80 gravatar image alfa_80  ( 2012-02-05 02:54:48 -0500 )edit
Did you #include <pcl_ros/transforms.h> ?
joq gravatar image joq  ( 2012-02-05 03:13:24 -0500 )edit
Thanks a lot. That worked! By the way, why someone said that pcl_ros is deprecated already, but when I go to the API doc, it is still someone actively committing codes last few days?
alfa_80 gravatar image alfa_80  ( 2012-02-05 04:12:38 -0500 )edit
I never heard it was deprecated. For Fuerte, the big PCL library will become a rosdep, but pcl_ros still exists.
joq gravatar image joq  ( 2012-02-05 04:17:26 -0500 )edit
I see, thanks a lot for the clarification.
alfa_80 gravatar image alfa_80  ( 2012-02-05 04:24:19 -0500 )edit
Last time, i just included "#include <pcl_ros/point_cloud.h>", but this one doesn't suffice.
alfa_80 gravatar image alfa_80  ( 2012-02-05 04:51:40 -0500 )edit

answered 2015-08-13 18:18:58 -0500

peci1 gravatar image

You can transform using the tf2_sensor_msgs (both C++ and Python interface, since at least Indigo):

#include <tf2_sensor_msgs.h>
#include <sensor_msgs/PointCloud2.h>
#include <geometry_msgs/TransformStamped.h>

const sensor_msgs::PointCloud2 cloud_in, cloud_out;
const geometry_msgs::TransformStamped transform;
// TODO load everything
tf2::doTransform (cloud_in, cloud_out, transform);

Or in Python:

from tf2_sensor_msgs.tf2_sensor_msgs import do_transform_cloud
cloud_out = do_transform_cloud(cloud_in, transform)

None of the codes was really tested, though I intend to use them tomorrow. If you test them and find a bug, please edit my answer. I really wonder why there aren't more tutorials for this kind of essential conversions.

edit flag offensive delete link more


What's the right data format for "transform" in python?

blueflame gravatar image blueflame  ( 2017-10-02 12:31:21 -0500 )edit

Let me post my example code here in python:

import sensor_msgs.point_cloud2 as pc2

from sensor_msgs.msg import PointCloud2

from tf2_sensor_msgs.tf2_sensor_msgs import do_transform_cloud

import tf2_ros

blueflame gravatar image blueflame  ( 2017-10-02 13:59:43 -0500 )edit

tf_buffer = tf2_ros.Buffer()

tf_listener = tf2_ros.TransformListener(tf_buffer)

transform = tf_buffer.lookup_transform("camera_link","map", rospy.Time())

pcd2_camera = do_transform_cloud(pcd2, transform)

This help to trasform pointclouds2 from "map" link into camera_link

blueflame gravatar image blueflame  ( 2017-10-02 14:03:45 -0500 )edit

@blueflame does your code actually work? because i tried to implement it but i get ImportError: No module named tf2_sensor_msgs.tf2_sensor_msgs

Please advise

lr101095 gravatar image lr101095  ( 2018-05-16 20:07:18 -0500 )edit

Hi! Make sure you installed the tf2_sensor_msgs package for your ros distribution.

diogoa gravatar image diogoa  ( 2018-08-27 09:42:18 -0500 )edit

sudo apt-get install ros-kinetic-tf2-sensor-msgs

Markus gravatar image Markus  ( 2019-11-24 06:25:44 -0500 )edit

I have tested this part of the code and am facing some offset issues, meaning there is an increasing offset issue with it. Let me explain it furthur, so I have the laser scan data in laser frame being plotted in the rviz and I then convert the same point cloud frame to odom frame and then plot the same in rviz. Initially there is an offset only in the z axis at the start position but as the robot moves the point cloud data keeps drifting away from the laser scan plot. Has anyone else faced this issue as well ?

Vignesh_93 gravatar image Vignesh_93  ( 2021-03-31 06:51:42 -0500 )edit

answered 2014-12-07 16:38:38 -0500

bzr gravatar image

Warning: pcl_ros has been depreciated.

edit flag offensive delete link more


pcl_ros is not deprecated.

tfoote gravatar image tfoote  ( 2021-03-31 13:48:12 -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


Asked: 2012-02-04 07:07:36 -0500

Seen: 4,120 times

Last updated: Aug 13 '15