white color rviz

asked 2020-05-25 09:53:00 -0500

dinesh gravatar image

updated 2020-05-26 06:24:37 -0500

When i run the rviz and view the markers being published it's color is not changeing from white to any other colour. Here is the screenshot i took: image description

#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

// PCL specific includes
#include <sensor_msgs/PointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include "pcl_ros/point_cloud.h"
#include <visualization_msgs/Marker.h>
#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <iostream>
#include <math.h>
#include <visualization_msgs/Marker.h>
#include "std_msgs/Float32.h"
#include "rosbag/bag.h"
#include <rosbag/view.h>
#include <vector>
#include <utility>
#include <fstream>
#include <utility>
#include <fstream>
#include <iterator>
#include <string>
#include <boost/interprocess/file_mapping.hpp>
#include <boost/interprocess/mapped_region.hpp>
static const std::string OPENCV_WINDOW = "Image window";
using namespace std;
class ImageConverter
  ros::NodeHandle nh_;
  image_transport::ImageTransport it_;
  image_transport::Subscriber image_sub_;
  image_transport::Publisher image_pub_;
  ros::Publisher marker_pub = nh_.advertise<visualization_msgs::Marker> ("visualization_marker",1);

    : it_(nh_)
    // Subscrive to input video feed and publish output video feed
    image_sub_ = it_.subscribe("/cv_camera/image_raw", 1,
      &ImageConverter::imageCb, this);
    image_pub_ = it_.advertise("/image_converter/output_video", 1);



  void imageCb(const sensor_msgs::ImageConstPtr& msg)
    cv_bridge::CvImagePtr cv_ptr;
      cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
    catch (cv_bridge::Exception& e)
      ROS_ERROR("cv_bridge exception: %s", e.what());

    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 = 0;
    marker.type = visualization_msgs::Marker::POINTS;
    marker.scale.x = 0.1;
    marker.scale.y = 0.1;
    marker.scale.z = 0.1;
    geometry_msgs::Point P; std_msgs::ColorRGBA pc, parent;

    // Draw an example circle on the video stream
    if (cv_ptr->image.rows > 60 && cv_ptr->image.cols > 60)
      cv::circle(cv_ptr->image, cv::Point(50, 50), 10, CV_RGB(255,0,0));

    cv::Mat Lab;
    for(int x=0;x<cv_ptr->image.cols;x++) {
    for(int y=0;y<cv_ptr->image.rows;y++) {
        P.x = (float)Lab.at<cv::Vec3b>(y,x)[0]/100.0;
            P.y = (float)Lab.at<cv::Vec3b>(y,x)[1]/128.0;
        P.z = (float)Lab.at<cv::Vec3b>(y,x)[2]/128.0;
            pc.r = (float)cv_ptr->image.at<cv::Vec3b>(y,x)[0]/255.0;
            pc.g = (float)cv_ptr->image.at<cv::Vec3b>(y,x)[1]/255.0;
            pc.b = (float)cv_ptr->image.at<cv::Vec3b>(y,x)[2]/255.0;
            pc.a = 1;

    // Output modified video stream

int main(int argc, char** argv)
  ros::init(argc, argv, "image_converter");
  ImageConverter ic;
  return 0;

image description

edit retag flag offensive close merge delete


Could you post an image of the point clound/marker's settings in the RViz?

Teo Cardoso gravatar image Teo Cardoso  ( 2020-05-25 12:49:53 -0500 )edit

Have you tried modifying the colours directly on the rviz interface?

Kharkad gravatar image Kharkad  ( 2020-05-26 04:04:42 -0500 )edit

Ok i'v updated my question with the screen shot. their is not option to modify the colours directly in rviz interface.

dinesh gravatar image dinesh  ( 2020-05-26 06:25:23 -0500 )edit

Instead of using markers, could you use PointClound/PointClound2 messages? These messages have a color option.

Teo Cardoso gravatar image Teo Cardoso  ( 2020-05-26 08:06:00 -0500 )edit