Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ROS image topic framerate is extremely low

I'm trying to get VREP vision sensor output processed with opencv via ROS api. I did manage to set up scene and get scripts running, but the problem is that I get somewhat like 4-5 fps even without actual processing (currently I just push images directly to output).

This issue does not seem to depend on image resolution, since both 1024*512 and 128*128 captures result in exactly the same fps.

This also is not a matter of blocking calls, although I'm posting single-theaded code, I do have quite complex multithreaded processing pipeline which performs rather well with actual cameras (~50 fps).

Lua scripts on VREP's side do not seem to be a problem also, since I've tried to play with video retranslation examples provided by vrep, and they seem to achieve rather satisfying fps.

So it seems like image streaming is a bottleneck.

Here's my sample script:

# coding=utf-8

import rclpy
import rclpy.node as node
import cv2
import numpy as np
import sensor_msgs.msg as msg

import third_party.ros.ros as ros

class TestDisplayNode(node.Node):
    def __init__(self):
        super().__init__('IProc_TestDisplayNode')
        self.__window_name = "img"
        self.sub = self.create_subscription(msg.Image, 'Vision_sensor', self.msg_callback)

    def msg_callback(self, m : msg.Image):
        np_img = np.reshape(m.data, (m.height, m.width, 3)).astype(np.uint8)
        self.display(np_img)

    def display(self, img : np.ndarray):
        cv2.imshow(self.__window_name, cv2.cvtColor(img, cv2.COLOR_RGB2BGR))
        cv2.waitKey(1)

def main():
    ros_core = Ros2CoreWrapper()

    node = TestDisplayNode()

    rclpy.spin(node)

    node.destroy_node()
    rclpy.shutdown()

if __name__ == "__main__":
    main()

I also have to mention that I run it with ros bridge, since I need processing done with python3, which is supported by ROS2 only, and VREP seems to work only with ROS1 (although I'm just starting to work with these systems, so I'm not confident in that case).

like image 527
Roman Avatar asked Nov 08 '22 04:11

Roman


1 Answers

I got a similar issue with a slow python.

I used the flag -OO : https://docs.python.org/3/using/cmdline.html#cmdoption-o which decreased the execution time.

Also, a new issue has been filed: https://github.com/ros2/rosidl_python/issues/9 showing how conversion of message objects can be improved for python.

like image 55
Stoogy Avatar answered Nov 15 '22 12:11

Stoogy