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

not sending different marker colours to rviz properly

asked 2016-11-10 03:02:17 -0500

dinesh gravatar image

updated 2016-12-22 20:59:57 -0500

when i send different coloured markers it doesn't shows exact object from which its color was extracted. as i've shown below: 1. real object image description

2. poicloud rendered in rviz
![image description](/upfiles/14819498042350993.png)]
  1. object rendered with its colour and coordinates: image description

    I just want to check if the colour datas saved by the 3d model of the object is real or not. Here background color of 2nd image is black. This code is just for demonstration purpose, i'm using this concept in another program.

        int h = 479, w = 639, n = 306081;
    
        for(int raw = 0;raw<h;raw++)
        {
            for(int col = 0;col<w;col++)
            {
                P[raw][col] = output.at(col,raw);
            }
        }
        rosbag::Bag bag("image.bag");
       int iv = -1, ix = -1, iy = -1, iz = -1, icx=-1, icy=-1, icz=-1;
    
            rosbag::View view(bag, rosbag::TopicQuery("numbers"));
            BOOST_FOREACH(rosbag::MessageInstance const m, view)
               {
                   std_msgs::Float32::ConstPtr i = m.instantiate<std_msgs::Float32>();
                   iv = iv+1; 
                   if(iv>=0 && iv<306081) {
                       ix = ix+1;
                       xv[ix] = i->data;
                   }
                            if(iv>=306081 && iv<306081*2) {
                       iy = iy+1;
                       yv[iy] = i->data;
                   }
                   if(iv>=306081*2 && iv<306081*3) {
                       iz = iz+1;
                       zv[iz] = i->data;
                   }
    
    
               if(iv>=306081*3 && iv<306081*4) {
                       icx = icx+1;
                       cx[icx] = i->data;
                   }
        if(iv>=306081*4 && iv<306081*5) {
                       icy = icy+1;
                       cy[icy] = i->data;
                   }
        if(iv>=306081*5 && iv<306081*6) {
                       icz = icz+1;
                       cz[icz] = i->data;
                   }
            }
             bag.close();
    
    
             // ** converting already read saved points to 2 d array
             int ip = -1;
             for(int i=0;i<h;i++)
             {
                 for(int j=0;j<w;j++)
                 {
                     ip = ip+1;
                     x[i][j] = xv[ip]; xp[i][j] = P[i][j].x; xc[i][j]=P[i][j].r; // (xp,yp,zp) is present image,(x,y,z) is cordinate of privious image
                     y[i][j] = yv[ip]; yp[i][j] = P[i][j].y; yc[i][j]=P[i][j].g;
                     z[i][j] = zv[ip]; zp[i][j] = P[i][j].z; zc[i][j]=P[i][j].b;
                 }
             }
    
     // ** comparing previous and present point cloud and finding moved objects
                   int im = -1;
                   for(int k=0;k<h;k++)
                           {
                               for(int l=0;l<w;l++)
                           {
                               if( z[k][l]!=0 && zp[k][l]!=0 && !isnan(x[k][l]) && !isnan(xp[k][l]) && !isnan(y[k][l]) && !isnan(yp[k][l]) && !isnan(z[k][l]) && !isnan(zp[k][l]) )
                               {
                                   float dx=abs(float(x[k][l]-xp[k][l])*100);
                                   float dy=abs(float(y[k][l]-yp[k][l])*100);
                                   float dz=abs(float(z[k][l]-zp[k][l])*100); 
                                   float d = sqrt(dx*dx+dy*dy+dz*dz); 
                                   if(d>2)
                                   {
                                       im = im+1;
                                       a[im] =(int) xc[k][l]; b[im] =(int) yc[k][l]; c[im] =(int) zc[k][l]; // (a,b,c) has color of present points  
                                       ac1[im]=xp[k][l]; bc1[im]=yp[k][l]; cc1[im]=zp[k][l]; // (ac1,bc1,cc1) has 3d coordinates  
                                       xa[im] = l ...
(more)
edit retag flag offensive close merge delete

Comments

" int h = 479, w = 639, n = 306081;" This is extremely bad coding style. If you use a camera with a different resolution or try to run you algorithm on a downsampled pointcloud, this will fail. Simply read width and height from the pointcloud and use these values.

NEngelhard gravatar image NEngelhard  ( 2016-12-23 01:43:08 -0500 )edit

2 Answers

Sort by » oldest newest most voted
2

answered 2016-11-10 04:16:00 -0500

rbbg gravatar image

Judging from your earlier question, you are using a visualization_msgs::Marker message with the type POINTS, looking at the message definition, you can see that there is two ways of specifying the color, which are: Marker.color and Marker.colors. The latter is a vector that has to be of the same length as the number of points. Putting the colors into that vector will allow you to set different colors for different points. If you use Marker.color (like you seem to do in the code you posted before), you will indeed also change the color of the previous points.

edit flag offensive delete link more

Comments

really wow, i'll try this one.

dinesh gravatar image dinesh  ( 2016-11-16 07:45:28 -0500 )edit

error: ‘visualization_msgs::Marker_<std::allocator<void> >::_colors_type’ has no member named ‘r’ points.colors.r = 1.0f; it is not working like that. have u urself tried that also?

dinesh gravatar image dinesh  ( 2016-11-20 06:48:31 -0500 )edit

points.colors.r = 1.0f; will indeed not work, because points.colors is an array of std_msgs::ColorRGBA. In order to set it for the different points you need to set the color for all the points. For each point you need to make a ColorRGBA and add it to the points.colors vector.

rbbg gravatar image rbbg  ( 2016-12-01 05:12:17 -0500 )edit
1

answered 2016-12-27 05:45:35 -0500

dinesh gravatar image
ros::Publisher marker_pub;
marker_pub = nh.advertise<visualization_msgs::Marker> ("visualization_marker",1);
visualization_msgs::Marker marker;
marker.header.frame_id = "/camera_link";
marker.header.stamp = ros::Time();
marker.ns = "lines";
marker.action = visualization_msgs::Marker::ADD;
marker.pose.orientation.w = 1;
marker.id = 1;
marker.type = visualization_msgs::Marker::POINTS;
marker.scale.x = 0.001;
marker.scale.y = 0.001;
marker.scale.z = 0.001;
marker.color.a = 1.0;
marker.color.r = 0.0;
marker.color.g = 1.0;
marker.color.b = 0.0;

     geometry_msgs::Point p; std_msgs::ColorRGBA pc;
     for(int i=0;i<a.size() && ros::ok();i++) {
        p.x = a.at(i); p.y = b.at(i); p.z = c.at(i); 
        pc.r =(float) r1.at(i)/255; pc.g =(float) g1.at(i)/255; pc.b =(float) b1.at(i)/255; pc.a=1;
        marker.points.push_back(p);
        marker.colors.push_back(pc); 
     }
     marker_pub.publish(marker);

This is the code which i tried and it is working as thought. Here a,b,c are vectors containing position of point and r1,g1,b1 are vectors containg color of given point.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2016-11-10 03:02:17 -0500

Seen: 1,146 times

Last updated: Dec 27 '16