java_rosbridge icon indicating copy to clipboard operation
java_rosbridge copied to clipboard

Does exist an example to send/receive images?

Open jabrena opened this issue 8 years ago • 2 comments

Hi,

I would like to know if exist and example to send & receive images. In the sources, I saw that exist the message, but I am not sure if you test the message in the past.

Many thanks in advance

Juan Antonio

jabrena avatar Jun 28 '17 22:06 jabrena

Yes, subscribing/publishing to image topics with the Image message works (did the last time I used it at least). Hooking it up works the same way as any other message/topic. When the delegate receives the message, you'll probably want to use a MessageUnpacker like in the example in the readme. But unlike in the example in the readme that is for a string message, you set the generic and class to be the Image class defined in the messages. That class includes methods for auto unpacking the ROS image message data into a Java Buffered object for RGB and Mono encoded images so you can render it in something like a Swing GUI pretty easily.

jmacglashan avatar Jun 29 '17 14:06 jmacglashan

I don't know how to do this... here is my code to receive:

public void receive(JsonNode data, String stringRep) {
  MessageUnpacker<BufferedImage> unpacker = new MessageUnpacker<BufferedImage>(BufferedImage.class);
  BufferedImage msg = unpacker.unpackRosMessage(data);
}

And I got this error:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of java.awt.image.BufferedImage (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: UNKNOWN; line: -1, column: -1] at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67) at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1451) at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1027) at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1290) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:326) at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159) at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3972) at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2264) at com.fasterxml.jackson.databind.ObjectMapper.treeToValue(ObjectMapper.java:2746) at ros.tools.MessageUnpacker.unpackRosMessage(MessageUnpacker.java:55) at rostest$1.receive(rostest.java:170) at ros.RosBridge$RosBridgeSubscriber.receive(RosBridge.java:571) at ros.RosBridge.onMessage(RosBridge.java:228) at ros.RosBridge.processFragment(RosBridge.java:520) at ros.RosBridge.onMessage(RosBridge.java:232) at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.eclipse.jetty.websocket.common.events.annotated.CallableMethod.call(CallableMethod.java:71) at org.eclipse.jetty.websocket.common.events.annotated.OptionalSessionCallableMethod.call(OptionalSessionCallableMethod.java:72) at org.eclipse.jetty.websocket.common.events.JettyAnnotatedEventDriver.onTextMessage(JettyAnnotatedEventDriver.java:234) at org.eclipse.jetty.websocket.common.message.SimpleTextMessage.messageComplete(SimpleTextMessage.java:69) at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.appendMessage(AbstractEventDriver.java:66) at org.eclipse.jetty.websocket.common.events.JettyAnnotatedEventDriver.onTextFrame(JettyAnnotatedEventDriver.java:226) at org.eclipse.jetty.websocket.common.events.AbstractEventDriver.incomingFrame(AbstractEventDriver.java:162) at org.eclipse.jetty.websocket.common.WebSocketSession.incomingFrame(WebSocketSession.java:376) at org.eclipse.jetty.websocket.common.extensions.ExtensionStack.incomingFrame(ExtensionStack.java:220) at org.eclipse.jetty.websocket.common.Parser.notifyFrame(Parser.java:220) at org.eclipse.jetty.websocket.common.Parser.parse(Parser.java:256) at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.readParse(AbstractWebSocketConnection.java:679) at org.eclipse.jetty.websocket.common.io.AbstractWebSocketConnection.onFillable(AbstractWebSocketConnection.java:511)

Anything I did wrong? Thanks!

zcbmlijygrdwa avatar Apr 11 '18 06:04 zcbmlijygrdwa