Skip to content

Instantly share code, notes, and snippets.

@UnaNancyOwen UnaNancyOwen/README.md

Last active May 27, 2020
Embed
What would you like to do?
Shell Script for SetUp Azure Kinect SDK

Shell Script for SetUp Azure Kinect SDK

This is shell script for setup Azure Kinect SDK (Azure Kinect Sensor SDK/Azure Kinect Body Tracking SDK).
You can easily setup Azure Kinect SDK on Ubuntu 18.04 LTS (ARM64, AMD64) using this script.
If you run script and it succeeds, Azure Kinect Viewer will launch.

How To Use

  • Install Azure Kinect SDK from Pre-Built Package
sh install-azure-kinect-sdk.sh
  • Build Azure Kinect SDK from Source Code Yourself
mkdir <workspace> && cd $_
sh build-azure-kinect-sdk.sh

Result

Screenshot from 2020-03-24 22-17-32

#!/bin/sh
# Shell Scripts for Build/Install Azure Kinect Sensor SDK from Source Code
## Define Version
K4A_VERSION=1.4.0
## Check CPU Architecture
ARCH=$(uname -m)
if [ $ARCH != "aarch64" ] && [ $ARCH != "x86_64" ]; then
exit 1
fi
## Install Dependencies
sudo apt update
sudo apt install -y unzip
sudo apt install -y wget
sudo apt install -y libglu1-mesa-dev freeglut3-dev mesa-common-dev
sudo apt install -y openssl
sudo apt install -y ninja-build
sudo apt install -y libssl-dev
sudo apt install -y libsoundio-dev
sudo apt install -y libxinerama-dev
sudo apt install -y libsdl2-dev
## Install Depth Engine
wget https://www.nuget.org/api/v2/package/Microsoft.Azure.Kinect.Sensor/$K4A_VERSION -O microsoft.azure.kinect.sensor.nupkg
mv microsoft.azure.kinect.sensor.nupkg microsoft.azure.kinect.sensor.zip
if [ $ARCH = "aarch64" ]; then
unzip -j -o microsoft.azure.kinect.sensor.zip linux/lib/native/arm64/release/libdepthengine.so.2.0
elif [ $ARCH = "x86_64"]; then
unzip -j -o microsoft.azure.kinect.sensor.zip linux/lib/native/x64/release/libdepthengine.so.2.0
fi
sudo chmod a+rwx /lib/$ARCH-linux-gnu
cp -f libdepthengine.so.2.0 /lib/$ARCH-linux-gnu
## Clone Azure Kinect Sensor SDK
git clone https://github.com/microsoft/Azure-Kinect-Sensor-SDK.git
cd Azure-Kinect-Sensor-SDK
git checkout -b v$K4A_VERSION refs/tags/v$K4A_VERSION
## Build and Install Azure Kinect Sensor SDK
mkdir -p build
cd build
cmake .. -GNinja
cmake --build .
sudo cmake --build . --target install
## Set Udev Rule
sudo chmod a+rwx /etc/udev/rules.d
cp -f ../scripts/99-k4a.rules /etc/udev/rules.d
## Set Emvironment Valiable for Shared Library (Temporary)
#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
#export PATH=$PATH:/usr/local/bin
## Set Emvironment Valiable for Shared Library
sudo chmod a+rwx /etc/ld.so.conf.d
echo '/usr/local/lib' > /etc/ld.so.conf.d/k4a.conf
sudo ldconfig
## Set Emvironment Valiable for Executable
echo 'PATH=$PATH:/usr/local/bin' >> ~/.bashrc
. ~/.bashrc
## Run Azure Kinect Viewer
k4aviewer
#!/bin/sh
# Shell Scripts for Install Azure Kinect Sensor SDK from Package
## Define Version
K4A_VERSION=1.4
K4ABT_VERSION=1.0
## Check CPU Architecture
ARCH=$(uname -m)
if [ $ARCH != "x86_64" ] && [ $ARCH != "aarch64" ]; then
exit 1
fi
## Regist Package Repository
sudo apt update
sudo apt install -y curl
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
if [ $ARCH = "x86_64" ]; then
sudo apt-add-repository https://packages.microsoft.com/ubuntu/18.04/prod -u
else
sudo apt-add-repository https://packages.microsoft.com/ubuntu/18.04/multiarch/prod -u
fi
sudo apt update
## Install Azure Kinect Sensor SDK
sudo apt install -y libk4a$K4A_VERSION # Runtime Package
sudo apt install -y libk4a$K4A_VERSION-dev # Development Package
sudo apt install -y k4a-tools # Tools Package
## Set Udev Rule
sudo chmod a+rwx /etc/udev/rules.d
wget https://raw.githubusercontent.com/microsoft/Azure-Kinect-Sensor-SDK/develop/scripts/99-k4a.rules -O /etc/udev/rules.d/99-k4a.rules
## Install Azure Kinect Body Tracking SDK
#sudo apt install -y libk4abt$K4ABT_VERSION # Runtime Package
#sudo apt install -y libk4abt$K4ABT_VERSION-dev # Development Package
## Run Azure Kinect Viewer
k4aviewer
@themancalledjakob

This comment has been minimized.

Copy link

themancalledjakob commented May 26, 2020

does this work for you? You should get an error when trying to install libk4abt1.0(-dev) next to libk4a1.4(-dev) due to conflicting symbolic link /usr/lib/x86_64-linux-gnu/libk4a.so.

@UnaNancyOwen

This comment has been minimized.

Copy link
Owner Author

UnaNancyOwen commented May 27, 2020

@themancalledjakob Hmmm, Do you have any ideas?

@themancalledjakob

This comment has been minimized.

Copy link

themancalledjakob commented May 27, 2020

@UnaNancyOwen You can install everything in local directories.
Here a script, ready to test:
https://gitlab.com/snippets/1980897

For me everything works. k4aviewer 1.3 and 1.4, as well as k4abt_simple_3d_viewer with 1.3 and 1.4.
Inspired by your script, they run automatically after install is finished.

you end up with something like this, and just need to include and link properly per project:

install
├── k4a-tools-1.3
│   └── usr
│       └── bin
│           ├── AzureKinectFirmwareTool
│           ├── k4arecorder
│           └── k4aviewer
├── k4a-tools-1.4
│   └── usr
│       └── bin
│           ├── AzureKinectFirmwareTool
│           ├── k4arecorder
│           └── k4aviewer
├── libk4a1.3
│   └── usr
│       ├── include
│       │   ├── k4a
│       │   │   ├── k4a_export.h
│       │   │   ├── k4a.h
│       │   │   ├── k4a.hpp
│       │   │   ├── k4atypes.h
│       │   │   └── k4aversion.h
│       │   └── k4arecord
│       │       ├── k4arecord_export.h
│       │       ├── playback.h
│       │       ├── playback.hpp
│       │       ├── record.h
│       │       └── types.h
│       ├── lib
│       │   └── x86_64-linux-gnu
│       │       ├── cmake
│       │       │   ├── k4a
│       │       │   │   ├── k4aConfig.cmake
│       │       │   │   ├── k4aConfigVersion.cmake
│       │       │   │   ├── k4aTargets.cmake
│       │       │   │   └── k4aTargets-relwithdebinfo.cmake
│       │       │   └── k4arecord
│       │       │       ├── k4arecordConfig.cmake
│       │       │       ├── k4arecordConfigVersion.cmake
│       │       │       ├── k4arecordTargets.cmake
│       │       │       └── k4arecordTargets-relwithdebinfo.cmake
│       │       ├── libdepthengine.so.2.0
│       │       ├── libk4arecord.so -> libk4arecord.so.1.3
│       │       ├── libk4arecord.so.1.3 -> libk4arecord.so.1.3.0
│       │       ├── libk4arecord.so.1.3.0
│       │       ├── libk4a.so -> libk4a.so.1.3
│       │       ├── libk4a.so.1.3 -> libk4a.so.1.3.0
│       │       └── libk4a.so.1.3.0
│       └── share
│           └── doc
│               └── libk4a1.3
│                   ├── LICENSE.txt
│                   ├── REDIST.txt
│                   └── ThirdPartyNotices.txt
├── libk4a1.4
│   └── usr
│       ├── include
│       │   ├── k4a
│       │   │   ├── k4a_export.h
│       │   │   ├── k4a.h
│       │   │   ├── k4a.hpp
│       │   │   ├── k4atypes.h
│       │   │   └── k4aversion.h
│       │   └── k4arecord
│       │       ├── k4arecord_export.h
│       │       ├── playback.h
│       │       ├── playback.hpp
│       │       ├── record.h
│       │       ├── record.hpp
│       │       └── types.h
│       ├── lib
│       │   └── x86_64-linux-gnu
│       │       ├── cmake
│       │       │   ├── k4a
│       │       │   │   ├── k4aConfig.cmake
│       │       │   │   ├── k4aConfigVersion.cmake
│       │       │   │   ├── k4aTargets.cmake
│       │       │   │   └── k4aTargets-relwithdebinfo.cmake
│       │       │   └── k4arecord
│       │       │       ├── k4arecordConfig.cmake
│       │       │       ├── k4arecordConfigVersion.cmake
│       │       │       ├── k4arecordTargets.cmake
│       │       │       └── k4arecordTargets-relwithdebinfo.cmake
│       │       ├── libk4a1.4
│       │       │   └── libdepthengine.so.2.0
│       │       ├── libk4arecord.so -> libk4arecord.so.1.4
│       │       ├── libk4arecord.so.1.4 -> libk4arecord.so.1.4.0
│       │       ├── libk4arecord.so.1.4.0
│       │       ├── libk4a.so -> libk4a.so.1.4
│       │       ├── libk4a.so.1.4 -> libk4a.so.1.4.0
│       │       └── libk4a.so.1.4.0
│       └── share
│           └── doc
│               └── libk4a1.4
│                   ├── LICENSE.txt
│                   ├── REDIST.txt
│                   └── ThirdPartyNotices.txt
└── libk4abt1.0
    └── usr
        ├── bin
        │   ├── dnn_model_2_0.onnx
        │   └── k4abt_simple_3d_viewer
        ├── include
        │   ├── k4abt.h
        │   ├── k4abt.hpp
        │   ├── k4abttypes.h
        │   └── k4abtversion.h
        ├── lib
        │   ├── cmake
        │   │   └── k4abt
        │   │       ├── k4abtConfig.cmake
        │   │       ├── k4abtConfigVersion.cmake
        │   │       ├── k4abtTargets.cmake
        │   │       └── k4abtTargets-relwithdebinfo.cmake
        │   ├── libcublas.so.10.0
        │   ├── libcudart.so.10.0
        │   ├── libcudnn.so.7
        │   ├── libk4abt.so -> libk4abt.so.1.0
        │   ├── libk4abt.so.1.0 -> libk4abt.so.1.0.0
        │   ├── libk4abt.so.1.0.0
        │   └── libonnxruntime.so.1.0.0
        └── share
            └── doc
                └── libk4abt1.0
                    ├── LICENSE.txt
                    ├── REDIST.txt
                    └── ThirdPartyNotices.txt

43 directories, 83 files

This approach allows to install any k4a or k4abt version, and hook them up with each other in any combination without conflicts. It's a bit hacky, because we link at one point libk4a.so.1.4.0 to libk4a.so.1.3 to make a hardcoded link in libk4abt happy ... But it works. Not sure if it's the best approach, but I can't think of a more elegant solution at the moment.

Also, then body tracking works with 1.4 on linux! :)

Didn't see this approach anywhere else, so maybe there is something utterly wrong with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.