How to rectify the frame rate drop that occurs while subscribing to the topic of camera image from ROS in Simulink ?

16 views (last 30 days)
I am trying to observe the camera feed captured by ros in simulink and even though the image is being published at 30fps when i try to observe in Simulink it reduces to around 5fps. I have used to ROS toolbox to subscribe to /camera/image_color and used read image block to observe the images in Simulink Video Viewer but the fps is 5 not 30 even though i checked the hz of the topic and verified it to be 30. Any possible solution to rectify this issue

Answers (1)

Cam Salzberger
Cam Salzberger on 28 Jan 2019
Hello Arun,
There are two major potential sources for the delay that I can think of offhand. One is that using subscribers on the topic involves copying the data in the message. For large amounts of data, like images, this can take considerable time. I would suggest ensuring that you are making use of enabled subsystems (enabling them with the IsNew output from the Subscribe block), to avoid passing along and copying data that is not actually from a new message. This also should cut down on time by avoiding processing non-new messages.
Another (usually larger) factor in slowing down processing of anything is visualization. In MATLAB, this typically comes from plotting data or outputting text to the Command Window. In Simulink, this includes using Scopes or viewing images. If your model is sensitive to the rate, I would highly suggest removing all visualization while the model is running. Instead, collect the output for later viewing.
Another possibility, if you are testing an algorithm, is to collect the camera data and save it, then process the file through your algorithm later. You can either save the data as a rosbag on your ROS machine or subscribe to the topic from within MATLAB, directly saving the data to a MAT file. If you are able to update to R2018b, you could even play back the rosbag within Simulink, and process the data with model time synced to the rosbag timestamps.
Hope this helps you to get things moving.
-Cam
  1 Comment
arun joshi
arun joshi on 29 Jan 2019
hello Cam,
Thanks for the response. Since i am trying to do image processing in Matlab from the images acquired from ROS and send out information based on the processed image to ROS, i cant really record the data and playback as i am looking for ways where i can make use of Matlab computing capability of my PC parallel to ROS to support the robot's decisipon making. I have tried the other two suggestions from you but was unsuccessful in improving the frame rate. I have yet again checked the average rate in ROS and it shows 30 but at simulink it is still around 5-6 frames per second. Do you have any other suggestions?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!