subscribe image slow on rospy with python3 and melodic
I've seen several issues posted about rospy being slow to subscribe to images in particular:
https://answers.ros.org/question/5011... https://answers.ros.org/question/2967... https://answers.ros.org/question/2123... https://answers.ros.org/question/2205... https://answers.ros.org/question/3629... https://github.com/ros2/ros2/issues/509
On Jetson Xavier NX with L4T (ARM) image 32.4.4, I've tried all of the advice listed in those issues, namely:
setting
PYTHONOPTIMIZE=0
env varusing queue_size for asynchronous subscriber
Using buffer size to buffer large images completely (1280x720 raw images at ~24 fps):
rospy.Subscriber(image_topic, Image, image_callback, queue_size=1, buff_size=100428800)
Connecting over ethernet to the other machine publishing the images at 24 fps (rosbag)
Still I am only achieving a max of 2.5 FPS subscription rate, which is unacceptable for real-time image processing. Any other suggestions for how to speed up subscribing images?
my image callback is just logging the FPS. In roscpp subscribing to this same image topic does not have a significant lag. Am I hitting a fundamental limit of python(3)?
# all code besides ros spin and imports. Topic published by rosbag as 1280x720 rgb raw image
def image_callback(self, data):
current = rospy.get_time()
rospy.loginfo(f"image FPS: {1/(current - self.last_time)}")
self.last_time = current
Note that I had to build ros from source setting python executable to python3 in order to use python3 packages with ros melodic.
I lowered the image resolution (using image_proc) down to less than half the original on my laptop, which has a much better CPU and so with the Xavier NX only deserializing 512x256 images the FPS jumped >15! So I guess RTSP would be better suited for low-end processors than Ros?