Reputation: 2489
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. 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. 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?
Upvotes: 0
Views: 2589
Reputation: 2489
I found a solution based on @Marks comments, and this post: http://www.kinectingforwindows.com/
I first needed to set both the trackingId and the faceframwfeatures, I do this when I get a tracked body:
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:
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":
After I got the post build events up running, I got data in the FaceFrame :)
Upvotes: 2