How can I subscribe to Image topic on ROS Matlab and obtain the RGB image?

Illustration
Pedro Gusmao - 2023-06-06T14:25:59+00:00
Question: How can I subscribe to Image topic on ROS Matlab and obtain the RGB image?

Hello,   Please, how can I extract an image from a ROS Image Message followed by an imshow? I have already subscribed to the correct topic but message.getData() gives me a SlicedChannelBuffer object. Thanks,

Expert Answer

Profile picture of John Michell John Michell answered . 2025-11-20

ip="Your IP Address";
rosinit(ip);
%Command Velocity Publisher
robotCmd = rospublisher("/cmd_vel","DataFormat","struct") ;
velMsg = rosmessage(robotCmd);
%Camera Subscriber
img_sub = rossubscriber("/camera/rgb/image_raw","DataFormat","struct");
%Publish a constant angular velocity
velMsg.Angular.Z=0.5;
send(robotCmd,velMsg);
% Start timer
tic;
figure
while toc < 20
    %Image
    im = receive(img_sub);
    image = rosReadImage(im);
    imshow(image);
    
end
velMsg.Angular.Z=0.0;
send(robotCmd,velMsg);
rosshutdown;
disp("Network Shutdown");

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!