how to subscribe a topic which is publishing a image using rosjava
can you explain how to subscribe a image coming from a camera?
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
can you explain how to subscribe a image coming from a camera?
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";
@Override
public GraphName getDefaultNodeName() {
return GraphName.of(TAG);
}
@Override
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>() {
@Override
public void onNewMessage(Image message) {
log.info("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 https://github.com/rosjava/rosjava_mv... to see the latest version of these messages). Then, you will be able to import sensor_msgs.Image to your project. Hope it helps!
Asked: 2017-02-28 12:14:06 -0500
Seen: 707 times
Last updated: Apr 11 '17
Rosjava gradle build java classpath
How to turn an android app to a ROS node
How would I take multiple values from a subscriber to output to RosTextViews?
How to use an external library with a rosjava
android_core compilation error
problem creating rosjava packages using catkin_create_rosjava_pkg on indigo
error setting localhost on android