ネット上にUnityで動くAzureKinectのサンプルがあんまりないんですよね・・・・
ほとんどDepthを使ってPointCloud表示したりとか
シンプルすぎるやつはまあ、誰でもできるよねって感じかもしれないけどC#なれてない自分は時間がかかったのでここに置いておきます。
UnityでAzureKinectを動かすためプロジェクトづくりはMicrosoftの公式のサンプルの中にUnityで使えるBodyTrackingのやつに書いてあるのでそれ見て環境を作ってください。
https://github.com/microsoft/Azure-Kinect-Samples
using System.Collections; using System.Collections.Generic; using UnityEngine; using Microsoft.Azure.Kinect.Sensor; public class ColorImageKinect : MonoBehaviour { Device device; Calibration calibration; Texture2D kinectColor; DeviceConfiguration config; [SerializeField] Material mat; // Start is called before the first frame update void Start() { InitKinect(); } void InitKinect() { device = Device.Open(0); config = new DeviceConfiguration(); config.ColorFormat = ImageFormat.ColorBGRA32; config.ColorResolution = ColorResolution.R720p; config.DepthMode = DepthMode.NFOV_2x2Binned; config.CameraFPS = FPS.FPS30; config.SynchronizedImagesOnly = true; device.StartCameras(config); calibration = device.GetCalibration(); int width = calibration.ColorCameraCalibration.ResolutionWidth; int height = calibration.ColorCameraCalibration.ResolutionHeight; kinectColor = new Texture2D(width, height); } // Update is called once per frame void Update() { Capture capture = device.GetCapture(); Image colorImg = capture.Color; Image depthImg = capture.Depth; Color32[] pixels = colorImg.GetPixels<Color32>().ToArray(); kinectColor.SetPixels32(pixels); kinectColor.Apply(); mat.mainTexture = kinectColor; } private void OnDestroy() { device.StopCameras(); } }
上記スクリプトを適当なゲームオブジェクトにつけて、適当なマテリアルを用意すれば動くはず。
なぜか青と赤の色が入れ替わってるけど気にする人はシェーダーで直したってくださいませ。