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

Coloring of pcd-pointcloud in Rviz

asked 2015-12-03 01:49:45 -0600

Jay4Ros gravatar image

updated 2015-12-04 03:17:31 -0600

Hi!

I am very new to ROS, so please take that into account when answering :) (Ubuntu 14.04 64bit in a VirtualBox with Windows Host, ROS Indigo)

What I did:

I used

rosrun pcl_ros pcd_to_pointcloud myFilename.pcd 0.1

to publish a topic containing my pcl-pointcloud as a PointCloud2 message. The output of this call is:

[ INFO] [1449049889.334492450]: Publishing data on topic /cloud_pcd with frame_id /base_link. [ INFO] [1449049889.438294770]: Loaded a point cloud with 307200 points (total size is 4915200) and the following channels: x y z rgba.

As one can correctly see, the pointcloud also contains color information. I now tried to visualize the point cloud using Rviz. For this purpose I set the Fixed Frame to "/base_link" and added a "PointCloud2"-Display whose topic I set to "/cloud_pcd".

Problem description:

I was only able to see the point cloud when setting the color to something else than RGB8. Why? There should be color information and I'd like my point cloud nicely colored :) How can I fix this?

edit retag flag offensive close merge delete

Comments

this seems to be related with the fact that my pointcloud contains rgba and not only rgb. Indeed, the latter case works. According to https://github.com/ros-visualization/... this is a known issue. Is there a way to resolve it by now?

Jay4Ros gravatar image Jay4Ros  ( 2015-12-03 09:12:29 -0600 )edit

Looking again, the issue should have been resolved on 6th of Aug (I am not really familiar with the issue-tracking system of github). I tried to confirm that I have the fixed version by checking the "Modified" date of point_cloud_common.h in my ros-folder (which is 06.August.2015). Fix did not work?

Jay4Ros gravatar image Jay4Ros  ( 2015-12-04 03:16:47 -0600 )edit

The only (rather unsatisfying way) I have found so far is to write an own pcd-file reader that puts the pointcloud into a pcl::PointCloud<pcl::pointxyzrgb> object. Still hoping for a better solution here!! ;-)

Jay4Ros gravatar image Jay4Ros  ( 2015-12-07 09:58:15 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
2

answered 2018-08-01 09:58:25 -0600

ierosodin gravatar image

updated 2018-08-01 13:05:14 -0600

I think ROS does not really implement rgb data publish in pcd_to_pointcloud package. This is an example to change the PointCloud type from PointXYZ to PointXYZRGB

#include <iostream>
#include <string>
#include <ros/ros.h>
#include <pcl_ros/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl_ros/io/pcd_io.h>

typedef pcl::PointXYZRGB PointT;
typedef pcl::PointCloud<PointT> PointCloud;
using namespace std;

int main(int argc, char** argv)
{
    PointCloud::Ptr cloud(new PointCloud);
    ros::init (argc, argv, "my_pcl_tutorial");
    ros::NodeHandle nh;
    ros::Publisher pub = nh.advertise<PointCloud> ("points", 1);
    pcl::io::loadPCDFile<PointT> ("yourpcd.pcd", *cloud);

    PointCloud::Ptr msg(new PointCloud);
    msg->header.frame_id = "map";
    msg->height = cloud->height;
    msg->width = cloud->width;

    PointT p;
    for (size_t i = 0; i < cloud->size(); i++) {
        p.x = cloud->points[i].x;
        p.y = cloud->points[i].y;
        p.z = cloud->points[i].z;
        p.r = cloud->points[i].r;
        p.g = cloud->points[i].g;
        p.b = cloud->points[i].b;
        msg->points.push_back(p);
    }

    ros::Rate loop_rate(4);

    while (nh.ok())
    {
        pub.publish (msg);
        ros::spinOnce ();
        loop_rate.sleep ();
    }
}
edit flag offensive delete link more
0

answered 2018-08-02 02:19:51 -0600

updated 2018-08-02 02:30:41 -0600

Yes @ierosodin, you are able to visualize RGB-Data in RVIZ. You already pointed out how to do that. Simply convert PointCloud type from PointXYZ to (at least) PointXYZRGB and use the Pointcloud2 message from ROS to publish it.

Im not sure but I think you are not able to visualize RGB data with the Pointcloud msg type. In order to use the color information, you have to use the Pointcloud2 msg type to publish your data. (At least that is how I got it working.)

Here a little code snippet of how i got it running:

pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr final_cloud_smooth(new pcl::PointCloud<pcl::PointXYZRGBNormal>);
sensor_msgs::PointCloud2

... some point cloud processing ...

pcl::toROSMsg(*final_cloud_smooth, output_ros_cloud);
pcl_pub.publish(output_ros_cloud)

Then as you already did, chose the Pointcloud2 message type in RVIZ and chose the topic you are publishing to.

edit flag offensive delete link more

Comments

1

I use Pointcloud message type and it's work (with rgb color visualization in rviz), but I think using "sensor_msgs::PointCloud2" is a better way to publish ros pointCloud. "sensor_msgs::PointCloud" is deprecated.

ierosodin gravatar image ierosodin  ( 2018-08-02 05:00:20 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-12-03 01:49:45 -0600

Seen: 3,741 times

Last updated: Aug 02 '18