how to convert sensor_msgs::PointCloud2 to cv::Mat
I subscribed the ros message which type is sensor_msgs::PointCloud2, and I want to convert it to cv::Mat.
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
I subscribed the ros message which type is sensor_msgs::PointCloud2, and I want to convert it to cv::Mat.
Okay, your question makes sense now you've said
I want to obtain the grid map by converting this ros_msg to mat
This is fairly straightforward but you'll need to define a couple of things first, the cell size of your gridmap needs to be set, using this and the extents of your point-cloud you can work out the size of the cv::Mat you need to create to store the map.
If you create this Mat with all pixels set to empy, then you just need to loop through each point in the cloud and which 'pixel' of the map it falls into then set that pixel to occupied.
It's worth noting that you'll need to record the location of the Mat's origin within the coordinate frame that contains the point-cloud otherwise the position of the whole map will be unknown.
Thank you very much, I ignored the problem of the coordinate frame.
Glad you got it sorted, if this helped you solve the problem can you accept this answer. Thanks.
I'm sorry, I am a novice, I now know I need to mark this answer as correct, thank you again!
My way is to create the cv::mat which can contain 3 channel (Like RGB - but it will store XYZ) make a loop through width and height and store subscribed data onto it :)
Thank you firstly! But the cloud is unordered, height is 1 and width is the length of the point cloud. I want to obtain the grid map by converting this ros_msg to mat.
Asked: 2017-12-20 02:40:00 -0600
Seen: 1,028 times
Last updated: Dec 20 '17