0
$\begingroup$

Rosanswers logo

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::PointCloud2pcl::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

Originally posted by nayan on ROS Answers with karma: 26 on 2021-08-02

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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 :)


Originally posted by nayan with karma: 26 on 2021-08-05

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.