Ask Your Question
0

How to prepare sensor_msgs/CompressedImage without cv2?

asked 2020-07-27 10:04:19 -0500

Py gravatar image

I would like to publish a .png image so that it can be viewed on a web GUI using roslibjs. I have read that this must be of the format sensor_msgs/CompressedImage for roslibjs compatibility.

in my main.js file I have:

        let image_topic = new ROSLIB.Topic({
            ros: this.ros,
            name: '/image',
            messageType: 'sensor_msgs/CompressedImage'
        })
        image_topic.subscribe(function(message) {
            document.getElementById("image").src = "data:image/png;base64," + message.data;
            image_topic.unsubscribe();
        })

However, I am unsure how to prepare the image correctly for this in Python. I am struggling to understand what to put in msg.data. Some examples online use cv2 but I have struggled with that because other dependencies are forcing me to stay with Python 2 for now. Here's what I have so far:

    image = plt.imread('image.png')
    msg = CompressedImage()
    msg.header.stamp = rospy.Time.now()
    msg.format = "png"
    msg.data = ????????

Any ideas how to provide what msg.data needs without cv2?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-07-27 17:31:48 -0500

Typically, I'd interact with compressed images via http://wiki.ros.org/image_transport (and really all image streams). If there's a javascript binding for it, you should use that.

edit flag offensive delete link more

Comments

Ok sounds interesting. How would I used this to import and compress an image to publish? Is there a suitable alternative for Python?

Py gravatar image Py  ( 2020-07-28 01:32:12 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-07-27 10:04:19 -0500

Seen: 256 times

Last updated: Jul 27 '20