-
Notifications
You must be signed in to change notification settings - Fork 41
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
Publishing image to ROS #3
Comments
Can you provide a screen dump of the error message from ROS? Also, please remember that as currently implemented the ROSBridge protocol is 8 bits clean so I am not sue that the compressedImageMsg (as a compressed image) is going to be that happy. We normally do not send streamed images through the ROSBridge linkage. It is too easy to saturate the bandwidth the of the channel. Michael
|
Is there a method that you would recommend for streaming images from Unity 3D back to ROS? Please know that I appreciate the quick response! I really enjoyed getting to know your library. It's pretty fun! |
I’ve never done it the Unity->ROS direction. In the other direction ROS->Unity, we have tried both services and also establishing a separate web channel to send them. The problem is that if you just send image sequences through the ROSBridge channel you can easily saturate the ROSBridge link, to the point where responsiveness suffers. On the ROS side you can throttle the image (or any large data stream) in many ways. The idea of sampling images from the Unity side should work too, although I would be careful to only restart the clock once the image has been drained through the link. Michael PS If you send along the bug output, I can have a look to see where it is coming from. Glad to hear the library is useful.
|
Hi,
All the best |
Can you send a bit of the code that leads to this? But it looks as though a comma is missing before “data” which is invalid?
{"op": "publish”,
"topic": "/unityx”,
"msg": {"header” :
{"seq": 0,
"stamp": {"data" : {"secs" : 1, "nsecs" : 129}},
"frame_id": "xvariable”}. <- no comma
"data" : 0}}. <- no “data” associated with the message??? Strange
Michael
… On Sep 21, 2017, at 7:59 PM, robetto ***@***.***> wrote:
Hi,
Did you solve the problem with the op code error?
I am trying to send a Float32 to ROS and get the same op error.
[ERROR] [1506036825.816606]: [Client 1] Received a message without an op. All messages require 'op' field with value one of: ['service_response', 'unadvertise_service', 'call_service', 'publish', 'fragment', 'subscribe', 'advertise_service', 'unsubscribe', 'unadvertise', 'advertise']. Original message was: {"op": "publish", "topic": "/unityx", "msg": {"header" :{"seq": 0, "stamp": {"data" : {"secs" : 1, "nsecs" : 129}}, "frame_id": "xvariable"}"data" : 0}}
All the best
Robert
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#3 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AJy_kvojSP6uQ-FXlwTEKHrmrW-VwtgXks5skvhRgaJpZM4JUCcE>.
|
` public class pubtest : MonoBehaviour {
} And the code for the Float32 is ` namespace ROSBridgeLib {
} |
You were right!
Thank You! |
Is it possible to send Image from Unity -> ROS, the texture converted to .png or .jpeg? |
Yes, but if will have to be converted to JSON and the receiving ROS message type will have to match. Michael
… On Oct 2, 2017, at 10:37 PM, Pushkal Katara ***@***.***> wrote:
Is it possible to send Image from Unity -> ROS, the texture converted to .png or .jpeg?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#3 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AJy_khVLsPKhCR_HQM4U1JYbtgsczr0Oks5soZ3OgaJpZM4JUCcE>.
|
There are two message image formats under sensor_msgs in ROS - sensor_msgs/Image and sensor_msgs/CompressedImage. When I try to send as message type sensor_msgs/Image, ros gives out the error, step does not match. http://docs.ros.org/api/sensor_msgs/html/msg/Image.html I think am missing the header info. |
It can be made got work, but is not recommended. The problem is that the base64 encoding of the image is going to result in a huge package. Such packages can easily saturate the rosbridge connection.
I think that the problem you are having is at the other end?
Michael
… On Nov 6, 2017, at 2:43 AM, hermonir ***@***.***> wrote:
Any success on sending an image from Unity to ROS?
I'm using this code:
void SendJPEGImage(Texture2D _image)
{
var timeMessage = new TimeMsg(timeSinceStart.Seconds, timeSinceStart.Milliseconds);
var headerMessage = new HeaderMsg(count, timeMessage, "camera");
byte[] data = _image.EncodeToJPG();
string picString = Convert.ToBase64String(data);
Debug.Log ("data length: " + data.Length);
// set format
string format = "jpeg";
//CompressedImageMsg(HeaderMsg header, string format, byte[] data)
byte[] array = Encoding.ASCII.GetBytes(picString);
var compressedImageMsg = new CompressedImageMsg(headerMessage, format, array);
ros.Publish(CompressedImagePublisher.GetMessageTopic(), compressedImageMsg);
}
ROS or rosbridge do not complain, but the image does not open in MatLab or in rqt.
rqt says it doesn't have a compressedImage plugin:
<https://user-images.githubusercontent.com/14308559/32430005-e2b9ef9c-c2d5-11e7-9638-ab82d17c9688.png>
Matlab error is:
Could not find a semicolon in format character vector jpeg. Modify the "format" property of the message object appropriately.
I tried putting in "jpeg; jpeg uncompressed", and after looking at a working image from another source, also "bgr8; jpeg uncompressed bgr8"
to no avail.
Thanks :-)
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#3 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AJy_kqCAeFrQyXQ-hKmhNhuC7R3aHThjks5szriigaJpZM4JUCcE>.
|
Any other way to convert Unity Texture2D Byte Stream to Ros topic? Maybe without using rosbridge, sockets or wwwforms in unity to send the bytes and requests in python to parse the bytes and display using opencv? |
@michaeljenkin I couldn't find any other way to send an image to ros. When I tried sending an uncompressed image, rosbridge kept complaining about the width and height and offset. Cheers |
You have to send the image in a compressed format (well thats how I have been able to get Unity->Ros working). Otherwise you can not get a byte[] array to ship out. You aslo have to use RGB24 when using ReadPixels() to convert RenderTexture to texture2D before encoding as png or jpeg. Then you can use rosrun image_view image_view image:=<your/topic/url> _image_transport:=compressed. Im now struggling getting the correct projection matrix conversion from Unity camera. Iv been using cam.projectionM * cam.worldToCameraM to get a 4x4 projection matrix, but my vision-odometry that im running has a hard time tracking points. |
Do you mean the render texture needs to be in RGB24? There is no such format... This is my pre-sending code:
Thanks |
@hermonir @hermonir1 any luck? |
@pushkalkatara No, I'm actually waiting for your answer.. |
Oh, RGB24 is used when creating the new texture2d. I'll try it tomorrow. |
@pushkalkatara @michaeljenkin Still no go :-\ Texture encoding code:
Actual publishing code:
Can someone please send a working code sample? |
It is not clear where the error is, at the Unity side or at the Matlab error. All the Unity side does is fire out a json string that encodes the image. Its a 7 bit clean stream so you should be able to put it in a file, give it to your favourite json decoder, and see if you are actually getting a jpeg. Btw, the json structure will be really simple, so except for the really large Base64 encoded image it should be quite easy to view and inspect visually.
But to repeat, firing images (repeatedly) through the rosbridge link is not recommended. Open up some other stream and pump the jpeg through that. http is usually really easy.
Michael
… On Nov 13, 2017, at 3:51 AM, hermonir1 ***@***.***> wrote:
@pushkalkatara <https://github.com/pushkalkatara> @michaeljenkin <https://github.com/michaeljenkin> Still no go :-\
Texture encoding code:
Texture2D image = new Texture2D(camTexture.width, camTexture.height, TextureFormat.RGB24, false);
image.ReadPixels(new Rect(0, 0, camTexture.width, camTexture.height), 0, 0);
image.Apply();
SendJPEGImage (image);
Actual publishing code:
void SendJPEGImage(Texture2D _image)
{
var timeMessage = new TimeMsg(timeSinceStart.Seconds, timeSinceStart.Milliseconds);
var headerMessage = new HeaderMsg(count, timeMessage, "camera");
byte[] data = _image.EncodeToJPG();
string picString = Convert.ToBase64String(data);
Debug.Log ("data length: " + data.Length);
// set format
string format = "jpeg";
//CompressedImageMsg(HeaderMsg header, string format, byte[] data)
byte[] array = Encoding.ASCII.GetBytes(picString);
var compressedImageMsg = new CompressedImageMsg(headerMessage, format, array);
ros.Publish(CompressedImagePublisher.GetMessageTopic(), compressedImageMsg);
}
Can anyone please send a working code sample?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#3 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AJy_kuIopvCh51j4fb2P4_0n_ZBXDIhmks5s2AMPgaJpZM4JUCcE>.
|
Thanks! Just solved the problem. It actually was on the Matlab side - it didn't convert from base64 string back to byte[]. Will look at sending the images with http. At least now we have a working solution. |
Thanks! image_np = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)
cv2.imshow('cv_img', image_np)
cv2.waitKey(2) |
I am aware this issue is for image type; i am unable to send even string from unity to ros, however I can hear back from ros to unity.
|
Hi. Thanks very much for putting together this awesome library to connect Unity 3D to ROS. I have enjoyed using it to connect SLAM algorithms to Unity 3D. I had a quick question regarding publishing images. I'm trying to publish an image to ROS bridge every 2 seconds.
Does this use case feel feasible? Any help you can offer would be appreciated.
ROS is currently mentioning that it's missing an op code.
`
using UnityEngine;
using System;
using System.Collections;
using ROSBridgeLib.sensor_msgs;
using ROSBridgeLib.std_msgs;
using ROSBridgeLib;
using System.Text;
public class VideoTexture : MonoBehaviour {
}
`
The text was updated successfully, but these errors were encountered: