Skip to content

Commit

Permalink
Merge pull request #358 from piedar/OpenNI2-FreenectDriver
Browse files Browse the repository at this point in the history
OpenNI2-FreenectDriver
  • Loading branch information
piedar committed Jan 19, 2014
2 parents 2d4d053 + 529958b commit 518688a
Show file tree
Hide file tree
Showing 31 changed files with 7,827 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ OPTION(BUILD_CPP "Build C++ Library (currently header only)" ON)
OPTION(BUILD_CV "Build OpenCV wrapper" OFF)
OPTION(BUILD_AS3_SERVER "Build the Actionscript 3 Server Example" OFF)
OPTION(BUILD_PYTHON "Build Python extension" OFF)
OPTION(BUILD_OPENNI2_DRIVER "Build libfreenect driver for OpenNI2" OFF)
IF(PROJECT_OS_LINUX)
OPTION(BUILD_CPACK "Build an RPM or DEB using CPack" OFF)
ENDIF(PROJECT_OS_LINUX)
Expand Down Expand Up @@ -153,6 +154,10 @@ IF(BUILD_PYTHON)
add_subdirectory (wrappers/python)
ENDIF()

IF(BUILD_OPENNI2_DRIVER)
add_subdirectory(OpenNI2-FreenectDriver)
ENDIF()

######################################################################################
# Extras
######################################################################################
Expand Down
22 changes: 22 additions & 0 deletions OpenNI2-FreenectDriver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
######################################################################################
# OpenNI2-FreenectDriver
######################################################################################

file(GLOB SOURCES src/*.cpp)
add_library(FreenectDriver SHARED ${SOURCES})

set(CMAKE_CXX_FLAGS "-Wno-gnu-static-float-init -Wno-unused-function")

set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib/OpenNI2-FreenectDriver)
set_target_properties( FreenectDriver PROPERTIES
VERSION ${PROJECT_VER}
SOVERSION ${PROJECT_APIVER}
OUTPUT_NAME FreenectDriver)

include_directories(extern/OpenNI-Linux-x64-2.2.0.33/Include)
include_directories(${PROJECT_SOURCE_DIR}/wrappers/cpp)

target_link_libraries(FreenectDriver freenectstatic ${MATH_LIB})

install (TARGETS FreenectDriver
DESTINATION "${PROJECT_LIBRARY_INSTALL_DIR}/OpenNI2-FreenectDriver")
46 changes: 46 additions & 0 deletions OpenNI2-FreenectDriver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
OpenNI2-FreenectDriver
======================

OpenNI2-FreenectDriver is a bridge to libfreenect implemented as an OpenNI2 driver.
It allows OpenNI2 to use Kinect hardware on Linux and OSX.
It was originally a [separate project](https://github.com/piedar/OpenNI2-FreenectDriver) but is now distributed with libfreenect.
OpenNI2-FreenectDriver is distributed under the Apache 2 license.

Install
-------
1. Download and unpack [OpenNI](http://www.openni.org/openni-sdk/) 2.2.0.33 or higher.
2. Build libfreenect with the OpenNI2 driver.

mkdir build && cd build
cmake .. -DBUILD_OPENNI2_DRIVER=ON
make

3. Copy the driver to your OpenNI2 driver repository.

Repository="/example/path/to/Samples/Bin/OpenNI2/Drivers/"
cp -L lib/OpenNI2-FreenectDriver/libFreenectDriver.{so,dylib} ${Repository}

OpenNI2-FreenectDriver is built with a static libfreenect, so you do not need to include libfreenect when deploying.
However, you will need to make sure target systems have libusb and all other libfreenect dependencies.

__________________________________________________

Structure
---------
This driver is modeled on TestDevice.cpp and Drivers/Kinect/. In the FreenectDriver namespace, it ties together the C++ interfaces of OpenNI2 and libfreenect using multiple inheritance.

Driver inherits publically from oni::driver::DriverBase and privately from Freenect::Freenect. A custom libfreenect.hpp allows protected access to the Freenect context, so that FreenectDriver can call the Freenect's C API. As a DriverBase, FreenectDriver manages devices and sets up device state callbacks.

Device inherits publically from oni::driver::DeviceBase and Freenect::FreenectDevice. Because of this, it can be built by Freenect::Freenect::createDevice() and it can define Device's depth and video callbacks. Those callbacks trigger acquireFrame() in FreenectStream.

VideoStream is a virtual base class inheriting from oni::driver::StreamBase. It does generic frame setup in buildFrame() and then calls pure virtual populateFrame() to let derived classes finish the frame. It also provides the base skeleton for setting and getting properties, which cascades down the inheritance tree.

DepthStream and ColorStream are nearly identical in definition and implementation, both inheriting from VideoStream. They differ mostly in the formats they use to process data and the video modes they support. These two classes offer a system to store and report supported video modes. To implement a new mode, simply add it to getSupportedVideoModes() and modify populateFrame() if necessary.

__________________________________________________

Todo
----
* support more FREENECT_RESOLUTION_\*, FREENECT_VIDEO_\*, and FREENECT_DEPTH_\*
* provide more OniVideoMode and OniStreamProperty
* implement remaining derived functions
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*****************************************************************************
* *
* OpenNI 2.x Alpha *
* Copyright (C) 2012 PrimeSense Ltd. *
* *
* This file is part of OpenNI. *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* *
*****************************************************************************/
#ifndef _ONI_PLATFORM_ANDROID_ARM_H_
#define _ONI_PLATFORM_ANDROID_ARM_H_

// Start with Linux-x86, and override what's different
#include "../Linux-x86/OniPlatformLinux-x86.h"

//---------------------------------------------------------------------------
// Platform Basic Definition
//---------------------------------------------------------------------------
#undef ONI_PLATFORM
#undef ONI_PLATFORM_STRING

#define ONI_PLATFORM ONI_PLATFORM_ANDROID_ARM
#define ONI_PLATFORM_STRING "Android-Arm"

#ifdef HAVE_ANDROID_OS
#define ONI_PLATFORM_ANDROID_OS

#undef ONI_PLATFORM_STRING
#define ONI_PLATFORM_STRING "AndroidOS-Arm"
#endif

#endif //_ONI_PLATFORM_LINUX_ARM_H_
Loading

0 comments on commit 518688a

Please sign in to comment.