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?
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
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.
Asked: 2020-09-29 08:07:53 -0500
Seen: 2,559 times
Last updated: Sep 29 '20
error while launching lslidar_c16
Where can I find exaustive list of error codes with description for ROS?
Command 'roswtf' not found,installation failed.
Package for lidar obstacle detection
Nvidia driver problem in Ubuntu 18.04 host with a ros-kinetic-desktop-full docker
gmapping slam with multiple turtlebot3's as dynamic obstacles
ServiceServer declaration within a class
op_local_planner m_TrajectoryCosts.size() Not Equal m_GeneratedRollOuts.size() error