Publish image from Unity

asked 2017-10-23 09:38:20 -0500

hermonir gravatar image

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.

edit retag flag offensive close merge delete


Not an answer, but may save you some time: Siemens recently open-sourced ros-sharp:

a set of open source software libraries and tools in C# for communicating with ROS from .NET applications, in particular Unity3D.

Might be worth looking into.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-23 09:53:06 -0500 )edit

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.

indra gravatar image indra  ( 2019-06-01 07:28:14 -0500 )edit