using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Windows.Kinect;
public class color : MonoBehaviour {
private KinectSensor _kinectsensor;
private ColorFrameReader _colorreader;
private Texture2D _textureinfo;
private byte[] _colordata;
private RawImage _cameramaterial;
// Use this for initialization
void Start () {
_cameramaterial = this.gameObject.GetComponent<RawImage> ();
_cameramaterial.uvRect = new Rect (0,0,1,-1);
_kinectsensor = KinectSensor.GetDefault ();
if (_kinectsensor == null)
return;
_colorreader = _kinectsensor.ColorFrameSource.OpenReader ();
FrameDescription color = _kinectsensor.ColorFrameSource.CreateFrameDescription (ColorImageFormat.Rgba);
_textureinfo = new Texture2D (color.Width, color.Height, TextureFormat.RGBA32, false);
_colordata = new byte[color.BytesPerPixel*color.LengthInPixels];
if (!_kinectsensor.IsOpen)
_kinectsensor.Open ();
}
// Update is called once per frame
void Update () {
if (_colorreader == null)
return;
ColorFrame frame = _colorreader.AcquireLatestFrame ();
if (frame == null)
return;
frame.CopyConvertedFrameDataToArray (_colordata, ColorImageFormat.Rgba);
_textureinfo.LoadRawTextureData (_colordata);
_textureinfo.Apply ();
frame.Dispose ();
frame = null;
_cameramaterial.texture = _textureinfo;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/44137.html
標籤:Unity3D
上一篇:關于CRM系統的一些困惑
