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
It sounds like you may be receiving a grayscale image instead of color. I don't know enough about matlab or matlab ROS to suggest more.