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

roslibjs subscribe to sensor_msgs/image

asked 2017-01-20 19:09:33 -0500

Swoncen gravatar image

Hello,

I couldn't find an example of how to subscribe to a sensor_msgs/image and display it in a html5 canvas. I already have a page running and I can somehow access the data, but it won't display in an image nor in a html5 canvas. This is an excerpt of my test code:

imageTopic.subscribe(function(message)
{
   var imagedata = "data:image/jpeg;base64," + message.data;
   document.getElementById('xy_image').setAttribute('src', imagedata);
   imageTopic.unsubscribe();
});

First of all: how can I access the frames without subscribing to the topic every time and unsubscribing to it again? Second: The message.data seems correct, but the header doesnt work and the image is not displayed. I tried png as well, with no success. I would be happy if you could help me out - maybe with a basic example.

Thanks in advance

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-01-22 15:14:32 -0500

Swoncen gravatar image

updated 2017-01-22 15:32:11 -0500

gvdhoorn gravatar image

Found a solution:

var imageTopic = new ROSLIB.Topic({
    ros : ros,
    name : '/camera/image/compressed',
    messageType : 'sensor_msgs/CompressedImage'
});

the compressed image can be retrieved via:

var imagedata = "data:image/jpg;base64," + message.data;
edit flag offensive delete link more

Comments

I've converted your comment to an answer, as it would seem you have answered your own question (good!).

Could you accept your own answer? You can do so by ticking the checkmark to the left of the answer.

gvdhoorn gravatar image gvdhoorn  ( 2017-01-22 15:31:54 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2017-01-20 19:09:33 -0500

Seen: 2,489 times

Last updated: Jan 22 '17