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

Kinect video Buffer is wrong size.

asked 2014-03-20 08:53:01 -0500

MTGGTL gravatar image

updated 2016-10-24 09:02:55 -0500

ngrennan gravatar image

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

edit retag flag offensive close merge delete

Comments

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.

ahendrix gravatar image ahendrix  ( 2014-03-21 07:04:40 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-09-12 09:40:59 -0500

dbs12 gravatar image

updated 2014-09-12 09:43:54 -0500

Hi,

For your problem I think you should try: /camera/rgb/image_color

Am trying to do the same thing but struggling to get data from kinect. Since it is question regarding same topic..I did not create a new post. Here is what am doing, if you see something missing please let me know:

  1. In terminal (using ros-groovy):

    roslaunch openni_launch openi.launch
    
  2. In Matlab:

    node = rosmatlab.node('NODE',master_uri)
    subscriber = rosmatlab.subscriber('/camera/rgb/image_rect','sensor_msgs/Image',10,node);
    imgMsg = rosmatlab.message('sensor_msgs/Image',node);
    
  3. I also tried the way you have mentioned but still no progress. Code does not enter in grabimage function.:(

    ImgSub.setOnNewMessageListeners({@grabimage});
    

It can be seen with rostopic info that NODE is subscribed to topic /camera/rb/image_rect but imgMsg.getData() is always zero.

Could you please tell if am missing any steps.

Thanks..:)

edit flag offensive delete link more

Comments

are you running matlab and the openni driver on the same computer or over a network?

ahendrix gravatar image ahendrix  ( 2014-09-13 00:11:18 -0500 )edit

at the moment it is on same computer but does it matter? bcoz. later it will be over a network

dbs12 gravatar image dbs12  ( 2014-09-13 11:25:30 -0500 )edit

Question Tools

Stats

Asked: 2014-03-20 08:53:01 -0500

Seen: 330 times

Last updated: Sep 12 '14