How to prepare sensor_msgs/CompressedImage without cv2?
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
?