ROS2: bridge.cv2_to_imgmsg is very slow
Hello,
I wrote a simple image publisher. It loads rgb data from Realsense depth camera, converts them to sensor_msgs/msg/Image
via cv_bridge and publishes them. Problem is that command
msg = bridge.cv2_to_imgmsg(color_image, encoding="passthrough")
takes about one second, resulting to ~1fps publish rate. Lowering image resolution will help, but to have somewhat decent fps, resolution has to be as low as 320x240.
I dont have much expirience using ROS, please comment if additional information would help to decide what is wrong. Thanks for any help!
code from main:
rclpy.init(args=args)
bridge = CvBridge()
node = rclpy.create_node('image_publisher')
publisher = node.create_publisher(Image, 'image')
pipeline.start(config)
msg = Image()
def timer_callback():
# Convert images to numpy arrays
frames = pipeline.wait_for_frames()
color_frame = frames.get_color_frame()
color_image = np.asanyarray(color_frame.get_data())
# when commented out, publish rate is extremely high:
msg = bridge.cv2_to_imgmsg(color_image, encoding="passthrough")
print("Message published")
publisher.publish(msg)
timer_period = 0
timer = node.create_timer(timer_period, timer_callback)
rclpy.spin(node)
node.destroy_timer(timer)
node.destroy_node()
rclpy.shutdown()
Asked by CreaM on 2019-08-20 11:27:00 UTC
Comments