2014-09-16 15 views
0

를 사용하여 "몸 그림자"그리기 :넥트 하나 & 유니티 - BodyIndexSource 프레임 문제, 좋아, 그래서 더 나은 자신을 설명하기 위해 BodyIndexSource

목표 :가 사용 유니티 에 "그림자 수치"를 만들기 : 넥트를 One, Unity, C#

Unity 용으로 제공 한 Windows 예제 소스를 사용하고 있습니다. 내가 한 기본적으로 무엇을


는 BodyIndexSourceManager.cs과 BodyIndexSourceView.cs들이 단결의 색상/깊이/적외선/BodySource 데이터 쇼를 만들어 같은 방법을 만들 수 있습니다. 문제가 보이지 않지만 심도있는 Byte 데이터로 작업 한 적이 없기 때문에 BodyIndexSource 스트림에서 실제로 어떤 종류의 데이터를 받았는지에 대한 문서는 거의 없습니다.


예제 코드 :

public class BodyIndexSourceManager : MonoBehaviour 
    { 

    public int IndexWidth { get; private set; } 
    public int IndexHeight { get; private set; } 

    private KinectSensor _Sensor; 
    private BodyIndexFrameReader _Reader; 
    private Texture2D _Texture; 
    private byte[] _Data; 

    public Texture2D GetTexture() 
    { 
     return _Texture; 
    } 
    void Start() 
    { 
     _Sensor = KinectSensor.GetDefault(); 
     if (_Sensor != null) 
     { 
      _Reader = _Sensor.BodyIndexFrameSource.OpenReader(); 
      var frameDesc = _Sensor.BodyIndexFrameSource.FrameDescription; 
      IndexWidth = frameDesc.Width; 
      IndexHeight = frameDesc.Height; 
      _Texture = new Texture2D(frameDesc.Width, frameDesc.Height, TextureFormat.RGBA32, false); 
      if (!_Sensor.IsOpen) 
      { 
       _Sensor.Open(); 
      } 
     } 
    } 

    void Update() 
    { 
     if (_Reader != null) 
     { 
      var frame = _Reader.AcquireLatestFrame(); 
      if (frame != null) 
      { 
       Debug.Log("frame not null"); 
       frame.CopyFrameDataToArray(_Data); 
       _Texture.LoadRawTextureData(_Data); 
       _Texture.Apply(); 
       frame.Dispose(); 
       frame = null; 
      } 
     } 
    } 

    void OnApplicationQuit() 
    { 
     if (_Reader != null) 
     { 
      _Reader.Dispose(); 
      _Reader = null; 
     } 
     if (_Sensor != null) 
     { 
      if (_Sensor.IsOpen) 
      { 
       _Sensor.Close(); 
      } 
      _Sensor = null; 
     } 
    } 
    } 

다음 클래스 :

public class BodyIndexSourceView : MonoBehaviour 
{ 
    public GameObject BodyIndexSourceManager; 
    private BodyIndexSourceManager _bodyIndexManager; 

    void Start() 
    { 
     gameObject.renderer.material.SetTextureScale("_MainTex", new Vector2(-1, 1)); 
    } 

    void Update() 
    { 
     if (BodyIndexSourceManager == null) 
     { 
      return; 
     } 

     _bodyIndexManager = BodyIndexSourceManager.GetComponent<BodyIndexSourceManager>(); 
     if (_bodyIndexManager == null) 
     { 
      return; 
     } 

     gameObject.renderer.material.mainTexture = _bodyIndexManager.GetTexture(); 
    } 
    } 

나는 아마 잘못된 일을하거나 뭔가를 감독하고 있습니다. 누군가가 나에게 통찰력을 보여 주어 계속할 수 있기를 바랍니다.^_^주어진 응답에 대해 미리 감사드립니다.

요약 : 당신이 가장 좋은 방법은 키 넥트 하나를 통해 통일에 대한 추적 몸의 "전용"픽셀 데이터를 그리는 무엇인지 알고 있다면 알려 주시기 아니면 내가 시작에 대한 잘못하고있는 무슨 말씀 해주십시오 @ 위에 주어진 코드.

답변

1

아, 내가 왜 작동하지 않는 주요 문제를 발견. BodyIndexSource 스트림은 항상 DepthSource와 함께 COMBINATION에 있습니다. 짧은 그래서


:

시작() 메소드가 MultiSourceReader을 필요는 다음 업데이트() 메소드는 DepthFrame 및 BodyIndexFrame에 _reader.AcquireLatestFrame() "를 해부한다." DepthFrame이 없으면 BodyIndexFrame에서 값을 가져올 수 없습니다. 아니면 적어도 그렇게 생각됩니다.

그러면 Texture2D에 실제로 쓰는 논리를 채우기 만하면 Unity3D에서 사용할 수있는 것이 있습니다.