what is the simpliest way to publish and subscribe an image
what is the simpliest way to publish and subscribe an image , example i have dog.png can this be posible in python?
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
what is the simpliest way to publish and subscribe an image , example i have dog.png can this be posible in python?
I found these two examples to be very good they are in C++
http://wiki.ros.org/image_transport/T...
http://wiki.ros.org/image_transport/T...
another example in python:
http://wiki.ros.org/cv_bridge/Tutoria...
From my experience I found the python image publisher and subscriber a little slow. I would recommend to code them in C++ if possible.
Hi !! You can open the image using opencv, and then convert it using cv_bridge (http://wiki.ros.org/cv_bridge) into a ROS image message:
note: dont forget to import: import cv2 and from cv_bridge import CvBridge and also from sensor_msgs.msg import Image
pub = rospy.Publisher('img_rviz', Image, queue_size=10)
if os.path.isfile(img_path):
img = cv2.imread(img_path)
bridge = CvBridge()
img_msg = bridge.cv2_to_imgmsg(img, encoding="passthrough")
pub.publish(img_msg)
if you are using rviz you can check the image, adding an image display and suscribing to the topic (in this case "img_rviz") and observe the desire image
Hope this helps
Asked: 2020-09-29 08:07:53 -0500
Seen: 2,520 times
Last updated: Sep 29 '20