Skip to content
This repository was archived by the owner on Aug 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
0e8fafe
PythonK4A: Adding initial directory structure, k4atypes.py which defi…
JonathanESantos Dec 9, 2020
b77771a
PythonK4A: Updating __init__.py to point to the "api" directory (rena…
JonathanESantos Dec 9, 2020
f1e90ba
Python K4A: Rearranging directory tree so that it matches the expecta…
JonathanESantos Dec 9, 2020
b2443dd
Python k4a api: Put ctypes structs inside k4atypes.py.
JonathanESantos Dec 10, 2020
1e8677c
Python k4a api: Adding to setup.py so that "pip install -e .[test]" w…
JonathanESantos Dec 10, 2020
071ab03
Python k4a api: An enum name with AUTO was mistakenly replaced with _…
JonathanESantos Dec 10, 2020
de120dd
Python k4a api: Adding __repr__() functions to structs in order to pr…
JonathanESantos Dec 10, 2020
ad64501
Python k4a api: Adding a check that the required dlls are in the _lib…
JonathanESantos Dec 10, 2020
8e5e3a1
Python k4a api: Adding the rest of the bindings for the functions tha…
JonathanESantos Dec 10, 2020
5d9db7b
Python k4a: Adding tests to call the functions in the dll.
JonathanESantos Dec 11, 2020
744ccb9
Python k4a: Adding missing enum in color resolution, and adding tests…
JonathanESantos Dec 12, 2020
f85d8d2
Python k4a: Changing @unittest.skip to @unittest.expectedfail for tho…
JonathanESantos Dec 12, 2020
c1a85d9
Python k4a: Updating docs. Removing platform tag in building the k4a …
JonathanESantos Dec 12, 2020
3c25d68
Python API: Renaming enums and structs to Python naming convention.
JonathanESantos Dec 16, 2020
88be9e5
Python API: Moving all internal files and symbols into the _bindings/…
JonathanESantos Dec 16, 2020
da31b2a
Python API: Moving handle structs from _k4a.py back to _k4atypes.py s…
JonathanESantos Dec 16, 2020
a080d08
Renaming modules inside _bindings subpackage to not include underscor…
JonathanESantos Dec 16, 2020
ee41c9a
Python api: Adding Device class which corresponds to a device with a …
JonathanESantos Dec 17, 2020
fddad4e
Python API: Adding capture and image classes to encapsulate capture a…
JonathanESantos Dec 22, 2020
c44293c
Python API: Bug in Image class was missing a height_pixels in one lin…
JonathanESantos Dec 22, 2020
76b3e83
Python API: Adding Calibration and Transformation wrapper classes.
JonathanESantos Dec 23, 2020
cd14e98
Python API: Renaming a test file.
JonathanESantos Dec 23, 2020
d023902
Python API: Adding more tests to test the Device, Capture, Image, and…
JonathanESantos Dec 24, 2020
359525d
Python API: Fixing transformation functions and their tests.
JonathanESantos Dec 28, 2020
ef8887b
Python API: Adding example code that makes use of the Python API.
JonathanESantos Dec 29, 2020
456c0b6
Python API: Adding docstrings *.py files and a Doxygen settings file …
JonathanESantos Dec 31, 2020
cd9a0da
Python API: Adding a main page to the documentation, and fixing a bug…
JonathanESantos Dec 31, 2020
f48bf0c
Python API: Adding lines in build_wheel.ps1 to generate the documenta…
JonathanESantos Dec 31, 2020
6bf9c0c
Making minor changes to get this k4a package to work in both Windows …
JonathanESantos Jan 8, 2021
0e53962
Forgot to commit the minor changes to get this k4a package to work in…
JonathanESantos Jan 8, 2021
1b6b6aa
Python API: Specifying specific library names that the python code wi…
JonathanESantos Jan 8, 2021
49a52fd
Python API: Modifying the build_wheel.csh script to look for libdepth…
JonathanESantos Jan 8, 2021
d560c73
Python API: Updating building.md for clarity.
JonathanESantos Jan 15, 2021
c567635
Python API: Fixing bug in tests that causes failure in some of the te…
JonathanESantos Jan 22, 2021
038b9f6
Removing forced-loading of depthengine library. Just load k4a.dll and…
JonathanESantos Mar 23, 2021
ccbc0bf
In the wheel build scripts, adding test to check if doxygen is instal…
JonathanESantos Mar 23, 2021
f1902be
Fixing markdown documents.
JonathanESantos Mar 23, 2021
7b69e00
Adding blurb about installing pip in Linux.
JonathanESantos Mar 23, 2021
55d6ba7
Changing ctypes.c_ulonglong to ctypes.c_size_t where it matches the f…
JonathanESantos Mar 23, 2021
a742479
Changing c_ulonglong to c_size_t in the tests to match the change in …
JonathanESantos Mar 23, 2021
bd1cad9
Fixing build script in Linux to look for depthengine.so* inside a sub…
JonathanESantos Mar 23, 2021
d65d0b7
Fixing documents that say the Linux depthengine.so.2.0 must be in a s…
JonathanESantos Mar 24, 2021
57802b3
The build script for Linux needs to check for depthengine.so* in the …
JonathanESantos Mar 24, 2021
f71cbea
Making slight changes to the building.md documentation for more clarity.
JonathanESantos Mar 24, 2021
cf713d6
Fixing a minor typo in the comments of image_transformations.py, and …
JonathanESantos Mar 24, 2021
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
2,562 changes: 2,562 additions & 0 deletions src/python/k4a/Doxyfile

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions src/python/k4a/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Azure Kinect Python API(K4A)

Welcome to the Azure Kinect Python API! We hope you can use it to build many great applications and participate in the project. Don't be shy to ask questions, and provide feedback. See [Azure.com/Kinect](https://Azure.com/kinect) for device
info and available documentation.

## Introduction

**K4A** is a Python user mode API to read data from your Azure Kinect device.

## Why use K4A

K4A enables you to get the most out of your Azure Kinect camera. Features include:

* Depth camera access
* RGB camera access and control (e.g. exposure and white balance)
* Motion sensor (gyroscope and accelerometer) access
* Synchronized Depth-RGB camera streaming with configurable delay between cameras
* External device synchronization control with configurable delay offset between devices
* Camera frame meta-data access for image resolution, timestamp and temperature
* Device calibration data access

All image data is encapsulated in numpy arrays, allowing Python users to easily use the data in OpenCV
and other packages that work with numpy arrays.

## Documentation

API documentation will soon be made available.

## Building

K4A uses Python's setuptools to build a wheel file for distribution.
For instructions on how to build this distributable, please see
[building](docs/building.md).

## Testing

For information on writing or running tests, please see [testing](docs/testing.md).

## Contribute

We welcome your contributions! Please see the [contribution guidelines](../../../CONTRIBUTING.md).

## Feedback

For SDK feedback or to report a bug, please file a [GitHub Issue](https://github.com/Microsoft/Azure-Kinect-Sensor-SDK/issues). For general suggestions or ideas, visit our [feedback forum](https://aka.ms/azurekinectfeedback).

## Sample Code

Sample Python code that uses the Python API can be found in the examples/ folder. See [examples](docs/examples.md).

## Q&A

Welcome to the [Q&A](kinect-qa.md) corner!

## Join Our Developer Program

Complete your developer profile [here](https://aka.ms/iwantmr) to get connected with our Mixed Reality Developer Program. You will receive the latest on our developer tools, events, and early access offers.

## Code of Conduct

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.

## Reporting Security Issues
Security issues and bugs should be reported privately, via email, to the
Microsoft Security Response Center (MSRC) at <[[email protected]](mailto:[email protected])>.
You should receive a response within 24 hours. If for some reason you do not, please follow up via
email to ensure we received your original message. Further information, including the
[MSRC PGP](https://technet.microsoft.com/en-us/security/dn606155) key, can be found in the
[Security TechCenter](https://technet.microsoft.com/en-us/security/default).

## License and Microsoft Support for Azure Kinect Sensor SDK

[MIT License](../../../LICENSE)

[Microsoft Support for Azure Kinect Sensor SDK](../../../microsoft-support.md)
80 changes: 80 additions & 0 deletions src/python/k4a/build_wheel.csh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

# Script to automate creation of the Python wheel for the k4a library.
# In Ubuntu, the command for the base installation of Python 3 is python3.
# Also, pip and venv may need to be installed manually before running this
# script since it may not come with the base installation of Python 3.
# To get pip: sudo apt install python3-pip
# To get venv: sudo apt install python3-venv
# To get doxygen: sudo apt install doxygen

# Get the directory where this script lives.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"

# Check that the k4a.so and depth_engine.so have been copied into the _libs/ folder.
# Because these dlls may not be located in a standard place, leave it to the developer
# to manually copy them into the _libs/ folder.
if [ ! -f "$DIR/src/k4a/_libs/libk4a.so" ] && [ ! -h "$DIR/src/k4a/_libs/libk4a.so" ]; then
echo "File not found: $DIR/src/k4a/_libs/libk4a.so"
echo "Please manually copy the k4a library into that folder."
return 1
fi

if [ ! -f "$DIR/src/k4a/_libs/libk4a"*"/libdepthengine"* ] && [ ! -h "$DIR/src/k4a/_libs/libk4a"*"/libdepthengine"* ]; then
echo "File not found: $DIR/src/k4a/_libs/libk4a*/libdepthengine*"
echo "Please manually copy the depth engine library into that folder."
return 1
fi

# Create a virtual environment and activate it.
echo "Creating a Python virtual environment."

if [ -d "temp_build_venv" ]; then
rm -rf "temp_build_venv"
fi

if [ -d "build" ]; then
rm -rf "build"
fi

python3 -m venv temp_build_venv
source ./temp_build_venv/bin/activate

# Install the package in editable mode so that it installs dependencies. These are needed for sphinx docs.
python -m pip install --upgrade pip
pip install -e .

# Build the .whl file and place it in a build/ folder.
pip install wheel
pip wheel . -w build

# Build the docs and move them to the build/ folder. doxygen must be in the path.
if command -v doxygen &> /dev/null
then
mkdir ./build/docs
doxygen ./Doxyfile
else
echo "doxygen not found, skipping building the documentation."
fi

# Create a convenient documentation.html that redirects to the index.html that doxygen generates.
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta http-equiv="REFRESH" content="0;URL=html/index.html">
</html>' > ./build/docs/documentation.html


# Deactivate virtual environment and delete it.
deactivate
rm -rf "temp_build_venv"

echo "Done creating k4a package wheel."
65 changes: 65 additions & 0 deletions src/python/k4a/build_wheel.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Script to automate creation of the Python wheel for the k4a library.

# Check that the k4a.dll and depth_engine.dll have been copied into the _libs/ folder.
# Because these dlls may not be located in a standard place, leave it to the developer
# to manually copy them into the _libs/ folder.
If (-not (Test-Path -Path "$PSScriptRoot\src\k4a\_libs\k4a.dll")) {
Write-Host "File not found: $PSScriptRoot\src\k4a\_libs\k4a.dll"
Write-Host "Please manually copy the k4a library into that folder."
exit 1
}

If (-not(Test-Path -Path "$PSScriptRoot\src\k4a\_libs\depthengine*.dll")) {
Write-Host "File not found: $PSScriptRoot\src\k4a\_libs\depthengine*.dll"
Write-Host "Please manually copy the depth engine library into that folder."
exit 1
}

# Create a virtual environment and activate it.
Write-Host "Creating a Python virtual environment."

If (Test-Path -Path "temp_build_venv") {
Remove-Item -LiteralPath "temp_build_venv" -Force -Recurse
}

If (Test-Path -Path "build") {
Remove-Item -LiteralPath "build" -Force -Recurse
}

python -m venv temp_build_venv
./temp_build_venv/Scripts/activate

# Install the package in editable mode so that it installs dependencies. These are needed for sphinx docs.
python -m pip install --upgrade pip
pip install -e .

# Build the .whl file and place it in a build/ folder.
pip install wheel
pip wheel . -w build
Remove-Item ./build/* -Exclude k4a*.whl -Recurse -Force


# Build the docs and move them to the build/ folder. doxygen must be in the path.
if (Get-Command doxygen -errorAction SilentlyContinue) {
mkdir ./build/docs
doxygen ./Doxyfile

# Create a convenient documentation.html that redirects to the index.html that doxygen generates.
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta http-equiv="REFRESH" content="0;URL=html/index.html">
</html>' > ./build/docs/documentation.html
}
else {
Write-Host "doxygen not found, skipping building the documentation."
}


# Deactivate virtual environment and delete it.
./temp_build_venv/Scripts/deactivate.bat
Remove-Item -LiteralPath "temp_build_venv" -Force -Recurse

Write-Host "Done creating k4a package wheel."
142 changes: 142 additions & 0 deletions src/python/k4a/docs/building.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Building Azure Kinect Python API(K4A)

This information is for how to build your own copy of the Python wheel.
If you need to build from source, you have to clone the repository to ensure all the submodule dependencies in place.

## Support Configurations

Python:
* Greater than or equal to version 3.6.

Architectures:
* amd64
* x86 (limited, no testing is performed)

OS:
* Windows
* Linux

## Dependencies

Building on Windows and Linux requires an active internet connection. Part of the
build will require downloading dependencies.

The following dependencies are for both Windows and Linux:

* [python3](https://www.python.org/getit/). During the install make sure to add
python to path.

* [k4a library](../../../../docs/building.md)
The k4a library can be built from the repository or the SDK can be downloaded
for the binary. The Windows library is k4a.dll, and the Linux library is libk4a.so.
The k4a binary needs to be copied to the host system and added
to the path src/python/k4a/src/k4a/_libs in this repository before building.

* [Depth Engine](../../../../docs/depthengine.md).
The depth engine (DE) is a closed source binary shipped with the
SDK installer. The DE binary needs to be copied to the host system and added
to the path src/python/k4a/src/k4a/_libs in this repository before building.

The following dependencies are for both Windows and Linux, but in Windows they seems to be
automatically part of a Python installation, while on Linux they need to be installed
separately:

* Python module pip
On Linux, install pip with:
`sudo apt install python3-pip -y`

* Python module venv
On Linux, install venv with:
`sudo apt install python3-venv -y`

The following tools are optional:

* [doxygen](https://github.com/doxygen/doxygen)
Required for building documentation. If not installed, html documentation will not be built.


## Building

### Building using a powershell script (Windows)

1. Copy the k4a and DE binaries into the folder src/python/k4a/src/k4a/_libs.
The file name for the k4a library MUST be k4a.dll.

>**Note:** To create a Windows-only wheel, the .dll for Windows need to copied into the folder.
>Python will look for "k4a.dll" which will also load the depth engine dll.

>**Note:** An example of the files in _libs for Windows are:
>- k4a.dll
>- depthengine\_2\_0.dll

2. In a powershell terminal, run the script src/python/k4a/build_wheel.ps1.
This will create the .whl file in a build/ folder.

### Building using a bash script (Linux)

1. Copy the k4a and DE binaries into the folder src/python/k4a/src/k4a/_libs.
The file name for the k4a library MUST be libk4a.so. The depth engine library must be in a
folder named libk4a\<ver\>, where \<ver\> is the version major.minor of the k4a library
(e.g. _libs constains libk4a1.4/libdepthengine.so.2.0).

>**Note:** To create a Linux-only wheel, the the .so for Linux need to copied into the folder.
>Python will look for "libk4a.so" in Linux which will also load the depth engine dll.

>**Note:** An example of the files in _libs for Linux are:
>- libk4a.so, a soft link to libk4a.1.4
>- libk4a.so.1.4, a soft link to libk4a.1.4.0
>- libk4a.so.1.4.1, the k4a library
>- depthengine.so.2.0, the depth engine library in a sub-folder

2. In a terminal, source the script src/python/k4a/build_wheel.csh.
This will create the .whl file in a build/ folder.

`cd <repo_root>/src/python/k4a`
`source build_wheel.csh`

### Building using a command line terminal (cross platform)

1. Copy the k4a and DE binaries into the folder src/python/k4a/src/k4a/_libs.
The file names for the k4a library MUST be k4a.dll (for Windows) and libk4a.so (for Linux).

>**Note:** To create a cross-platform wheel, the .dll for Windows and the .so for Linux need to
>copied into the folder. Python will look for "k4a.dll" in Windows and "libk4a.so" in Linux.

>**Note:** An example of the files in _libs for cross-platform compatibility are:
>- libk4a.so, a soft link to libk4a.1.4
>- libk4a.so.1.4, a soft link to libk4a.1.4.0
>- libk4a.so.1.4.1
>- depthengine.so.2.0
>- k4a.dll
>- depthengine\_2\_0.dll

2. In a command line terminal, create a Python virtual environment and activate it (do not include brackets):
`cd <repo_root>/src/python/k4a`
`python -m venv <env_name>`
`./<env_name>/Scripts/activate`

3. Build the .whl file and place it in a build/ folder.
`pip install wheel`
`pip wheel . -w build`

4. Deactivate the virtual environment and delete it.
`./<env_name>/Scripts/deactivate.bat`
Delete the directory `<env_name>`.

### Building the HTML Documentation

A Doxygen settings file is provided in the project directory. Run doxygen using the
settings file to create the html documentation.

The build scripts will run doxygen as part of the build.

## Installing

The build process will create a k4a*.whl wheel file that can be installed via pip.
The wheel file can be distributed and installed as follows.

1. In a command line terminal, install the k4a python library via pip.
Replace <k4a*.whl> with the name of the wheel file.
`pip install <k4a*.whl>`

Once installed, the user can "import k4a" in their python code.
Loading