简体   繁体   English

Kinect v2脸部追踪-如何开始?

[英]Kinect v2 facetracking - how to get started?

I just got my brand new Kinect for Windows v2, I have some programs from the old SDK I would like to port, and from msdn it should be easy. 我刚刚获得了用于Windows v2的全新Kinect,我想从旧的SDK中移植一些程序,而从msdn移植它应该很容易。 From the samples that comes with the SDK, I feel I have some decent understanding of the new features, I got color, depth and body(the old skeleton) working. 从SDK随附的示例中,我觉得我对新功能有了一定的了解,可以使颜色,深度和主体(旧骨架)正常工作。 Now I just wont to get the facial tracking up running. 现在,我只是不想让面部跟踪开始运行。 And here starts my problems. 从这里开始我的问题。

If I would like the color data: 如果我想要颜色数据:

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

If I would like the body data: 如果我想要身体数据:

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

But if I would like to get the face data, I never get the callback: 但是,如果我想获取人脸数据,就永远不会得到回调:

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

Can anyone help me with how I get face tracking to work in kinect v2 sdk? 谁能帮我解决如何在kinect v2 sdk中使用人脸跟踪?

I found a solution based on @Marks comments, and this post: http://www.kinectingforwindows.com/ 我发现了一种基于@Marks注释的解决方案,并且该帖子: http ://www.kinectingforwindows.com/

I first needed to set both the trackingId and the faceframwfeatures, I do this when I get a tracked body: 我首先需要设置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 sets the _player to the body, and starts the facetracking: PlayTracked将_player设置为主体,并开始面部跟踪:

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

And then the tracking is started: 然后开始跟踪:

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);
    }

Then I need on last and very important thing, the post build event, which is to copy the NuiDatabase to the output folder on my installation it's: "C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v8.0\\ExtensionSDKs\\Microsoft.Kinect.Face\\2.0\\Redist\\CommonConfiguration\\x64\\NuiDatabase": 然后,我需要做的最后一个非常重要的事情是构建后事件,该事件将NuiDatabase复制到我安装的输出文件夹中:“ C:\\ Program Files(x86)\\ Microsoft SDKs \\ Windows \\ v8.0 \\ ExtensionSDKs \\ Microsoft.Kinect.Face \\ 2.0 \\ Redist \\ CommonConfiguration \\ x64 \\ NuiDatabase“: 在此处输入图片说明

After I got the post build events up running, I got data in the FaceFrame :) 在运行后构建事件后,我在FaceFrame中获取了数据:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM