我需要编写一个记录帧的程序,但只有当一个骨架/主体在框架中时。我查看了bodyCount方法,但它总是给出值6(无用)。我尝试做的一件事如下所示。该代码基本上显示了存储被跟踪体的索引。但是,我仍然无法弄清楚如何知道框架中是否有一个或多个实体。 我真的很感激任何帮助。 提前致谢。
private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e){
using (BodyFrame bodyFrame=e.FrameReference.AquireFrame()){
if (bodyFrame!=null){
if(this.bodies==null){
this.bodies=new Body[bodyFrame.BodyCount];
}
body.Frame.GetAndRefreshBodyData(this.bodies)
for(int i=0; i<6;i++){
if(this.bodies[i].IsTracked){
Console.WriteLine("Tracked"+i)
}
}
}
}
}
答案 0 :(得分:1)
只需检查每个实体的IsTracked属性,并将跟踪的骨架数存储在单个变量中。如果此数字等于1,则只跟踪一个骨架,您可以开始录制。
private Body[] bodies = null;
[...]
private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
bool dataReceived = false;
using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame())
{
if (bodyFrame != null)
{
if (this.bodies == null)
{
this.bodies = new Body[bodyFrame.BodyCount];
}
// The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array.
// As long as those body objects are not disposed and not set to null in the array,
// those body objects will be re-used.
bodyFrame.GetAndRefreshBodyData(this.bodies);
dataReceived = true;
}
}
if (dataReceived)
{
int trackedBodyCount = 0;
for (int i=0; i<this.bodies.Length; ++i)
{
if(this.bodies[i].IsTracked) {
trackedBodyCount += 1;
}
}
if (trackedBodyCount == 1)
{
// One skeleton is tracked
}
}
}