Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

white color rviz #71

Open
roboticsai opened this issue Jun 7, 2020 · 1 comment
Open

white color rviz #71

roboticsai opened this issue Jun 7, 2020 · 1 comment

Comments

@roboticsai
Copy link

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: https://answers.ros.org/question/353188/white-color-rviz/?comment=353270#post-id-353270

#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);

public:
  ImageConverter()
    : 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);

    cv::namedWindow(OPENCV_WINDOW);
  }

  ~ImageConverter()
  {
    cv::destroyWindow(OPENCV_WINDOW);
  }

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

    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;
    cv::cvtColor(cv_ptr->image,Lab,cv::COLOR_BGR2Lab); 
    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;
            marker.points.push_back(P);
            marker.colors.push_back(pc);
        }
    }

    marker_pub.publish(marker);            
    // Output modified video stream
    image_pub_.publish(cv_ptr->toImageMsg());
  }
};

int main(int argc, char** argv)
{
  ros::init(argc, argv, "image_converter");
  ImageConverter ic;
  ros::spin();
  return 0;
}
@LeroyR
Copy link

LeroyR commented Sep 2, 2020

Check your Message with rostopic echo /visualization_marker i assume you put in invalid colors outside [0..1]
In any other case Reopen as bug in rviz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants