ruby-freenect

FFI-based Ruby wrapper for the OpenKinect library. ruby-freenect supports the following,

  • Video, IR and Depth

  • LED

  • Tilt

  • Accelerometer

Requirements

Interface

The interface is very simple. This section will give a brief description of all supported methods and attributes.

Video and Depth Modes

Video and depth modes are used to configure the video and depth data streams and provide info about the streams. Both are instances of the FreenectFrameMode. FreenectFrameMode attributes are shown below and may be accessed with []

  • :resolution - Resolution

  • :format - Video or depth format accessed using mode[:format][:video_format] or mode[:format][:depth_format]

  • :bytes - Total buffer size in bytes to hold a single frame of data,

  • :width - Width of the frame, in pixels

  • :height - Height of the frame, in pixels

  • :data_bits_per_pixel - Number of bits of information needed for each pixel

  • :padding_bits_per_pixel - Number of bits of padding for alignment used for each pixel

  • :framerate - Approximate expected frame rate, in Hz

  • :is_valid - If 0 is invalid and does not describe a supported mode. Otherwise, the frame_mode is valid.

The supported resolutions are,

  • :freenect_resolution_medium VGA - 640x480

The supported Depth Formats are.

  • :freenect_depth_11bit - 11 bit depth information in one uint16_t/pixel

  • :freenect_depth_10bit - 10 bit depth information in one uint16_t/pixel

  • :freenect_depth_11bit_packed - 11 bit packed depth information

  • :freenect_depth_10bit_packed - 10 bit packed depth information

The supported Video Formats are,

  • :freenect_video_rgb - Decompressed RGB mode

  • :freenect_video_bayer - Bayer compressed mode

  • :freenect_video_ir_8bit - 8-bit IR mode

  • :freenect_video_ir_10bit - 10-bit IR mode

  • :freenect_video_ir_10bit_packed - 10-bit packed IR mode

  • :freenect_video_yuv_rgb - YUV RGB mode

  • :freenect_video_yuv_raw - YUV Raw mode

Video Stream

The following methods are used to access and configure the video stream,

Return the number of supported video modes.

Freenect.get_video_mode_count

Return the video mode with the specified mode_id.

Freenect.get_video_mode(mode_id)

Return the configured video mode.

Freenect.get_current_video_mode

Return video mode with specified video_format.

Freenect.find_video_mode(video_format)

Return video frame with specified video_mode. This methods blocks until the video frame is available.

Freenect.get_video(video_mode)

Depth Stream

The following methods are used to access and configure the depth stream,

Return the number of supported depth modes.

Freenect.get_depth_mode_count

Return the depth mode with the specified mode_id.

Freenect.get_depth_mode(mode_id)

Return the configured depth mode.

Freenect.get_current_depth_mode

Return depth mode with specified depth_format.

Freenect.find_depth_mode(depth_format)

Return video frame with specified video_mode. This methods blocks until the video frame is available.

Freenect.get_depth(depth_mode)

Tilt

The following methods are used to access and change the kinect tilt configuration,

Set the Kinect tilt to the specified angle.

Freenect.set_tilt(angle)

Return the Kinect tilt state. Use the following methods to read the tilt state.

Freenect.get_tilt_state

Return the Kinect tilt angle from the tilt state.

Freenect.get_tilt(tilt_state)

Return the Kinect tilt status from the tilt state.

Freenect.get_tilt_status(tilt_state)

Return the acceleration vector components from the tilt state

Freenect.get_acceleration(tilt_state)

LED

The following methods are used to change the LED status,

Freenect.set_led(led_option)

The supported values for LED Option are,

  • :led_off Turn LED off

  • :led_green Turn LED to Green

  • :led_red Turn LED to Red

  • :led_yellow Turn LED to Yellow

  • :led_blink_green Make LED blink Green

  • :led_blink_red_yellow Make LED blink Red/Yellow

Miscellaneous methods

End the current session.

Freenect.stop

Return the number of Kinects.

Freenect.get_device_count

Examples

Several examples can be found at github.com/troystribling/ruby-freenect/tree/master/examples. The examples require the ruby-opengl2 gem and the mkrf gem.

Install libfreenect

If you have problems visit openkinect.org/wiki/Getting_Started#Manual_Build_on_Linux

Prerequisites

sudo apt-get install cmake libglut3-dev pkg-config build-essential libxmu-dev libxi-dev libusb-1.0-0-dev

sudo apt-get install autoconf automake

sudo apt-get install libltdl3-dev

Build and Install libusb

git clone git://git.libusb.org/libusb.git

./autogen.sh
make
sudo make install

Build and Install libfreenect

git clone git://github.com/OpenKinect/libfreenect.git

cd libreenect
mkdir build
cd build
cmake ..

make
sudo make install

Configure USB Interface

Add the following lines to the file usr-local-libs.conf

/usr/local/lib64
/usr/local/lib

Next enter the following commands

sudo su root
mv usr-local-libs.conf /etc/ld.so.conf.d/usr-local-libs.conf
/sbin/ldconfig -v

Copyright © 2012 Troy Stribling. See LICENSE.txt for details.