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

how to subscribe a topic which is publishing a image using rosjava

asked 2017-02-28 12:14:06 -0500

vinay_kumar28 gravatar image

can you explain how to subscribe a image coming from a camera?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-04-11 12:45:41 -0500

jubeira gravatar image

You need to create a node that subscribes to a sensor_msgs/Image topic. Here's some code:

public class ImageListenerNode extends AbstractNodeMain {

public static String TAG = "image_listener";

public GraphName getDefaultNodeName() {
    return GraphName.of(TAG);

public void onStart(ConnectedNode node) {
  final Log log = node.getLog();
  Subscriber<Image> subscriber = node.newSubscriber("/image_topic", "sensor_msgs/Image");

  subscriber.addMessageListener(new MessageListener<Image>() {
      public void onNewMessage(Image message) {
"New image is here!");


Apart from the standard rosjava dependency, you will need to add org.ros.rosjava_messages:sensor_msgs to your dependencies in your Gradle script / POM file (check to see the latest version of these messages). Then, you will be able to import sensor_msgs.Image to your project. Hope it helps!

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2017-02-28 12:14:06 -0500

Seen: 707 times

Last updated: Apr 11 '17