Difference between revisions of "OpenNI2"

From Wiki for iCub and Friends
Jump to: navigation, search
(Created page with " Installation Download and install OpenNI2. The best option is from github: git clone ..... On Debian testing (jessie), you have to make small changes: 1) pthread 2) commen...")
 
m (Troubleshooting for OS X: -> macOS)
 
(66 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
The OpenNI2 device driver for YARP exposes streams of data (color and depth videos, skeleton user tracking) from RGB-D sensors, including: Asus Xtion Pro, Kinect v1 and Kinect v2 (soon).
  
 +
Note: other projects with similar purposes exist:
 +
# [http://www.yarp.it/classyarp_1_1dev_1_1depthCameraDriver.html YARP depthCamera plugin], based on OpenNI 2;
 +
# https://github.com/robotology/kinect-wrapper, based on OpenNI 1 or Microsoft Kinect SDK;
 +
# [http://wiki.icub.org/yarpdoc/group__kinect__openni.html Kinect YARP device driver], also based on OpenNI 1.
  
Installation
+
= Installation =
  
Download and install OpenNI2. The best option is from github:
+
This driver was tested on Debian Jessie (stable), Ubuntu 12.04+ and macOS 10.8.4+.
git clone .....
 
  
On Debian testing (jessie), you have to make small changes:
+
== Dependencies ==
1) pthread
 
2) comment supress errors
 
  
cd in the directory
+
For Debian and Ubuntu, install the following dependencies:
 +
sudo apt-get install g++ python libusb-1.0-0-dev libudev-dev freeglut3-dev doxygen graphviz libxmu-dev libxi-dev
 +
Also, you must have installed a Java SDK (Oracle recommended).
  
make
+
Debian Wheezy (oldstable) is not supported by OpenNI2, due to glibc version being < 2.14.
  
cd Packaging
+
For macOS, the above packages are either preinstalled or available through Homebrew.
  
./Release x64 or x86
+
== OpenNI2 ==
  
cd Final
+
Install OpenNI2 (from zip packages or from GitHub source - see http://structure.io/openni) and NiTE2.
  
 +
For macOS, OpenNI2 is also available through Homebrew.
  
NiTE2
+
== Environment variables ==
  
Download, extract, run instal.sh
+
Follow the installation instructions for OpenNI2 and NiTE2 by running the respective install.sh scripts. These scripts will create two files called OpenNIDevEnvironment and NiTEDevEnvironment. To copy their content permanently into your .bashrc, do:
 +
cat OpenNIDevEnvironment >> ~/.bashrc
 +
cat NiTEDevEnvironment >> ~/.bashrc
  
add source ..../OpenNidev
+
At the end of this process, you will have these environment variables:
ad source ..../NiTEDev
+
OPENNI2_INCLUDE: full path to OpenNI2/Include
 +
OPENNI2_REDIST: full path to OpenNI2/''arch''-Release
 +
NITE2_INCLUDE: full path to NiTE-''OS''-''arch''-2.x
 +
NITE2_REDIST64 or NITE2_REDIST: full path to NiTE-''OS''-''arch''-2.x/Redist
 +
where ''OS'' = Linux, ''arch'' = x64 or x86.
  
log in/log out or source ~bashrc
+
== Enabling OpenNI2 YARP driver ==
  
in YARP.
+
In the CMake configuration for YARP, set the following:
 +
CREATE_DEVICE_LIBRARY_MODULES ON
 +
ENABLE_yarpmod_OpenNI2DeviceServer ON
 +
ENABLE_yarpmod_OpenNI2DeviceClient ON
  
Enable devices
+
== Finalizing the installation ==
SET OpenNI2DeviceServer to ON
 
set OpenNI2DeviceClient to ON
 
  
set INSTALL WITH RPATH to ON
+
These final steps are necessary to not incur in runtime errors like ''Couldn't create user tracker''.
  
Usage:
+
The OpenNI2 YARP driver must always be called from a directory that contains a copy (or symbolic link) of the NiTE.ini file from the stock NiTE2 distribution, properly configured. To prepare such a setup, do something along these lines:
 +
mkdir ~/yarp_openni2_root
 +
cd ~/yarp_openni2_root
 +
cp $NITE2_REDIST64/NiTE.ini .
 +
// or if you have the 32-bit version:
 +
// cp $NITE2_REDIST/NiTE.ini .
  
Options:
+
Edit NiTE.ini, setting DataDir to be the full path to $NITE2_REDIST64/NiTE2 (or $NITE2_REDIST/NiTE2).
  
--device
+
Now you're ready to call the yarpdev command from the yarp_openni2_root directory.
  
--playback filename.oni
+
= Support for different RGB-D cameras =
    Playbacks the specified oni file.
 
  
--loop
+
== PrimeSense-compatible sensors ==
    Forces the playback to loop. If not used, the playback will stop after one run.
 
  
--record filename.oni
+
These sensors (Asus Xtion, Carmine) work out of the box with the driver.
    records to the specified oni file
 
  
--name
+
== Kinect v1 ==
    chenge default port prefix (default=/OpenNI2)
 
--noCameras
 
    use only user tracker
 
  
--noMirror
+
Install [https://github.com/OpenKinect/libfreenect libfreenect], including the OpenNI2-freenect bridge. Then copy (or create a symbolic link of) libFreenectDriver.so inside yarp_openni2_root/OpenNI2/Drivers.
    disable mirroring
 
--noUserTracking
 
  
--minConfidence x (double)
+
== Kinect v2 ==
    set minimum confidence required. Default is 0.6
 
Doesn't start the user tracker.
 
  
--
+
Support coming soon.
  
The driver opens three ports:
+
= Usage =
imageFrame:o
 
depthFrame:o
 
userTracker:o
 
  
imageFrame and depthFrame stream YARP images, and if connectd to a yarpview, the video is available.
+
To print a list of all available options (help):
UserTracker outputs bottles in the format:
+
yarpdev --device OpenNI2DeviceServer --verbose
  
 +
General options:
 +
{| class="wikitable" border="1"
 +
|-
 +
!  option
 +
!  description
 +
!  default
 +
|-
 +
|  --name
 +
|  Set port prefix.
 +
|  /OpenNI2
 +
|-
 +
|  --printVideoModes
 +
|  Print supported video modes.
 +
 +
|-
 +
|  --depthVideoMode
 +
|  Set depth camera video mode.
 +
|  0 (i.e., 320x240 @ 30fps)
 +
|-
 +
|  --colorVideoMode
 +
|  Set color (RGB) camera video mode.
 +
|  0 (i.e., 320x240 @ 30fps)
 +
|-
 +
|  --noRGB
 +
|  Disable color (RGB) camera, while keeping depth sensor and user skeleton enabled. Useful for RGB-less sensors and to reduce CPU load.
 +
|  off (i.e., RGB on)
 +
|-
 +
|  --noRGBMirror
 +
|  Disable mirroring for the color (RGB) stream. Mirroring causes the stream to appear as if seen in a mirror, i.e., the image is transformed by reflecting all pixels across the vertical axis.
 +
|  off (i.e., mirroring on)
 +
|-
 +
|  --noDepthMirror
 +
|  Disable mirroring for the depth stream. Mirroring causes the depth to appear as if seen in a mirror, i.e., the image is transformed by reflecting all pixels across the vertical axis.
 +
|  off (i.e., mirroring on)
 +
|-
 +
|  --noUserTracking
 +
|  Disable skeleton user tracking. Useful to reduce CPU load.
 +
|  off (i.e., user tracking on)
 +
|-
 +
|  --minConfidence x (double)
 +
|  Set minimum confidence required by skeleton user tracking.
 +
|  0.6
 +
|-
 +
|  --syncFrames
 +
|  Keep color and depth frames always in temporal sync.
 +
|  off
 +
|-
 +
|  --imageRegistration
 +
|  Align color and depth video streams. This computation is performed on the sensor hardware.
 +
|  off
 +
|}
  
To use the driver in an application:
+
Other options related to recording and playback:
Tested in Debian Jessie (testing), Ubuntu 12.04+ and Mac OS X 10.8.4+
+
{| class="wikitable" border="1"
The OpenNI2 and NiTE software does not work with Debian Wheezy (stable) due to glibc < 2.14
+
|-
Many thanks to Giovanni Saponaro for his help and suggestions during development and testing of the driver.
+
!  option
 +
!  description
 +
!  default
 +
|-
 +
|  --record filename.oni
 +
|  Record (save) to the specified oni file.
 +
 +
|-
 +
|  --playback filename.oni
 +
|  Playback the specified oni file.
 +
 +
|-
 +
|  --loop
 +
|  Force the playback to loop.
 +
|  off (i.e., playback stops after one run)
 +
|}
 +
 
 +
Note: in playback, options like --depthVideoMode and --colorVideoMode are ignored.
 +
 
 +
= Output and data format =
 +
 
 +
The driver opens these ports:
 +
* [portPrefix]/userSkeleton:o - userSkeleton detection port (only opened if user detection is on)
 +
* [portPrefix]/depthFrame:o - depth frame port
 +
* [portPrefix]/imageFrame:o - rgb camera frame port
 +
 
 +
imageFrame:o and depthFrame:o stream YARP images (PixelRGB and PixelMono16, respectively), and if connected to a yarpview, the video is available.
 +
 
 +
During tracking, userTracker:o contains YARP Bottles in the following format:
 +
 
 +
'''([USER] userID)    [POS] (x y z) positionConfidence [ORI] (w x y z) orientationConfidence    ...'''
 +
 
 +
where
 +
* the part between "[POS]" and "orientationConfidence" is repeated as many times as the number of skeleton joints (15): HEAD NECK LEFT_SHOULDER RIGHT_SHOULDER LEFT_ELBOW RIGHT_ELBOW LEFT_HAND RIGHT_HAND TORSO LEFT_HIP RIGHT_HIP LEFT_KNEE RIGHT_KNEE LEFT_FOOT RIGHT_FOOT
 +
* the position is expressed in 3D Cartesian coordinates
 +
* the orientation is expressed in four-dimensional quaternions
 +
 
 +
= Using the driver from an application =
 +
 
 +
Refer to http://wiki.icub.org/yarpdoc/IOpenNI2DeviceDriver_8h_source.html
 +
 
 +
tbc
 +
 
 +
= Advanced options =
 +
 
 +
In case you do not want to use RPATH, toggle CMAKE_SKIP_INSTALL_RPATH to ON in YARP. With this setting, the YARP OpenNI2 driver must always be called from a directory that contains a copy (or symbolic link) of the stock OpenNI2 and NiTE2 'Drivers' directories. To prepare such a setup, do something along these lines:
 +
mkdir ~/yarp_openni2_root
 +
cd ~/yarp_openni2_root
 +
cp -R $OPENNI2_REDIST/OpenNI2 .
 +
cp -R $NITE2_REDIST64/NiTE2 .
 +
// or if you have the 32-bit version:
 +
// cp -R $NITE2_REDIST/NiTE2 .
 +
and call the yarpdev command from the yarp_openni2_root directory.
 +
 
 +
= Troubleshooting for macOS =
 +
 
 +
Due to a combination of changes in the handling of RPATHs in macOS 10.10 Yosemite and CMake 3, the following is needed (once) before running the device:
 +
 
 +
cd $NITE2_REDIST64
 +
install_name_tool -id $PWD/libNiTE2.dylib libNiTE2.dylib
 +
install_name_tool -change libOpenNI2.dylib /usr/local/lib/ni2/libOpenNI2.dylib libNiTE2.dylib

Latest revision as of 17:23, 7 April 2017

The OpenNI2 device driver for YARP exposes streams of data (color and depth videos, skeleton user tracking) from RGB-D sensors, including: Asus Xtion Pro, Kinect v1 and Kinect v2 (soon).

Note: other projects with similar purposes exist:

  1. YARP depthCamera plugin, based on OpenNI 2;
  2. https://github.com/robotology/kinect-wrapper, based on OpenNI 1 or Microsoft Kinect SDK;
  3. Kinect YARP device driver, also based on OpenNI 1.

Installation

This driver was tested on Debian Jessie (stable), Ubuntu 12.04+ and macOS 10.8.4+.

Dependencies

For Debian and Ubuntu, install the following dependencies:

sudo apt-get install g++ python libusb-1.0-0-dev libudev-dev freeglut3-dev doxygen graphviz libxmu-dev libxi-dev

Also, you must have installed a Java SDK (Oracle recommended).

Debian Wheezy (oldstable) is not supported by OpenNI2, due to glibc version being < 2.14.

For macOS, the above packages are either preinstalled or available through Homebrew.

OpenNI2

Install OpenNI2 (from zip packages or from GitHub source - see http://structure.io/openni) and NiTE2.

For macOS, OpenNI2 is also available through Homebrew.

Environment variables

Follow the installation instructions for OpenNI2 and NiTE2 by running the respective install.sh scripts. These scripts will create two files called OpenNIDevEnvironment and NiTEDevEnvironment. To copy their content permanently into your .bashrc, do:

cat OpenNIDevEnvironment >> ~/.bashrc
cat NiTEDevEnvironment >> ~/.bashrc

At the end of this process, you will have these environment variables:

OPENNI2_INCLUDE: full path to OpenNI2/Include
OPENNI2_REDIST: full path to OpenNI2/arch-Release 
NITE2_INCLUDE: full path to NiTE-OS-arch-2.x
NITE2_REDIST64 or NITE2_REDIST: full path to NiTE-OS-arch-2.x/Redist

where OS = Linux, arch = x64 or x86.

Enabling OpenNI2 YARP driver

In the CMake configuration for YARP, set the following:

CREATE_DEVICE_LIBRARY_MODULES ON
ENABLE_yarpmod_OpenNI2DeviceServer ON
ENABLE_yarpmod_OpenNI2DeviceClient ON

Finalizing the installation

These final steps are necessary to not incur in runtime errors like Couldn't create user tracker.

The OpenNI2 YARP driver must always be called from a directory that contains a copy (or symbolic link) of the NiTE.ini file from the stock NiTE2 distribution, properly configured. To prepare such a setup, do something along these lines:

mkdir ~/yarp_openni2_root
cd ~/yarp_openni2_root
cp $NITE2_REDIST64/NiTE.ini .
// or if you have the 32-bit version:
// cp $NITE2_REDIST/NiTE.ini .

Edit NiTE.ini, setting DataDir to be the full path to $NITE2_REDIST64/NiTE2 (or $NITE2_REDIST/NiTE2).

Now you're ready to call the yarpdev command from the yarp_openni2_root directory.

Support for different RGB-D cameras

PrimeSense-compatible sensors

These sensors (Asus Xtion, Carmine) work out of the box with the driver.

Kinect v1

Install libfreenect, including the OpenNI2-freenect bridge. Then copy (or create a symbolic link of) libFreenectDriver.so inside yarp_openni2_root/OpenNI2/Drivers.

Kinect v2

Support coming soon.

Usage

To print a list of all available options (help):

yarpdev --device OpenNI2DeviceServer --verbose

General options:

option description default
--name Set port prefix. /OpenNI2
--printVideoModes Print supported video modes.
--depthVideoMode Set depth camera video mode. 0 (i.e., 320x240 @ 30fps)
--colorVideoMode Set color (RGB) camera video mode. 0 (i.e., 320x240 @ 30fps)
--noRGB Disable color (RGB) camera, while keeping depth sensor and user skeleton enabled. Useful for RGB-less sensors and to reduce CPU load. off (i.e., RGB on)
--noRGBMirror Disable mirroring for the color (RGB) stream. Mirroring causes the stream to appear as if seen in a mirror, i.e., the image is transformed by reflecting all pixels across the vertical axis. off (i.e., mirroring on)
--noDepthMirror Disable mirroring for the depth stream. Mirroring causes the depth to appear as if seen in a mirror, i.e., the image is transformed by reflecting all pixels across the vertical axis. off (i.e., mirroring on)
--noUserTracking Disable skeleton user tracking. Useful to reduce CPU load. off (i.e., user tracking on)
--minConfidence x (double) Set minimum confidence required by skeleton user tracking. 0.6
--syncFrames Keep color and depth frames always in temporal sync. off
--imageRegistration Align color and depth video streams. This computation is performed on the sensor hardware. off

Other options related to recording and playback:

option description default
--record filename.oni Record (save) to the specified oni file.
--playback filename.oni Playback the specified oni file.
--loop Force the playback to loop. off (i.e., playback stops after one run)

Note: in playback, options like --depthVideoMode and --colorVideoMode are ignored.

Output and data format

The driver opens these ports:

  • [portPrefix]/userSkeleton:o - userSkeleton detection port (only opened if user detection is on)
  • [portPrefix]/depthFrame:o - depth frame port
  • [portPrefix]/imageFrame:o - rgb camera frame port

imageFrame:o and depthFrame:o stream YARP images (PixelRGB and PixelMono16, respectively), and if connected to a yarpview, the video is available.

During tracking, userTracker:o contains YARP Bottles in the following format:

([USER] userID) [POS] (x y z) positionConfidence [ORI] (w x y z) orientationConfidence ...

where

  • the part between "[POS]" and "orientationConfidence" is repeated as many times as the number of skeleton joints (15): HEAD NECK LEFT_SHOULDER RIGHT_SHOULDER LEFT_ELBOW RIGHT_ELBOW LEFT_HAND RIGHT_HAND TORSO LEFT_HIP RIGHT_HIP LEFT_KNEE RIGHT_KNEE LEFT_FOOT RIGHT_FOOT
  • the position is expressed in 3D Cartesian coordinates
  • the orientation is expressed in four-dimensional quaternions

Using the driver from an application

Refer to http://wiki.icub.org/yarpdoc/IOpenNI2DeviceDriver_8h_source.html

tbc

Advanced options

In case you do not want to use RPATH, toggle CMAKE_SKIP_INSTALL_RPATH to ON in YARP. With this setting, the YARP OpenNI2 driver must always be called from a directory that contains a copy (or symbolic link) of the stock OpenNI2 and NiTE2 'Drivers' directories. To prepare such a setup, do something along these lines:

mkdir ~/yarp_openni2_root
cd ~/yarp_openni2_root
cp -R $OPENNI2_REDIST/OpenNI2 .
cp -R $NITE2_REDIST64/NiTE2 .
// or if you have the 32-bit version:
// cp -R $NITE2_REDIST/NiTE2 .

and call the yarpdev command from the yarp_openni2_root directory.

Troubleshooting for macOS

Due to a combination of changes in the handling of RPATHs in macOS 10.10 Yosemite and CMake 3, the following is needed (once) before running the device:

cd $NITE2_REDIST64
install_name_tool -id $PWD/libNiTE2.dylib libNiTE2.dylib
install_name_tool -change libOpenNI2.dylib /usr/local/lib/ni2/libOpenNI2.dylib libNiTE2.dylib