ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

MTGGTL's profile - activity

2014-09-12 09:41:09 -0500 received badge  Student (source)
2014-09-12 08:07:52 -0500 received badge  Popular Question (source)
2014-09-12 08:07:52 -0500 received badge  Notable Question (source)
2014-09-12 08:07:52 -0500 received badge  Famous Question (source)
2014-03-21 06:51:13 -0500 received badge  Editor (source)
2014-03-20 08:53:01 -0500 asked a question Kinect video Buffer is wrong size.

I am using the Turtlebot2 with ROS and matlab. I have the plugin for control with Matlab. I have tried Mathwork's Turtlebot ROS demo and everything works very well on that end.

I am trying to make a simple script that will just take the RGB input from the on board kinect in the exact same way that the demo uses it. I have copied the code verbatim and I am running into an issue. The demo scripts (within TurtlebotCommunicator.m) grabs message.getData().array() which is a vector of length widthxheightx3 or the red, green and blue channels collated. For a 640x480 image, this vector is approximately 921600 points long, and indeed when I run the demo program in debug mode that is the buffer size that it receives. We I try to run my own version I receive a vector that is one third as long. I am not sure what the disconnect it.

Below is the code that I am running, and like I said, it is near verbatim what is written in the demo that I have proven to work. Thanks

function getimage

node = rosmatlab.node('NODE', '10.0.1.4', 11311); 
ImgSub = node.addSubscriber('/camera/rgb/image_raw', 'sensor_msgs/Image', 5);
ImgSub.setOnNewMessageListeners({@grabimage});

function grabimage(message)

width = message.getWidth();
height = message.getHeight();
offset = message.getData().arrayOffset()-2; 

if strcmp(message.getEncoding, 'bgr8')
    indexB = offset:3:width*height*3+offset-1;
    indexG = indexB+1;
    indexR = indexG+1;            
else                
    indexR = offset:3:width*height*3+offset-1;
    indexG = indexR+1;
    indexB = indexG+1;
end

imgCol = typecast(message.getData().array(), 'uint8');
img = reshape([imgCol(indexR); imgCol(indexG); imgCol(indexB)], width, height, 3);

img = permute(img, [2 1 3]);
imshow(img);

end

end