Ask Your Question
0

Access image header information on roslibjs side

asked 2020-10-11 07:27:58 -0500

Jt3d gravatar image

Hi all,

I can access an image of type opencv format and send it to a web browser using roslibjs library.

What I am not sure in is how to access the header information eg. header.stamp and header.frame_id on the roslibjs side of things. Any help would be greatly appreciated?

this is the c++ side of things

  cv_bridge::CvImagePtr cv_ptr(new cv_bridge::CvImage);
  ros::Time time = ros::Time::now();
  cv_ptr->encoding = "bgr8";
  cv_ptr->header.stamp = time;
  cv_ptr->header.frame_id = "/camera/image123";  
  cv_ptr->image = img;    
  image_pub_.publish(cv_ptr->toImageMsg());

on the js side of things

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

    image_listener.subscribe(function(message) {      
      console.log("image listener event fired");      
      var imagedata = "data:image/jpeg;base64," + message.data;      
      document.getElementById("liveimage").src = imagedata;                             
    });
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-10-11 09:13:40 -0500

miura gravatar image

header.stamp should be accessible by message.header.stamp. Similarly, header.frame_id should be accessible by message.header.frame_id.

image_listener.subscribe(function(message) {      
  console.log("image listener event fired");      
  var imagedata = "data:image/jpeg;base64," + message.data;      
  document.getElementById("liveimage").src = imagedata;

  var stamp = message.header.stamp;                     
  var frame_id = message.header.frame_id;
});
edit flag offensive delete link more

Comments

Many thanks - for some reason the intellisene in visual studio code wasn't giving those options so I thought it was more complicated.

Jt3d gravatar image Jt3d  ( 2020-10-11 18:12:45 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2020-10-11 07:27:58 -0500

Seen: 183 times

Last updated: Oct 11 '20