Tuesday, April 3, 2012

Testing Openni Kinect with ROS

Openni Kinect with ROS

 ROS is an operating system developed at Stanford Artificial Intelligence Lab in 2008 .

Once you have followed the instructions provided here and installed everything accordingly, you might still face some problems, e.g
  • Rviz crashes with "Bad Drawable" command. 
[Fix]:  Remove the ".rviz" folder by typing "rm -rf .rviz" assuming you are in your home directory.

Frame Rate drop
You might come across this problem if you have just installed your linux and started running openni_kinect programs. You might notice that a considerable frame drop if you add a 'point cloud' display along with an 'image/camera' display in 'rviz'.
[Fix]: Check that you have installed the Graphics driver on your system :)

Playing Depth Data with Rosbag
You might have a problem playing 'depth' data rosbag. You might want to follow following steps.
Recording data
rosbag record -O depth_data.bag /camera/depth/image_raw

Playing data 
rosbag play depth_data.bag

Visualizing data
[1] rosrun rviz rviz   'or'
[2] rosrun image_view image_view image:=/camera/depth/image_raw

Running python API for Rosbag
Make sure you have set the path variable and add these two lines to the top of your main python script to avoid any dependency errors.

import roslib; roslib.load_manifest('your_package_name')

then write your rest of the script. Please keep in mind that this does not need to be in every python script but just in the main entry point.
Depth and RGB synchoronization 
RGB and depth data from Kinect are not synchronized  so you have to enable it. Thanks to ROS who does it for us. You just need to run the following
[1] Run the node which publishes the topics e.g roslaunch openni_launch openni.launch
[2] rosrun dynamic_reconfigure reconfigure_gui
[3] Goto the /Camera/drivers and then check the depth registration check box.

Now your both RGB and depth data are synchronized :)

Openni User Tracker on Linux Demo

Recording Point Cloud

When you record large amount of data published by some topics such as point clouds the system's memory gets exhausted.
What you might want to do is :
If you don't need all of this data, you can use the topic tools to drop or throttle messages, or the rostopic --filter to get rid of some messages.
Recording bag files in  a distributed way
Note: For those who want to record data from on board camera of a quadcopter

You can run the quadcopter on one PC and the recorder {camera driver on the other so that the load on recording machine is not that much }
export ROS_MASTER_URI=http://ip_address:port
Remember to do it in every terminal if you are using multiple
run camera launch on the one where you want to record the data

Subscribing data to a bag file publishers


  1. Hi Alex,
    Sorry for the late response, was busy in my thesis submission. It is just a screen capture. There can be alternatives as well
    1. In ROS you can record a bag file, then using rxbag you can dump the images and create a movie out of the images.

    2. Using OpenNI you can record the '.oni' file and then you can again convert these images in the '.oni' file to Opencv images and then write them to a video file.

    Hope it helps :)

  2. Its easy run openni_tracker u openni_kinect with oni file, but i have problems with files of type .bag (rosbag). I don't know how make or configure the xml files or the connection. (wpairo@gmail.com)