Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8b8c158
openni2: Copy OpenNI2-FreenectDriver from libfreenect 89f77f6d2c23876…
hanyazou May 9, 2015
9cbe0a7
openni2: Works with /opt/OpenNI2/Tools/NiViewer.
hanyazou May 10, 2015
4f1e7df
openni2: Add ItStream class
hanyazou May 15, 2015
7236306
openni2: Change name and directory, FreenectDriver -> Freenect2Driver
hanyazou May 24, 2015
f6e4a73
openni2: Change depth video mode from 512x424 to 640x480 to work with…
hanyazou May 31, 2015
7e7493b
openni2: Eliminate compile warnings in OpenNI2-Freenect2Driver
hanyazou Jun 6, 2015
cd4a96d
openni2: Add registration
hanyazou May 23, 2015
653451a
openni2: Move OpenNI2-Freenect2Driver into drivers/ sub directory
hanyazou Jun 13, 2015
7c0d3cf
openni2: Add timestamp on the frames
hanyazou May 23, 2015
f6bb18c
openni2: Change copying of color images to reflect the change from BG…
HenningJ Jun 15, 2015
048755d
openni2: Delete unused lines
hanyazou Jun 20, 2015
d4e47d3
openni2: Fix compile errors after last merge
hanyazou Jan 2, 2016
f6b2e9b
openni2: Have a member of libfreenect2::Freenect2 in the OpenNI2 driver
hanyazou Jul 3, 2015
6f76a8c
openni2: Use OpenNI2 logging functions/classes
hanyazou Jul 4, 2015
17b888e
openni2: Add OpenKinect Project's license headers
hanyazou Jul 4, 2015
11c122c
openni2: Delete OpenNI2 header files
hanyazou Jan 1, 2016
5992be3
openni2: Refactor setVideoMode() and getSensorInfo() in VideoStream c…
hanyazou Jan 1, 2016
6d37bae
openni2: Remove D2S.h adn S2D.h
hanyazou Jan 2, 2016
d67cac8
openni2: Update README.md
hanyazou Jan 2, 2016
38696ae
openni2: Add a cross-platform FindOpenNI2.cmake for Linux
hanyazou Jan 3, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SET(DEPENDS_DIR "${MY_DIR}/depends" CACHE STRING "dependency directory must be s

OPTION(BUILD_SHARED_LIBS "Build shared (ON) or static (OFF) libraries" ON)
OPTION(BUILD_EXAMPLES "Build examples" ON)
OPTION(BUILD_OPENNI2_DRIVER "Build OpenNI2 driver" OFF)
OPTION(ENABLE_CXX11 "Enable C++11 support" OFF)
OPTION(ENABLE_OPENCL "Enable OpenCL support" ON)
OPTION(ENABLE_OPENGL "Enable OpenGL support" ON)
Expand Down Expand Up @@ -268,3 +269,8 @@ IF(BUILD_EXAMPLES)
MESSAGE(STATUS "Configurating examples")
ADD_SUBDIRECTORY(${MY_DIR}/examples)
ENDIF()

IF(BUILD_OPENNI2_DRIVER)
MESSAGE(STATUS "Configuring OpenNI2 driver")
ADD_SUBDIRECTORY(${MY_DIR}/drivers/OpenNI2-Freenect2Driver)
ENDIF()
53 changes: 53 additions & 0 deletions cmake_modules/FindOpenNI2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# - Find OpenNI2
#
# OpenNI2_FOUND: true if OpenNI2 was found
# OpenNI2_INCLUDE_DIRS: the directory that contains the include file
# OpenNI2_INSTALL_DIR: the directory that contains the librariy file

IF(PKG_CONFIG_FOUND)
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
SET(MODULE "libopenni2")
IF(OpenNI2_FIND_REQUIRED)
SET(OpenNI2_REQUIRED "REQUIRED")
ENDIF()
PKG_CHECK_MODULES(OpenNI2 ${OpenNI2_REQUIRED} ${MODULE})
FIND_PATH(OpenNI2_INSTALL_DIR
NAMES ${OpenNI2_LIBRARIES}
HINTS ${OpenNI2_LIBRARY_DIRS}
)
SET(OpenNI2_INSTALL_DIR ${OpenNI2_LIBRARY})

RETURN()
ENDIF()
ENDIF()

FIND_PATH(OpenNI2_INCLUDE_DIRS
NAMES Driver/OniDriverAPI.h
PATHS
"/opt/include"
"/opt/local/include"
"/usr/include"
"/usr/local/include"
ENV OPENNI2_INCLUDE
PATH_SUFFIXES
"ni2"
"openni2"
)

FIND_PATH(OpenNI2_INSTALL_DIR
NAMES
libOniFile.so
libOniFile.dylib
PATHS
"/opt/lib"
"/opt/local/lib"
"/usr/lib"
"/usr/local/lib"
ENV OPENNI2_REDIST
PATH_SUFFIXES
ni2/OpenNI2/Drivers
OpenNI2/Drivers/lib
)

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenNI2 DEFAULT_MSG OpenNI2_INSTALL_DIR OpenNI2_INCLUDE_DIRS)
59 changes: 59 additions & 0 deletions drivers/OpenNI2-Freenect2Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12.1)

if(WIN32 AND NOT MINGW)
if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "d")
endif()
endif()

IF(NOT DEFINED CMAKE_BUILD_TYPE)
# No effect for multi-configuration generators (e.g. for Visual Studio)
SET(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose: RelWithDebInfo Release Debug MinSizeRel None")
ENDIF()

PROJECT(openni2_freenect2driver)

SET(MY_DIR ${openni2_freenect2driver_SOURCE_DIR})
SET(freenect2_ROOT_DIR ${MY_DIR}/../..)

FIND_PACKAGE(PkgConfig) # try find PKGConfig as it will be used if found
FIND_PACKAGE(OpenNI2 REQUIRED)

IF(TARGET freenect2)
MESSAGE(STATUS "Using in-tree freenect2 target")
SET(freenect2_LIBRARIES freenect2)
SET(freenect2_DLLS ${LIBFREENECT2_DLLS})
ELSE()
FIND_PACKAGE(freenect2 REQUIRED)
# Out-of-tree build will have to have DLLs manually copied.
ENDIF()

INCLUDE_DIRECTORIES(
${freenect2_INCLUDE_DIR}
${OpenNI2_INCLUDE_DIRS}
)

SET(OpenNI2-Freenect2Driver_src
src/ColorStream.cpp
src/DepthStream.cpp
src/IrStream.cpp
src/DeviceDriver.cpp
src/Registration.cpp
${freenect2_ROOT_DIR}/${LIBFREENECT2_THREADING_SOURCE}
)

SET(OpenNI2-Freenect2Driver_LIBRARIES
${freenect2_LIBRARIES}
)

SET(OpenNI2-Freenect2Driver_DLLS
${freenect2_DLLS}
)

ADD_LIBRARY(OpenNI2-Freenect2Driver ${OpenNI2-Freenect2Driver_src})

TARGET_LINK_LIBRARIES(OpenNI2-Freenect2Driver
${OpenNI2-Freenect2Driver_LIBRARIES}
)

INSTALL(TARGETS OpenNI2-Freenect2Driver DESTINATION "${OpenNI2_INSTALL_DIR}")
30 changes: 30 additions & 0 deletions drivers/OpenNI2-Freenect2Driver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
OpenNI2-Freenect2Driver
======================

OpenNI2-Freenect2Driver is a bridge to libfreenect2 implemented as an OpenNI2 driver.
It allows OpenNI2 to use Kinect for Windows v2 (K4W2) devices on Mac OS X. (and on Linux?)
OpenNI2-Freenect2Driver is derived from OpenNI2-FreenectDriver (https://github.com/OpenKinect/libfreenect/tree/master/OpenNI2-FreenectDriver).

Install
-------
Please refer libfreenect2 install documentation at first. This description assumes that you are familiar with the libfreenect2 build instruction.

1. You need [OpenNI](http://structure.io/openni) 2.2.0.33 or higher installed on your system and set the environment variables properly. You can use homebrew to install OpenNI if you use Mac OS X. And you will need to make sure target systems have libusb and all other dependencies also.

$ brew tap homebrew/science
$ brew install openni2

$ export OPENNI2_REDIST=/usr/local/lib/ni2
$ export OPENNI2_INCLUDE=/usr/local/include/ni2

2. Go to the top libfreenect2 directory and build it. The build option which enables to build this driver is OFF by default. You must specify -DBUILD_OPENNI2_DRIVER=ON in cmake argument. And you may specify additional -DENABLE_OPENGL=NO in cmake argument to use OpenNI2's NiViewer.

$ cd /some/where/libfreenect2
$ mkdir build
$ cd build
$ cmake -DBUILD_OPENNI2_DRIVER=ON ..
$ make

3. 'make install' copies the driver to your OpenNI2 driver repository (${OPENNI2_REDIST}/OpenNI2/Drivers)

$ make install
115 changes: 115 additions & 0 deletions drivers/OpenNI2-Freenect2Driver/src/ColorStream.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* This file is part of the OpenKinect Project. http://www.openkinect.org
*
* Copyright (c) 2015 individual OpenKinect contributors. See the CONTRIB file
* for details.
*
* This code is licensed to you under the terms of the Apache License, version
* 2.0, or, at your option, the terms of the GNU General Public License,
* version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
* or the following URLs:
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.gnu.org/licenses/gpl-2.0.txt
*
* If you redistribute this file in source form, modified or unmodified, you
* may:
* 1) Leave this header intact and distribute it under the same terms,
* accompanying it with the APACHE20 and GPL20 files, or
* 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
* 3) Delete the GPL v2 clause and accompany it with the APACHE20 file
* In all cases you must keep the copyright notice intact and include a copy
* of the CONTRIB file.
*
* Binary distributions must follow the binary distribution requirements of
* either License.
*/

#include <string>
#include "ColorStream.hpp"

using namespace Freenect2Driver;

// from NUI library & converted to radians
const float ColorStream::DIAGONAL_FOV = 73.9 * (M_PI / 180);
const float ColorStream::HORIZONTAL_FOV = 62 * (M_PI / 180);
const float ColorStream::VERTICAL_FOV = 48.6 * (M_PI / 180);

ColorStream::ColorStream(libfreenect2::Freenect2Device* pDevice, Freenect2Driver::Registration *reg) : VideoStream(pDevice, reg)
{
video_mode = makeOniVideoMode(ONI_PIXEL_FORMAT_RGB888, 1920, 1080, 30);
setVideoMode(video_mode);
}

// Add video modes here as you implement them
ColorStream::FreenectVideoModeMap ColorStream::getSupportedVideoModes() const
{
FreenectVideoModeMap modes;
// pixelFormat, resolutionX, resolutionY, fps
modes[makeOniVideoMode(ONI_PIXEL_FORMAT_RGB888, 512, 424, 30)] = 0;
modes[makeOniVideoMode(ONI_PIXEL_FORMAT_RGB888, 1920, 1080, 30)] = 1;

return modes;
}

void ColorStream::populateFrame(libfreenect2::Frame* srcFrame, int srcX, int srcY, OniFrame* dstFrame, int dstX, int dstY, int width, int height) const
{
dstFrame->sensorType = getSensorType();
dstFrame->stride = dstFrame->width * 3;

// copy stream buffer from freenect
switch (video_mode.pixelFormat)
{
default:
LogError("Pixel format " + to_string(video_mode.pixelFormat) + " not supported by populateFrame()");
return;

case ONI_PIXEL_FORMAT_RGB888:
if (reg->isEnabled()) {
libfreenect2::Frame registered(512, 424, 4);

reg->colorFrameRGB888(srcFrame, &registered);

copyFrame(static_cast<uint8_t*>(registered.data), srcX, srcY, registered.width * registered.bytes_per_pixel,
static_cast<uint8_t*>(dstFrame->data), dstX, dstY, dstFrame->stride,
width, height, mirroring);
} else {
copyFrame(static_cast<uint8_t*>(srcFrame->data), srcX, srcY, srcFrame->width * srcFrame->bytes_per_pixel,
static_cast<uint8_t*>(dstFrame->data), dstX, dstY, dstFrame->stride,
width, height, mirroring);
}
return;
}
}

void ColorStream::copyFrame(uint8_t* srcPix, int srcX, int srcY, int srcStride, uint8_t* dstPix, int dstX, int dstY, int dstStride, int width, int height, bool mirroring)
{
srcPix += srcX + srcY * srcStride;
dstPix += dstX + dstY * dstStride;

for (int y = 0; y < height; y++) {
uint8_t* dst = dstPix + y * dstStride;
uint8_t* src = srcPix + y * srcStride;
if (mirroring) {
dst += dstStride - 1;
for (int x = 0; x < srcStride; ++x)
{
if (x % 4 != 3)
{
*dst-- = *src++;
}
else
{
++src;
}
}
} else {
for (int x = 0; x < dstStride-2; x += 3)
{
*dst++ = src[2];
*dst++ = src[1];
*dst++ = src[0];
src += 4;
}
}
}
}
Loading