August 8, 2020

[Note] Kinect2 on Ubuntu

This is NOT about XBox-360 Kinect.

Environment: Ubuntu 20.04

Kinect v2, XBox One version + USB adapter for PC

For Win10 and more info, see - https://blog.keithkim.com/2020/02/kinect2-on-windows-motion-detection.html


Install

The whole step is just about downloading, compiling and installing libfreenect2

  • Requires gcc version 8
  • Requires CUDA sample code
  • Requires a lot of apt packages

[1] multiple gcc versions

Default was version 9.  I had to install version 8 and made it as default.

$ sudo apt -y install gcc-7 g++-7 gcc-8 g++-8 gcc-9 g++-9
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 7
$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 7
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 8
$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 8
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9
$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 9

# select v8:

$ sudo update-alternatives --config gcc
$ sudo update-alternatives --config g++

# check version

$ gcc --version
$ g++ --version

[2] install CUDA sample code

See, https://blog.keithkim.com/2020/08/note-cuda-on-ubuntu-2004.html

[3] Install lots of APT packages

$ sudo apt-get install build-essential cmake autoconf pkg-config doxygen \
 libusb-1.0-0-dev libtool libudev-dev \
 libturbojpeg libjpeg-turbo8-dev \
 mesa-common-dev libgl1-mesa-glx \
 freeglut3-dev libxrandr-dev libxi-dev libva-dev libva-drm2 \
 openni2-utils

[4] compile libfreenect2

If want to disable CUDA, change cmake line as below,

$ cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/freenect2 -ENABLE_CUDA OFF

If CUDA is installed, and you have the sample, type this before make to point where the sample is installed,

$ export CPATH=$CPATH:$HOME/NVIDIA_CUDA-10.1_Samples/common


$ git clone https://github.com/OpenKinect/libfreenect2.git
$ cd libfreenect2
$ mkdir build && cd build
$ cmake ..
$ make
$ make install
$ sudo cp ../platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/
 

# Unplug, plug in Kinect first
# you may have to add yourself to 'plugdev' group.

$ ./bin/Protonect

 

Closing

 Using it in Python, OpenCV will be another posting.


Reference

 

No comments:

Post a Comment