Boilerplate project for using the Kinect V2 (aka Kinect ONE) in Unity.
The project "UnityKinect" can be used as a base for a new project, or its assets can be used in another Unity project in order to include Kinect handling.
The required assets are in the "Kinect" directory of the assets.
The remaining assets are provided as examples, and can be reused or adapted.
The "Kinect for Unity" package must be imported in the project in order to use the Kinect.
If preferred, and if want to use the latest version of the package, it can be downloaded from the Microsoft website.
MS have ended the development of the Kinect, so the provided package should be the final one.
-
(OPTIONAL) Download the "Kinect for Unity" package
From:
https://developer.microsoft.com/en-us/windows/kinect
! - It is mentionned that it is a package for Unity Pro, but it works fine with the free Unity version. -
Import the "Kinect for Unity" package into the Unity project
- "Assets" -> "Import Package" -> "Custom Package..."
- Navigate to the "Dependencies" directory or to the download location if the package was downloaded separately (previous step).
- Select the package:
"Kinect.2.0.1410.19000.unitypackage" (or different version if downloaded separately) - Import the full package:
=> Both "Plugins" and "Standard Assets"
- "Assets" -> "Import Package" -> "Custom Package..."
-
Move the imported assets to the "Kinect" folder
- "Plugins" folder
- "Standard Assets" folder
! - MAKE SURE TO ONLY MOVE THE ASSETS RELATED TO KINECT! (the ones imported previously)
! - If the Unity project already had "Plugins" or "Standard Assets" directories, make sure to only move the Kinect related assets (those imported from the pacakge).
- "Plugins" folder
The last step is not required, but helps keeping a cleaner assets folder.
(The project's ".gitignore" also requires this folders hierarchy)
The main script of the project is "KinectInputManager".
It allows to specify which frames to acquire from the Kinect, and provides methods to access their data.
The different frame types are:
- Colour frames: RGB video stream
- Depth frames: Depth data obtained from the IR sensor
- Body framss: The tracked humand bodies composed of joints
- Body Index frames: Data indicating for the each element of the depth data if it belongs to a tracked human body
Each type can be acquired or not, depending on its respective setting:
- useColorInput
- useDepthInput
- useBodyInput
- useBodyIndexInput
The different types of data can be obtained through the following methods:
```cs
public byte[] GetColorBuffer();
//public Texture2D GetColorTexture(); //code can be uncommented if desired
public ushort[] GetDepthBuffer();
public DepthSpacePoint[] GetDepthCoordinates(); // mapping of colour frames to depth frames
public Body[] GetBodyData();
public byte[] GetBodyIndexBuffer();
```cs
There are 2 provided examples:
- "BodyFrames": Acquires the Body frames of the Kinect to display a detected human body.
- "MultiFrames": Acquires the colour, depth and body index frames of the Kinect. Currently only the colour frames are displayed.