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

Problem with assigning different colors to segments in PointCloud

asked 2021-08-02 03:40:40 -0500

nayan gravatar image

Hello,

I am trying a segment tracking algorithm. Right now I have 2 segments. I am coloring each segment with different RGB values, pushing the segments into output_cloud which is pcl::PointCloud2<pcl::pointxyzrgb> and publishing the output cloud.

The issue I am facing is when I see the PointCloud from RVIZ, I am getting only a single color for both (all) the segments. I have checked the correctness of assigning the RGB values by doing this:

 // checking colors 
        int prev_r = 0;
        int prev_g = 0;
        int prev_b = 0;

        int counter = 0;

        for (pcl::PointXYZRGB point : output_cloud) {
            if (prev_r != point.r) {
                std::cout << int(point.r) << " " << int(point.g) << " " << int(point.b) << std::endl;
                std::cout << counter << std::endl;
                counter = 0;
            }
            prev_r = point.r;
            prev_g = point.g;
            prev_b = point.b;
            counter++;
        }
        std::cout << counter << std::endl;

        pub_cloud.publish(output_cloud);

This is what I get (which I think is correct):

Size of segNo_cloud[0] :1168
Size of output_cloud: 1168
Size of segNo_cloud[1] :40680
Size of output_cloud: 41848
16 85 230
0
210 15 236
1168
40680
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-08-05 03:39:44 -0500

nayan gravatar image

Update: I fixed the issue! Everything was correct, but I was not clearing the vectors after assigning the segments due to which some segments were overwritten. Hope this helps someone :)

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2021-08-02 03:40:40 -0500

Seen: 125 times

Last updated: Aug 05 '21