How to publish an image message with ROSJava?n
I would like to learn how to publish an image message with ROSJava.
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
I would like to learn how to publish an image message with ROSJava.
Here you are an example. I've tested it and it works.
public class Talker implements NodeMain { @Override public GraphName getDefaultNodeName() { return new GraphName("rosjava_tutorial_pubsub/talker"); } @Override public void onStart(final Node node) { final Publisher<org.ros.message.sensor_msgs.image> publisher = node.newPublisher("chatter", "sensor_msgs/Image"); // This CancellableLoop will be canceled automatically when the Node shuts // down. node.executeCancellableLoop(new CancellableLoop() { @Override protected void setup() { } @Override protected void loop() throws InterruptedException { org.ros.message.sensor_msgs.Image str = new org.ros.message.sensor_msgs.Image(); publisher.publish(str); Thread.sleep(1000); } }); } @Override public void onShutdown(Node node) { } @Override public void onShutdownComplete(Node node) { } }
Of course you have to make sure that your javabootstrap.jar contains the sensor_msg/Image class. If not, here you can find a tutorial about how you can add it. You also should understand how to fill all the fields of the sensor_msgs/Image message. There are many documentation about this. You can start from here:
$ rosmsg show sensor_msgs/Image Header header uint32 seq time stamp string frame_id uint32 height uint32 width string encoding uint8 is_bigendian uint32 step uint8[] data
Some time ago I did a code in c++ that may be useful for you (I may test it tomorrow on rosjava):
image_msg->header.stamp = ros::Time::now(); image_msg->height = dwa_data->config.resolution_height; image_msg->width = dwa_data->config.resolution_width; image_msg->encoding = "rgb8"; //sensor_msgs::image_encodings::MONO16; image_msg->step = image_msg->width * 3; image_msg->data.resize(image_msg->height * image_msg->step); for (int i = 0; i<dwa_data->config.resolution_width*dwa_data->config.resolution_height ; i++) { //ROS_INFO("index %d",i); int offset = 3 * i; ... image_msg->data[offset] = 255; image_msg->data[offset + 1] = 0; image_msg->data[offset + 2] = i%255; ... }
Asked: 2012-02-05 09:12:25 -0600
Seen: 1,325 times
Last updated: Feb 07 '12
how to save an sensor_msgs/Image to a file?
Is there a way to compress an Image?
Generating messages for rosjava?
Where is there a canned disparity image to point cloud function? [closed]
AssertionError: Test node [test_rosjava/tester]
TF Frame Convention for Stereo Cameras
Putting a sensor_msgs/Image into a message, getting it back, and converting it for OpenCV?