private void FaceFrameReader_FrameArrived(object sender, FaceFrameArrivedEventArgs e) { if (_Continue) { if (e.FrameReference != null) { using (FaceFrame faceFrame = e.FrameReference.AcquireFrame()) { using (ColorFrame colorFrame = faceFrame.ColorFrameReference.AcquireFrame()) { if (faceFrame != null && colorFrame != null) { FaceFrameResult frameResult = faceFrame.FaceFrameResult; if (frameResult != null) { if (!AllBodySamplesCollected()) { if (!BodySamplesComplete(frameResult.TrackingId)) { var currentTrackedBody = _BodyManager.Where(o => o.Key == frameResult.TrackingId).FirstOrDefault(); if (currentTrackedBody.Value != null) { //Joint head = currentTrackedBody.Value.Body.Joints[JointType.Head]; //if (head.TrackingState != TrackingState.NotTracked) //{ // if (colorFrame.RawColorImageFormat == ColorImageFormat) // colorFrame.CopyRawFrameDataToArray(_ColorPixels); // else // colorFrame.CopyConvertedFrameDataToArray(_ColorPixels, ColorImageFormat); // RectF currentColorBoundingBox = frameResult.FaceBoundingBoxInColorSpace.Offset(0.40f, 0.50f, 0.70f); // if (currentColorBoundingBox.X > 0 && currentColorBoundingBox.Y > 0 && currentColorBoundingBox.Height > 0 && currentColorBoundingBox.Width > 0) // { // byte[] colorFace = _ColorPixels.ExtractPixelsFromImage(Convert.ToInt32(currentColorBoundingBox.Y), Convert.ToInt32(currentColorBoundingBox.X), // Convert.ToInt32(currentColorBoundingBox.Width), Convert.ToInt32(currentColorBoundingBox.Height), // _ColorFrameDescription.Width, Convert.ToInt32(_ColorFrameDescription.BytesPerPixel)); // Bitmap faceBitmap = colorFace.ToBitmap(Convert.ToInt32(currentColorBoundingBox.Width), Convert.ToInt32(currentColorBoundingBox.Height)); // FacePhoto photo = new FacePhoto() // { // Distance = Convert.ToInt32(head.Position.DistanceToCamera() * 1000), // TrackingId = frameResult.TrackingId, // Image = faceBitmap // }; // _FacePhotos.Add(photo); // RaisePhotoCollected(photo); // } //} } } } else { Stop(); RaiseCollectionComplete(_FacePhotos.AsReadOnly()); } } } } } } } }