Robotics StackExchange | Archived questions

How to make MATLAB VideoReader recognize ROS Image Topic stream?

I would like to know how to implement a camera stream/bridge Between MATLAB and ROS for applying Computer Vision built-in tools in the simulation generated images.

I am now using the standard MATLAB x ROS bridge, but not sure how to make the image topics to be recognized as a video input for the MATLAB's VideoReader. I wish to, for example, use ROS camera data as a "video input", for the demo example in this tutorial sample.

I have made this code so far in MATLAB, which gives me some kind of "video stream", with a big delay between frames, and not recognized by MATLAB VideoReader:

% default cleanup commands
clc
clear all
close all


% closing eventual ROS service before starting
rosshutdown

%launching ROS
rosinit('http://localhost:11311');

%setting up a subscriber for the interest message/topic
rgbsub = rossubscriber('/realsense/color/image_raw');

% tentative to break the infinit loop while requesting data from ROS
f = figure(1);
control = true;
while control
    rgbscan = receive(rgbsub, 5); % acquiring data form ROS
    myRGB = readImage(rgbscan); %reading the data as a MATLAB friendly data
    imshow(myRGB); % displaying the image
    isKeyPressed = ~isempty(get(f,'CurrentCharacter')); % trick to break the infinit loop
     if isKeyPressed
         control = false;
         close all
         %break
     end
end

rosshutdown % shutting down ROS...

Asked by msantos on 2021-03-22 16:15:46 UTC

Comments

Answers