C# Kinect One&;Unity-BodyIndexSource框架问题,图纸a“;身体阴影“;使用BodyIndexSource
好吧,为了更好地解释我自己: 目标:统一制作“影子人物” 使用:Kinect One,Unity,C# 我使用的是他们为Unity提供的Windows示例源代码C# Kinect One&;Unity-BodyIndexSource框架问题,图纸a“;身体阴影“;使用BodyIndexSource,c#,unity3d,kinect,texture2d,C#,Unity3d,Kinect,Texture2d,好吧,为了更好地解释我自己: 目标:统一制作“影子人物” 使用:Kinect One,Unity,C# 我使用的是他们为Unity提供的Windows示例源代码 基本上,我所做的是创建BodyIndexSourceManager.cs和BodyIndexSourceView.cs,就像它们统一显示颜色/深度/红外/体源数据一样。我看不出有什么问题,但这也是因为我从未深入研究过字节数据,也没有关于从BodyIndexSource流中实际接收到何种数据的文档 示例代码: public clas
基本上,我所做的是创建BodyIndexSourceManager.cs和BodyIndexSourceView.cs,就像它们统一显示颜色/深度/红外/体源数据一样。我看不出有什么问题,但这也是因为我从未深入研究过字节数据,也没有关于从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();
}
}
公共类BodyIndexSourceView:MonoBehavior
{
公共游戏对象BodyIndexSourceManager;
私人BodyIndexSourceManager_bodyIndexManager;
void Start()
{
gameObject.renderer.material.SetTextureScale(“_MainTex”,新矢量2(-1,1));
}
无效更新()
{
if(BodyIndexSourceManager==null)
{
返回;
}
_bodyIndexManager=BodyIndexSourceManager.GetComponent();
if(_bodyIndexManager==null)
{
返回;
}
gameObject.renderer.material.mainTexture=\u bodyIndexManager.GetTexture();
}
}
我可能只是做了错事或监督了一些事情。
希望有人能给我一些启示,这样我就可以继续了提前感谢您的回复
摘要:
如果您知道最好的方法是通过Kinect One“仅”将被跟踪物体的像素数据绘制成统一体,请让我知道或告诉我在开始时我做错了什么@上面给出的代码。啊,我发现了它不起作用的主要问题。 BodyIndexSource流始终与DepthSource组合
简言之: Start()方法需要一个MultiSourceReader,然后Update()方法将_reader.AcquireLatestFrame()分解为DepthFrame和BodyIndexFrame。 如果没有DepthFrame,您将无法从BodyIndexFrame获取值。至少,情况似乎是这样 然后,你“简单地”填写逻辑来实际写入纹理2D,瞧,你在Unity3D中有了一些有用的东西