Robotics StackExchange | Archived questions

ROS2 Foxy python cv_bridge img_to_cv2 broken

System:

ROS2 Foxy Raspberry Pi 4b (ARMv7) Buster (Debian 10) Raspberry Pi camera

I can publish an image topic using

from cv_bridge import CvBridge
...    
self.bridge = CvBridge()
...
self.publisher_.publish(self.br.cv2_to_imgmsg(frame))
...

And

$ros2 topic echo /image_raw --no-arr

header:
  stamp:
    sec: 0
    nanosec: 0
  frame_id: ''
height: 240
width: 320

    encoding: 8UC3
    is_bigendian: 0
    step: 960
    data: '<sequence type: uint8, length: 230400>'

But when I subscribe to the topic

    from rclpy.qos import qos_profile_sensor_data
    ...
    self.subscription =  self.create_subscription(
                     Image, 
                     'image_raw', 
                     self.callback, 
                     qos_profile_sensor_data)
            ...
        def callback(self, data):
            self.get_logger().info('Callback ...')
            cv_image = self.bridge.imgmsg_to_cv2(data)

The node crashes silently after the logger message (so the callback is called).

Looking through posts it looks like cv2toimgmsg only works with a c++ implementation. Is that correct, and if not is there a current python example for converting an Image message to a cv2 image?

Asked by mjohannessen on 2023-04-20 14:16:57 UTC

Comments

Answers