Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does exist an example to send/receive images? #6

Open
jabrena opened this issue Jun 28, 2017 · 2 comments
Open

Does exist an example to send/receive images? #6

jabrena opened this issue Jun 28, 2017 · 2 comments

Comments

@jabrena
Copy link

jabrena commented Jun 28, 2017

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

@jmacglashan
Copy link
Contributor

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.

@zcbmlijygrdwa
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants