Publish image from Unity
I'm trying to send an image (Texture2D) to RosBridge running on Ubuntu. Simple data types work well - floats, points.
Here is my code:
void SendUncompressedImage(Texture2D _image)
{
var timeMessage = new TimeMsg(timeSinceStart.Seconds, timeSinceStart.Milliseconds);
var headerMessage = new HeaderMsg(count, timeMessage, "camera");
byte[] data = _image.GetRawTextureData();
string picString = Convert.ToBase64String(data);
// set format
string encodingString = "rgb8";
JSONClass imageJson = CreateImageJsonNode(
headerMessage, // Header
(uint)camTexture.width, // width
(uint)camTexture.height, // height
encodingString, // encoding
false, // is_bigendian
(uint)camTexture.width * (uint)4, // step
picString); // data
// public ImageMsg(HeaderMsg header, uint height, uint width, string encoding, bool is_bigendian, uint row_step, byte[] data)
var imageMsg = new ImageMsg(headerMessage, (uint)camTexture.width, (uint)camTexture.height, encodingString, false, (uint)36, data);
ros.Publish(ImagePublisher.GetMessageTopic(), imageMsg);
}
In ros rqt, I get this error:
ImageView.callback_image() while trying to convert image from 'rgb8' to 'rgb8' an exception was thrown (Image is wrongly formed: height * step != size or 1 * 36 != 0)
Thanks for any help.
Not an answer, but may save you some time: Siemens recently open-sourced ros-sharp:
Might be worth looking into.
I am also trying to send image from Unity to ROS through ROSBridge but in my case putting image data as above throws error on ROS side related to JSON format. You seem to get past the format error. Plz help.