libfreenect Documentation

repository·master·Indexed 25 days ago

https://github.com/openkinect/libfreenect

A userspace driver for the original Microsoft Kinect supporting RGB/Depth images, motors, accelerometers, LEDs, and audio on Linux, OSX, and Windows. Includes the OpenNI2-FreenectDriver for bridging Kinect hardware to OpenNI2, Python wrappers, and Fakenect for session recording and playback.

Tokens
8.7K
Snippets
13
Records
67
Agent score
87%

What's inside libfreenect

  1. Compile libfreenect with Visual C++

    master

    To resolve C99 standard incompatibilities when compiling libfreenect with Visual Studio, force the project to compile all .c files as C++ code.

    Steps:

    1. Open Project Properties.
    2. Navigate to Properties >> C/C++ >> Advanced.
    3. Set Compile As to Compile as C++ Code (/TP).

    Note for MSVC versions prior to 2010: If the build still insists on using the C compiler, toggle the setting: set Compile As to Default, click Apply, then set it back to Compile as C++ Code (/TP), click Apply, and click OK.

    Project >> Properties >> C/C++ >> Advanced >> Compile As: Compile as C++ Code (/TP)
  2. Install libfreenect on OSX

    master

    You can install libfreenect on macOS using Homebrew or MacPorts.

    Homebrew Install the stable version or the latest development version (HEAD).

    MacPorts Install the necessary dependencies before proceeding with a manual build.

  3. Fetch and Build libfreenect from source

    master

    Follow these steps to clone and build the project using CMake. You can use CMake options to control specific build targets, such as Python wrappers or specific build types (debug vs optimized).

    git clone https://github.com/OpenKinect/libfreenect
    cd libfreenect
    mkdir build
    cd build
    cmake -L .. # -L lists all project options
    make
    
    # Alternative if 'make' is unavailable:
    # cmake --build .
  4. Install libfreenect on Linux (Ubuntu/Debian/Mint)

    master

    To build libfreenect on Ubuntu, Debian, or Mint, install the required build tools and dependencies. If you intend to run the provided examples, you must also install the OpenGL/GLUT development packages.

    Note: Remember to install the udev rules for your system to allow access to the Kinect device.

  5. Best practices for libfreenect on Windows

    master

    To ensure stability and performance when using libfreenect on Windows, follow these guidelines:

    1. Use a single freenect context: While multiple contexts might work in the future, currently only one context should be used.
    2. Yield the rendering thread: If your application performs direct rendering (e.g., OpenGL, Direct3D), call Sleep(1) immediately after your swap-buffers call (e.g., SwapBuffers(), glutSwapBuffers(), Present()) to reduce CPU usage.
    3. Thread-safe stream operations: Perform all stream operations (starting or stopping video/depth) only in the specific thread that calls freenect_process_events().

    Stream operations include:

    • freenect_start_video()
    • freenect_start_depth()
    • freenect_stop_video()
    • freenect_stop_depth()
  6. Install libfreenect on Windows

    master

    For Windows, use Zadig to install the libusbK driver for your Kinect device.

    When building with CMake, you must manually provide the paths to your libusb include and library directories so CMake can locate them.

    cmake .. -DLIBUSB_1_INCLUDE_DIR="C:\path\to\libusb\include" -DLIBUSB_1_LIBRARY="C:\path\to\libusb\libusb.lib"
  7. Install the OpenNI2-FreenectDriver

    master

    The OpenNI2-FreenectDriver allows OpenNI2 to use Kinect hardware on Linux and OSX by bridging it to libfreenect.

    Follow these steps to install:

    1. Download and unpack OpenNI version 2.2.0.33 or higher.
    2. Build libfreenect with the OpenNI2 driver enabled from the top libfreenect directory:
      mkdir build
      cd build
      cmake .. -DBUILD_OPENNI2_DRIVER=ON
      make
    3. Copy the driver files (libFreenectDriver.so or libFreenectDriver.dylib) to your OpenNI2 driver repository directory. You must update the Repository path variable in the command below to match your specific project layout.

    Note: The driver is built with a static libfreenect, so you do not need to include libfreenect separately when deploying. However, the target system must have libusb and all other dependencies listed in ldd libFreenectDriver.so installed.

    Repository="/example/path/to/Samples/Bin/OpenNI2/Drivers/"
    cp -L lib/OpenNI2-FreenectDriver/libFreenectDriver.{so,dylib} ${Repository}
  8. Set up libusb-win32 for Windows development

    master

    The Windows port of libfreenect uses a libusb-1.0 emulation layer (libusbemu) that relies on libusb-win32 to communicate with the Kinect. You must install libusb-win32 to use libfreenect on Windows.

    Installation: Download the latest snapshots of libusb-win32 from the official SourceForge repository: http://sourceforge.net/projects/libusb-win32/files/libusb-win32-snapshots