Ask Your Question
0

How to add a point to sensor_msgs::PointCloud2?

asked 2020-10-15 09:38:11 -0500

wiyogo gravatar image

I declare a point as

Eigen::Vector2f point;

However, I cannot add this point to my PointCloud2 with this code:

sensor_msgs::PointCloud2 filteredPoints;

filteredPoints.data.push_back(point);

The issue is the data is a type of std::vector<uint8_t, std::allocator<uint8_t>>. The eror shows clearly: error: no matching function for call to ‘std::vector<unsigned char, std::allocator<unsigned char> >::push_back(Eigen::Vector2f&) I never work with such a vector type with allocator as the second template.

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2020-10-15 10:56:07 -0500

JackB gravatar image

updated 2020-10-15 10:56:52 -0500

It is saying that you can't just use an Eigen::Vector2f to add a point to a pointcloud2. See this example for a use case of generating a point cloud and then publishing it.

As I understand it the best practice is that you process the data using the pcl library, and then after you have made the pointcloud you convert it to the ROS msg pointcloud2 and then publish it.

edit flag offensive delete link more

Comments

Thank you @JackB! But how can I integrate ros_pcl in an existing project in ros-melodic? I got an error msg: No such file or directory #include <pcl/conversions.h>, even I added pcl_conversions in my CMakeLists.txt. It seems I need to download the package too.

wiyogo gravatar image wiyogo  ( 2020-10-15 13:57:30 -0500 )edit

You should open another, separate question, with more detail and context so that someone can help you solve it. Glad I could help get you started in the right direction.

JackB gravatar image JackB  ( 2020-10-15 14:21:10 -0500 )edit

Thanks @JackB. This is my new question https://answers.ros.org/question/3635...

wiyogo gravatar image wiyogo  ( 2020-10-16 03:17:18 -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: 2020-10-15 09:38:11 -0500

Seen: 44 times

Last updated: Oct 15