Kinect v2 facetracking - 如何开始?

时间:2014-07-31 13:01:39

标签: c# kinect

我刚刚获得了我全新的Kinect for Windows v2,我有一些来自我希望移植的旧SDK的程序,而且从msdn它应该很容易。从SDK附带的示例中,我觉得我对新功能有一些不错的理解,我得到了颜色,深度和身体(旧骨架)的工作。现在我只是不想让面部跟踪运行起来。这里开始我的问题。

如果我想要颜色数据:

_kinectSensor = KinectSensor.GetDefault();            
_colorFrameReader = _kinectSensor.ColorFrameSource.OpenReader();
_colorFrameReader.FrameArrived += _colorFrameReader_FrameArrived;
_kinectSensor.Open();

如果我想要身体数据:

_bodyFrameReader = _kinectSensor.BodyFrameSource.OpenReader();
bodyFrameReader.FrameArrived += this.Reader_FrameArrived;
_kinectSensor.Open();

但如果我想获得面部数据,我永远不会得到回调:

var faceFrameSource = new FaceFrameSource(KinectSensor.GetDefault());
_faceFrameReader = faceFrameSource.OpenReader();
_faceFrameReader.FrameArrived +=_faceFrameReader_FrameArrived;
_kinectSensor.Open();

任何人都可以帮我了解如何在kinect v2 sdk中进行面部跟踪吗?

1 个答案:

答案 0 :(得分:2)

我找到了一个基于@Marks评论的解决方案,这篇文章:http://www.kinectingforwindows.com/

我首先需要设置trackingId和faceframwfeatures,当我得到一个跟踪的身体时,我会这样做:

private void bodyFrameReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
    {
        var dataReceived = false;

        using (var bodyFrame = e.FrameReference.AcquireFrame())
        {
            if (bodyFrame != null)
            {
                if (_bodies == null)
                {
                    _bodies = new Body[bodyFrame.BodyCount];
                }
                bodyFrame.GetAndRefreshBodyData(_bodies);
                dataReceived = true;
            }
        }

        if (dataReceived)
        {
            foreach (var body in _bodies)
            {
                if(!body.IsTracked)
                    continue;

                if (_player == null)
                    PlayerFound(body);                    
            }
        }
    }

PlayTracked将_player设置为正文,并启动面部跟踪:

private void PlayerFound(Body body)
    {
        _player = body;
        StartFaceTracting(body);
    }

然后开始跟踪:

private void StartFaceTracting(Body body)
    {
        // Face
        _faceFrameSource = new FaceFrameSource(KinectSensor.GetDefault())
        {
            FaceFrameFeatures = FaceFrameFeatures.BoundingBoxInColorSpace | FaceFrameFeatures.PointsInColorSpace,
            TrackingId = body.TrackingId
        };

        _faceFrameSource.TrackingIdLost += _faceFrameSource_TrackingIdLost;

        _faceFrameReader = _faceFrameSource.OpenReader();
        _faceFrameReader.FrameArrived += _faceFrameReader_FrameArrived;
        Log.Info("Facetracking strated Id: " + body.TrackingId);
    }

然后我需要最后一个非常重要的事情,即post build事件,即将NuiDatabase复制到我安装的输出文件夹中:“C:\ Program Files(x86)\ Microsoft SDKs \ Windows \ v8。 0 \ ExtensionSDKs \ Microsoft.Kinect.Face \ 2.0 \的Redist \ CommonConfiguration \ 64 \ NuiDatabase“: enter image description here

在我运行post build事件之后,我在FaceFrame中获得了数据:)