Installation of Azure Kinect SDK ①Open the directory of which Azure Kinect SDK is installed C:¥Program Files¥Azure Kinect SDK v1.2.0¥sdk¥windows-desktop¥amd64¥release¥bin ②Drag and drop depthengine_2_0.dll into Plugins of your project
Start and Stop Azure Kinect using UnityEngine; using Microsoft.Azure.Kinect.Sensor; public class KinectScript : MonoBehaviour { Device device; //Variable to access to Kinect void Start() { InitKinect(); //Initialization of Kinect } void InitKinect() { //See Next Page. } /*Omitted */ }
Preparation of Drawing Point Cloud Device device; int width, height, num; //width, height and total Pixels void Start(){ /*Omitted*/ } void InitKinect() { device = Device.Open(0); device.StartCameras ( /*Omitted*/ ); //Calculation of total number of pixel. width = device.GetCalibration(). depth_camera_calibration.resolution_width; height = device.GetCalibration(). depth_camera_calibration.resolution_height; num = height * width; }
Preparation of Drawing Point Cloud int width, height, num; Mesh mesh; //Used for Drawing Shape Vector3[] vertices; //Position of each point. Color32[] colors; //Color of each point. int[] indices; //Index list of drawing point void Start() { InitKinect(); InitMesh(); //Initialization of mesh } void InitMesh() { //See the next page. }
Preparation of Drawing Point Cloud void InitMesh() { mesh = new Mesh(); //Enable drawing more than 65535 points mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; //allocation of memory for treating information to //draw point cloud. vertices = new Vector3[num]; colors = new Color32[num]; indices = new int[num]; //See next page }
Drawing Points /*Continued from previous step (in InitMesh function)*/ int index = 0; //index of vertex array. for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { vertices[index].x = x ; vertices[index].y = y ; vertices[index].z = 2; colors[index].r = 0; colors [index].g = 0; colors [index].b = 255; colors [index].a = 255; indices[index] = index; index++; } } Temporally setting the coordinates of each vertex Temporally setting the color of each vertex Setting drawing list.
Drawing Points /*Continued from the previous page.*/ int index = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { /*Omitted*/ } } //Assignment vertices and colors to mesh. mesh.vertices = vertices; mesh.colors32 = colors; //Setting drawing list and mesh topology. mesh.SetIndices(indices, MeshTopology.Points, 0); //Assingnment of mesh to MeshFilter of the gameObject. gameObject.GetComponent().mesh = mesh;
Getting DataStream from Kinect using UnityEngine; using Microsoft.Azure.Kinect.Sensor; //Enable to use async function. using System.Threading.Tasks; public class KinectScript : MonoBehaviour { Device device; int width, height, num; Mesh mesh; Vector3[] vertices; Color32[] colors; int[] indices; /*Omitted*/
Getting DataStream from Kinect While (true) { //Getting synchlonyzed frame of Kinect using (Capture capture = await Task.Run(() => device.GetCapture()).ConfigureAwait(true)) { //Getting Depth image with capture.Depth //And transform it into xyz by DeptuImageToPointCloud Image pImage = trans.DepthImageToPointCloud(capture.Depth); //Getting vertices data. Short3[] pointCloud = pImage.GetPixels().ToArray(); /*See the next page*/ } }
Assigning Color to Point Cloud while (true) { using (Capture capture = await Task.Run(() => device.GetCapture()).ConfigureAwait(true)) { //Getting color image which is matched to Depth resolution Image modifiedColor = trans.ColorImageToDepthCamera(capture); //Getting pixel array. BGRA[] colorArray = modifiedColor.GetPixels().ToArray(); Image pImage = trans.DepthImageToPointCloud(capture.Depth); Short3[] pointCloud = pImage.GetPixels().ToArray(); /*See the next page*/ KinectLoop Function