Home > other >  Unity inside written in your c # script won't open access camera, how be to return a responsibi
Unity inside written in your c # script won't open access camera, how be to return a responsibi

Time:09-17

Using System. The Collections;
Using System. Collections. Generic;
using UnityEngine;
Using UnityEngine. UI;
Using Windows. It;

Public class color: MonoBehaviour {
Private KinectSensor _kinectsensor;
Private ColorFrameReader _colorreader;
Private Texture2D _textureinfo;
Private byte [] _colordata;
Private RawImage _cameramaterial;
//Use this for initialization
Void the Start () {
_cameramaterial=this. GameObject. GetComponent ();
_cameramaterial. UvRect=new the Rect (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=https://bbs.csdn.net/topics/new byte [color. BytesPerPixel * color. LengthInPixels];


if (! _kinectsensor. IsOpen)
_kinectsensor. The Open ();

}

//Update is called once per frame
Void the Update () {
If (_colorreader==null)
return;
ColorFrame frame=_colorreader. AcquireLatestFrame ();
If (frame==null)
return;

Frame. CopyConvertedFrameDataToArray (_colordata, ColorImageFormat Rgba);
_textureinfo. LoadRawTextureData (_colordata);
_textureinfo. The Apply ();
Frame. The Dispose ();
Frame=null;



_cameramaterial. Texture=_textureinfo;

}
}
  • Related