Saturday, February 28, 2015
Receive and display Kinect RGB and depth image from ROS using Matlab rosjava and matlab bridge interface
How-i-fixed-it:
Me and Google worked out together, how to get it done.
I used the ROS-Matlab Bridge created by Tingfan Wu at UCSD, which is based on rosjava. It can be downloaded under: https://code.google.com/p/mplab-ros-pkg/wiki/java_matlab_bridge.
The setup is described on the project page.
Next i did a svn checkout of the repository http://mplab-ros-pkg.googlecode.com/svn/trunk
The trunk has some updated files compared to the zip download dated 2012-10-23.
The project can either be used to run your own ROS master locally or to connect to another ROS master somewhere on the network. The HelloWorld.m example script is the point to start to make yourself familiar with the functionality of the software.
Based on this examples, i created my own script to subscribe to a kinect Images Publisher on my local network. I subsribed to the topics /camera/rgb/image_color and /camera/depth/image_rect.
I found the right hints on how to convert the sensor_msgs/Image message data to MATLAB Images here: https://alliance.seas.upenn.edu/~meam620/wiki/index.php?n=Roslab.KinectMatlab, written by Ben Cohen. My implementation is a little different to theirs, but it was a good point to start.
Heres my final result:

Heres the MATLAB script:
%Init rosjava first
sub_depth=edu.ucsd.SubscriberAdapter(node,/camera/depth/image_rect,sensor_msgs/Image);
logger.warn(timeout);
else
%Read the timestamp
%Calculate the fps for frames > 0
if(frame == 1)
data = typecast(msg.data,uint8);
%format RGBRGBRGB.... beginning with the upper left image pixel
%(0,0). This format has to be converted to matlab format
logger.warn(timeout);
else
%format RGBRGBRGB.... beginning with the upper left image pixel
%(0,0). This format has to be converted to matlab format
img_depth = reshape(typecast(msg.data,single), msg.width, msg.height);
Some more info and connecting ROS and MATLAB can be found here: http://www.ros.org/wiki/groovy/Planning/MatlabMy System configuration:
Windows 8 Enterprise 64 Bit
Matlab 2013a 64 Bit
guava-13.0.1.jar
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment