ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

what is the simpliest way to publish and subscribe an image

asked 2020-09-29 08:07:53 -0500

glenn_ford7 gravatar image

what is the simpliest way to publish and subscribe an image , example i have dog.png can this be posible in python?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-10-02 03:02:46 -0500

lfvm0001 gravatar image

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

edit flag offensive delete link more
1

answered 2020-09-29 08:48:47 -0500

Majed gravatar image

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.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2020-09-29 08:07:53 -0500

Seen: 2,559 times

Last updated: Sep 29 '20