Send compressed image in a service request using roslibjs

asked 2016-09-26 20:03:18 -0500

waspinator gravatar image

updated 2016-09-29 10:53:18 -0500

In the example showing basic roslibjs functionality they show how to send a service request. The data they send is just two ints, which is what the AddTwoInts service expects.

I'm trying to create a service that expects a sensor_msgs/CompressedImage.

I have a service file with the following:

sensor_msgs/CompressedImage original_image
---
sensor_msgs/CompressedImage modified_image

and I try to call the function using roslibjs

    var request = new ROSLIB.ServiceRequest({
      original_image: {
        header: {
          seq: 1,
          stamp: "",
          frame_id: ""
        },
        format: "jpeg",
        data: compressed_image
      }
    });

    ProcessImageClient.callService(request, function(result) {
      console.log(result);
    });

but I'm not sure what I should be putting in for header. This seems to get a response from the service, but it doesn't make much sense. All I'm trying to do for now is send back the image, but instead I get almost nothing back. This is my service handler:

def handle_process_image(req):
    print "This is a test: returning back original image"
    return ProcessImageResponse(req.original_image)

def process_image_server():
    rospy.init_node('process_image_server')
    s = rospy.Service('process_image', ProcessImage, handle_process_image)
    print "Ready to process image."
    rospy.spin()

if __name__ == "__main__":
    process_image_server()

and this is what I get as a response.

Object { modified_image: {
     data: "AAAAAA==",
     format: "jpeg",
     header: Object
  }
}

My data is obviously mangled, as it's always "AAAAAA==".

My question is, how do I create a proper sensor_msgs/CompressedImage object to send with my service request, and how do I send a sensor_msgs/CompressedImage back to roblibjs?

Thanks

http://wiki.ros.org/roslibjs/Tutorial...

EDIT: I figured out that I wasn't actually sending the image data, so now that am it's working. Still not sure what to put for the header.

req.original_image.data seems to be binary data instead of text base64 encoded data.

This is what I get when I ranrospy.loginfo(req.original_image.data), whereas I expected a readable character string representing the base64 image. the output of eq.original_image.data is <type 'str'>

pW�E#����!P݆��ޗk�k�:�
ä�du]Sd�Z̺�tSۭ�4���;�q�Nq�⟲���哳�4-<k�f�[��.��3�c�������!X��-S`!
                                                               nlg������g���ȭ�*9���*���o��^��-���}���J�6Frq{������g�0b���=9���o�o%�B�@��W�G�
                                                                                                                                            �"��P��L��5��L�����U�-�88�]�TRv9�#M�<A|�֢Y�n��8�OA]�
                                                                                                                                                                                               u8��.��`��$���ؚ֯��|�Z�'v,�U9?Z��e"-���*�W2�,1�F?:�0��w&��}Q������$��Et����}���k����m��1O�WO��J��F���?�β�����+��{�����vQ���Sb-qu���=+��oF����j�)��Ob�����d��b��P?�?��u��AET�(��(��(��(��(��(��(����(�Q%J:V��u- ��
B)�h��?lj��_��0?¹,�o�Λn��p?5j�������)�RNW1�a@��H)š��--�}@P)Ԃ�N��ҝH�)=A3�a>W�]T�7���t^"�-�uң�RZ�iXc{�g���m$^���������F���`�k��^I��𮆕�)t8��3H�񧇮�O<�T�\]]ē}�_�(�8��
edit retag flag offensive close merge delete

Comments

Were you able to solve this problem?

mpenmet gravatar image mpenmet  ( 2018-08-18 22:43:06 -0500 )edit

I would also like to see more details on this. I want to send a (compressed) image on a topic, but don't know what format I should choose to display the image with javascript/html.

Good practice would be to answer your own question if you have the solution to your original problem.

knxa gravatar image knxa  ( 2018-09-25 13:34:58 -0500 )edit

Hey, Compressed image can be displayed on JS using Canvas. The data from ros compressed image can be converted to base64 using atob function.

mpenmet gravatar image mpenmet  ( 2018-09-29 21:56:13 -0500 )edit