Ejemplo n.º 1
0
 public Coordinates2D?GetFaceCoordinates()
 {
     if (this.trackSucceeded)
     {
         Coordinates2D c = new Coordinates2D();
         c.X      = frame.FaceRect.Left;
         c.Y      = frame.FaceRect.Top;
         c.Width  = frame.FaceRect.Right - frame.FaceRect.Left;
         c.Height = frame.FaceRect.Right - frame.FaceRect.Left;
         EnumIndexableCollection <FeaturePoint, PointF> facePoints = frame.GetProjected3DShape();
         c.LeftEyeX  = (int)((facePoints[FeaturePoint.BelowThreeFourthLeftEyelid].X + facePoints[FeaturePoint.AboveOneFourthLeftEyelid].X) / 2);
         c.LeftEyeY  = (int)((facePoints[FeaturePoint.BelowThreeFourthLeftEyelid].Y + facePoints[FeaturePoint.AboveOneFourthLeftEyelid].Y) / 2);
         c.RightEyeX = (int)((facePoints[FeaturePoint.BelowThreeFourthRightEyelid].X + facePoints[FeaturePoint.AboveOneFourthRightEyelid].X) / 2);
         c.RightEyeY = (int)((facePoints[FeaturePoint.BelowThreeFourthRightEyelid].Y + facePoints[FeaturePoint.AboveOneFourthRightEyelid].Y) / 2);
         return(c);
     }
     return(null);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the face tracking information for this skeleton
        /// </summary>
        public void OnFrameReady(KinectSensor kinectSensor, ColorImageFormat colorImageFormat, byte[] colorImage, DepthImageFormat depthImageFormat, short[] depthImage, Skeleton skeletonOfInterest)
        {
            this.skeletonTrackingState = skeletonOfInterest.TrackingState;

            if (this.skeletonTrackingState != SkeletonTrackingState.Tracked)
            {
                // nothing to do with an untracked skeleton.
                return;
            }

            if (this.faceTracker == null)
            {
                try
                {
                    this.faceTracker = new FaceTracker(kinectSensor);
                }
                catch (InvalidOperationException)
                {
                    // During some shutdown scenarios the FaceTracker
                    // is unable to be instantiated.  Catch that exception
                    // and don't track a face.
                    Debug.WriteLine("AllFramesReady - creating a new FaceTracker threw an InvalidOperationException");
                    this.faceTracker = null;
                }
            }

            if (this.faceTracker != null)
            {
                FaceTrackFrame frame = this.faceTracker.Track(
                    colorImageFormat, colorImage, depthImageFormat, depthImage, skeletonOfInterest);

                this.lastFaceTrackSucceeded = frame.TrackSuccessful;
                if (this.lastFaceTrackSucceeded)
                {
                    if (faceTriangles == null)
                    {
                        // only need to get this once.  It doesn't change.
                        faceTriangles = frame.GetTriangles();
                    }

                    this.facePoints = frame.GetProjected3DShape();
                }
            }
        }