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

Revision history [back]

click to hide/show revision 1
initial version

This worked! No cv_bridge required. :)

  unsigned char* image_pointer_red; 
  unsigned char* image_pointer_green;
  unsigned char* image_pointer_blue;

  uint8_t *uint8_pointer_red    = reinterpret_cast<uint8_t*>((unsigned char*)channel_red_pointer[0].L());
  uint8_t *uint8_pointer_green  = reinterpret_cast<uint8_t*>((unsigned char*)channel_green_pointer[0].L());
  uint8_t *uint8_pointer_blue   = reinterpret_cast<uint8_t*>((unsigned char*)channel_blue_pointer[0].L());

  int height = atoi(height_pointer.ToString().Text());
  int width = atoi(width_pointer.ToString().Text());

  sensor_msgs::Image output_image;
  output_image.header.stamp     = ros::Time::now();
  output_image.height           = height;
  output_image.width            = width;
  output_image.encoding         = "rgb8";
  output_image.is_bigendian     = false;
  output_image.step             = 3 * height;

  for(int i=0; i<(width*height);i++)
  {
       output_image.data.push_back(uint8_pointer_red[i]);
       output_image.data.push_back(uint8_pointer_green[i]);
       output_image.data.push_back(uint8_pointer_blue[i]);
  }
  image_publisher.publish(output_image);