Exemple #1
0
        public void DrawLatestFaceResults(FaceManager manager, WriteableBitmap lastBitmap)
        {
            int counter = 0;

            for (int i = 0; i < manager.bodyCount; i++)
            {
                if (manager.faceTrackers[i].Reader != null)
                {
                    HighDefinitionFaceFrame frame = manager.faceTrackers[i].Reader.AcquireLatestFrame();

                    if (frame != null && frame.FaceModel != null && frame.IsFaceTracked)
                    {
                        DrawFaceBoundingBox(frame, manager.faceTrackers[i], faceColors[i]);
                        DrawFaceBodyInfo(manager.faceTrackers[i], faceColors[i], counter);

                        if (!manager.faceTrackers[i].ScreenshotTaken && manager.faceTrackers[i].CollectionCompleted)
                        {
                            if (lastBitmap != null)
                            {
                                ScreenshotFace(manager.faceTrackers[i], lastBitmap);
                            }
                        }

                        counter++;
                    }
                }
            }
        }
        internal static void CopyToFrameToDrawingContext(this HighDefinitionFaceFrame highDefinitionFaceFrame, DrawingContext context, bool useDepthSpace = true, byte bodyIndex = 1, double pointRadius = 2F)
        {
            var faceAlignment    = new FaceAlignment();
            var coordinateMapper = highDefinitionFaceFrame.HighDefinitionFaceFrameSource.KinectSensor.CoordinateMapper;
            var brush            = BodyIndexColor.GetBrushFromBodyIndex(bodyIndex);

            highDefinitionFaceFrame.GetAndRefreshFaceAlignmentResult(faceAlignment);

            var faceModel = new FaceModel();
            var vertices  = faceModel.CalculateVerticesForAlignment(faceAlignment);

            if (vertices.Count > 0)
            {
                for (int index = 0; index < vertices.Count; index++)
                {
                    CameraSpacePoint vertice = vertices[index];
                    DepthSpacePoint  point   = coordinateMapper.MapCameraPointToDepthSpace(vertice);

                    if (float.IsInfinity(point.X) || float.IsInfinity(point.Y))
                    {
                        return;
                    }

                    context.DrawEllipse(brush, null, point.GetPoint(), pointRadius, pointRadius);
                }
            }
        }
Exemple #3
0
        private void DrawFaceFeatures(HighDefinitionFaceFrame frame, FaceAlignment alignment, Color color)
        {
            frame.GetAndRefreshFaceAlignmentResult(alignment);
            var vertices = frame.FaceModel.CalculateVerticesForAlignment(alignment);

            if (vertices.Count > 0)
            {
                for (int index = 0; index < vertices.Count; index++)
                {
                    Ellipse ellipse = new Ellipse
                    {
                        Width  = 2.0,
                        Height = 2.0,
                        Fill   = new SolidColorBrush(color)
                    };

                    CameraSpacePoint vertice = vertices[index];
                    ColorSpacePoint  point   = sensor.CoordinateMapper.MapCameraPointToColorSpace(vertice);

                    if (float.IsInfinity(point.X) || float.IsInfinity(point.Y))
                    {
                        return;
                    }

                    Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
                    Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);

                    canvas.Children.Add(ellipse);
                }
            }
        }
        private void OnFaceReaderHighDefFrameArrived(object sender, HighDefinitionFaceFrameArrivedEventArgs e)
        {
            using (HighDefinitionFaceFrame frame = e.FrameReference.AcquireFrame())
            {
                if (frame != null && frame.IsFaceTracked)
                {
                    frame.GetAndRefreshFaceAlignmentResult(_faceAlignment);

                    if (_faceModel != null && _sensor != null)
                    {
                        CameraSpacePoint[] cameraSpacePoints = _faceModel.CalculateVerticesForAlignment(_faceAlignment).ToArray();
                        DepthSpacePoint[]  depthSpacePoints  = new DepthSpacePoint[cameraSpacePoints.Length];

                        if (cameraSpacePoints.Length > 0)
                        {
                            _sensor.CoordinateMapper.MapCameraPointsToDepthSpace(cameraSpacePoints, depthSpacePoints);
                        }

                        _faceState.Points = depthSpacePoints.ConvertToPointF();

                        if (this.OnFaceChanged != null)
                        {
                            this.OnFaceChanged(sender, _faceState);
                        }
                    }
                }
            }
        }
        internal static DrawingVisual GetDrawingGroup(this HighDefinitionFaceFrame highDefinitionFaceFrame, bool useDepthSpace = true, byte bodyIndex = 1, double pointRadius = 2F)
        {
            var bodyDrawingGroup = new DrawingVisual();

            highDefinitionFaceFrame.CopyToFrameToDrawingGroup(ref bodyDrawingGroup, useDepthSpace, bodyIndex, pointRadius);

            return(bodyDrawingGroup);
        }
        internal static void CopyToFrameToDrawingGroup(this HighDefinitionFaceFrame highDefinitionFaceFrame, ref DrawingVisual drawingVisual, bool useDepthSpace = true, byte bodyIndex = 1, double pointRadius = 2F)
        {
            drawingVisual.Children.Clear();

            using (DrawingContext context = drawingVisual.RenderOpen())
            {
                highDefinitionFaceFrame.CopyToFrameToDrawingContext(context, useDepthSpace, bodyIndex, pointRadius);
            }
        }
        public static BitmapSource ToBitmapSource(this HighDefinitionFaceFrame highDefinitionFaceFrame, byte bodyIndex = 1, double pointRadius = 2F)
        {
            var frameDescription   = highDefinitionFaceFrame.HighDefinitionFaceFrameSource.KinectSensor.DepthFrameSource.FrameDescription;
            var renderTargetBitmap = new RenderTargetBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Pbgra32);
            var drawingGroup       = highDefinitionFaceFrame.GetDrawingGroup(true, bodyIndex, pointRadius);

            renderTargetBitmap.Render(drawingGroup);

            return(renderTargetBitmap);
        }
Exemple #8
0
        private void HdFaceReader_FrameArrived(object sender, HighDefinitionFaceFrameArrivedEventArgs e)
        {
            faceFrame = e.FrameReference.AcquireFrame();
            if (faceFrame == null || !faceFrame.IsFaceTracked)
            {
                return;
            }

            faceFrame.GetAndRefreshFaceAlignmentResult(this.faceAlignment);
        }
 internal static byte[] GetNewPixelArray(this HighDefinitionFaceFrame highDefinitionFaceFrame, bool useDepthSpace = true)
 {
     if (useDepthSpace)
     {
         return(highDefinitionFaceFrame.HighDefinitionFaceFrameSource.KinectSensor.DepthFrameSource.GetNewPixelArray());
     }
     else
     {
         return(highDefinitionFaceFrame.HighDefinitionFaceFrameSource.KinectSensor.ColorFrameSource.GetNewPixelArray());
     }
 }
 internal static FrameDescription GetFrameDescription(this HighDefinitionFaceFrame highDefinitionFaceFrame, bool useDepthSpace = true)
 {
     if (useDepthSpace)
     {
         return(highDefinitionFaceFrame.HighDefinitionFaceFrameSource.KinectSensor.DepthFrameSource.FrameDescription);
     }
     else
     {
         return(highDefinitionFaceFrame.HighDefinitionFaceFrameSource.KinectSensor.ColorFrameSource.FrameDescription);
     }
 }
Exemple #11
0
        private void _FaceFrameHandler(object sender, HighDefinitionFaceFrameArrivedEventArgs e)
        {
            HighDefinitionFaceFrame faceFrame = e.FrameReference.AcquireFrame();

            // Checks face is tracked from body frame handler
            if (faceFrame != null && faceFrame.IsFaceTracked)
            {
                faceFrame.GetAndRefreshFaceAlignmentResult(_faceAlignment);

                _DrawFacePoints();
            }
        }
Exemple #12
0
        void faceReader_FrameArrived(object sender, HighDefinitionFaceFrameArrivedEventArgs e)
        {
            using (HighDefinitionFaceFrame frame = e.FrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    if (frame.IsTrackingIdValid == false)
                    {
                        return;
                    }
                    frame.GetAndRefreshFaceAlignmentResult(this.faceAlignment);
                    var vertices = this.faceModel.CalculateVerticesForAlignment(this.faceAlignment);

                    for (int i = 0; i < vertices.Count; i++)
                    {
                        var v = vertices[i];
                        this.FOutVertices[i] = new Vector3(v.X, v.Y, v.Z);
                    }

                    this.FOutFrameNumber[0] = frame.RelativeTime.Ticks;
                    //var res = frame.FaceModel.CalculateVerticesForAlignment(FaceAlignmen;

                    /*if(res != null)
                     * {
                     *  this.FOutFrameNumber[0] = (int)frame.FaceFrameResult.RelativeTime.Ticks;
                     *
                     *  Vector2 pos;
                     *  Vector2 size;
                     *
                     *  size.X = res.FaceBoundingBoxInColorSpace.Right - res.FaceBoundingBoxInColorSpace.Left;
                     *  //size.X /= 1920.0f;
                     *
                     *  size.Y = res.FaceBoundingBoxInColorSpace.Bottom - res.FaceBoundingBoxInColorSpace.Top;
                     *  //size.Y /= 1080.0f;
                     *
                     *  pos.X = size.X / 2.0f + (float)res.FaceBoundingBoxInColorSpace.Left;
                     *  pos.Y = size.Y / 2.0f + (float)res.FaceBoundingBoxInColorSpace.Top;
                     *
                     *  this.FOutPositionColor[0] = pos;
                     *  this.FOutSizeColor[0] = size;
                     *
                     *  this.FOutOrientation[0] = new Quaternion(res.FaceRotationQuaternion.X, res.FaceRotationQuaternion.Y,
                     *      res.FaceRotationQuaternion.Z, res.FaceRotationQuaternion.W);
                     *
                     *  this.FOutMouthOpen[0] = res.FaceProperties[FaceProperty.MouthOpen];
                     * } */
                }
            }
        }
 private void FrameArrived(object sender, HighDefinitionFaceFrameArrivedEventArgs e)
 {
     using (HighDefinitionFaceFrame frame = e.FrameReference.AcquireFrame())
     {
         if (frame != null)
         {
             if (frame.IsTrackingIdValid == false)
             {
                 return;
             }
             frame.GetAndRefreshFaceAlignmentResult(this.faceAlignment);
             frame.Dispose();
             if (this.HdFrameReceived != null)
             {
                 this.HdFrameReceived(this, new HdFaceFrameResultEventArgs(this.TrackingId, this.faceModel, this.faceAlignment));
             }
         }
     }
 }
        void faceReader_FrameArrived(object sender, HighDefinitionFaceFrameArrivedEventArgs e)
        {
            using (HighDefinitionFaceFrame frame = e.FrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    this.alignmentQuality = frame.FaceAlignmentQuality.ToString();
                    if (frame.IsTrackingIdValid == false)
                    {
                        return;
                    }
                    if (frame.FaceAlignmentQuality == FaceAlignmentQuality.Low)
                    {
                        return;
                    }

                    frame.GetAndRefreshFaceAlignmentResult(this.faceAlignment);
                    var o = this.faceAlignment.FaceOrientation;
                    this.FOutOrientation[0] = new Quaternion(o.X, o.Y, o.Z, o.W);

                    if (this.FInRCheck[0])
                    {
                        float f = this.FOutOrientation[0].LengthSquared();
                        if (f > 0.1f)
                        {
                            this.cameraPoints = this.faceModel.CalculateVerticesForAlignment(this.faceAlignment).ToArray();
                            this.runtime.Runtime.CoordinateMapper.MapCameraPointsToColorSpace(this.cameraPoints, this.colorPoints);
                            SetBounds();
                        }
                    }
                    else
                    {
                        this.cameraPoints = this.faceModel.CalculateVerticesForAlignment(this.faceAlignment).ToArray();
                        this.runtime.Runtime.CoordinateMapper.MapCameraPointsToColorSpace(this.cameraPoints, this.colorPoints);

                        SetBounds();
                    }
                }
            }
        }
        private static void UpdateFace()
        {
            if (faceReader != null)
            {
                HighDefinitionFaceFrame frame = faceReader.AcquireLatestFrame();
                if (frame != null && frame.IsFaceTracked)
                {
                    _faceIsTracked = true;
                    frame.GetAndRefreshFaceAlignmentResult(faceAlignment);

                    IList <CameraSpacePoint> vertices = faceModel.CalculateVerticesForAlignment(faceAlignment);
                    for (int i = 0; i < FaceModel.VertexCount; i++)
                    {
                        faceGeometry[i] = new Vector(vertices[i].X, vertices[i].Y, -vertices[i].Z);
                    }
                }
            }
            else
            {
                _faceIsTracked = false;
            }
        }
Exemple #16
0
        void faceFrameReader_FrameArrived(object sender, HighDefinitionFaceFrameArrivedEventArgs e)
        {
            lock (faceFrameLock)
            {
                if (processedLastFaceFrame)
                {
                    processedLastFaceFrame = false;
                    bool dataReceived = false;

                    using (HighDefinitionFaceFrame faceFrame = e.FrameReference.AcquireFrame())
                    {
                        if (faceFrame != null && faceFrame.IsFaceTracked)
                        {
                            faceFrame.GetAndRefreshFaceAlignmentResult(currentFaceAlignment);
                            dataReceived = true;
                        }
                    }

                    if (dataReceived && FaceFrameReady != null)
                    {
                        ThreadManager.invoke(() =>
                        {
                            lock (faceFrameLock)
                            {
                                FaceFrameReady.Invoke(currentFaceAlignment);
                                processedLastFaceFrame = true;
                            }
                        });
                    }
                    else
                    {
                        processedLastFaceFrame = true;
                    }
                }
            }
        }
    protected override void OnBodyFrameReceived(BodyFrame frame)
    {
        // Each user controls an avatar separately
        if (useSeparateUsers)
        {
            Body[] users     = frame.Bodies().Where(b => b.IsTracked).ToArray();
            int    userCount = users.Length;

            for (int i = 0; i < userCount; i++)
            {
                if (models[i].updateModel)
                {
                    Avateering.Update(models[i], users[i]);
                }

                if (showStickmen)
                {
                    if (!stickmen[i].gameObject.activeSelf)
                    {
                        stickmen[i].gameObject.SetActive(true);
                    }
                }
                else if (stickmen[i].gameObject.activeSelf)
                {
                    stickmen[i].gameObject.SetActive(false);
                }

                stickmen[i].UpdateBody(users[i], frameView, KinectSensor.CoordinateMapper, visualization);
            }

            if (faceFrameReader != null && users.Length > 0)
            {
                if (!faceFrameSource.IsTrackingIdValid)
                {
                    faceFrameSource.TrackingId = users[0].TrackingId;
                }

                using (var faceFrame = faceFrameReader.AcquireLatestFrame())
                {
                    if (faceFrame != null)
                    {
                        Face face = faceFrame.Face();

                        if (face != null)
                        {
                            if (!detailedFace.gameObject.activeSelf)
                            {
                                detailedFace.gameObject.SetActive(true);
                            }

                            detailedFace.UpdateFace(face, frameView, visualization, KinectSensor.CoordinateMapper);
                        }
                        else if (detailedFace.gameObject.activeSelf)
                        {
                            detailedFace.gameObject.SetActive(false);
                        }
                    }
                }
            }

            for (int i = userCount; i < models.Length; i++)
            {
                if (stickmen[i].gameObject.activeSelf)
                {
                    stickmen[i].gameObject.SetActive(false);
                }
            }
        }
        // The first assigned user controls all avatars
        else
        {
            //   Body user = frame.Bodies().First();//Closest();
            // Debug.Log(user);
            if (user == null)
            {
                user = frame.Bodies().Closest();
            }
            else
            {
                // user = frame.Bodies().First();
            }

            if (user != null)
            {
                for (int i = 0; i < models.Length; i++)
                {
                    if (models[i].updateModel)
                    {
                        Avateering.Update(models[i], user);
                    }
                }

                if (showStickmen)
                {
                    if (!stickmen[0].gameObject.activeSelf)
                    {
                        stickmen[0].gameObject.SetActive(true);
                    }
                }
                else if (stickmen[0].gameObject.activeSelf)
                {
                    stickmen[0].gameObject.SetActive(false);
                }

                stickmen[0].UpdateBody(user, frameView, KinectSensor.CoordinateMapper, visualization);

                if (faceFrameReader != null)
                {
                    if (!faceFrameSource.IsTrackingIdValid)
                    {
                        faceFrameSource.TrackingId = user.TrackingId;
                    }

                    using (HighDefinitionFaceFrame faceFrame = faceFrameReader.AcquireLatestFrame())
                    {
                        if (faceFrame != null)
                        {
                            Face face = faceFrame.Face();

                            if (face != null)
                            {
                                if (!detailedFace.gameObject.activeSelf)
                                {
                                    detailedFace.gameObject.SetActive(true);
                                }

                                detailedFace.UpdateFace(face, frameView, visualization, KinectSensor.CoordinateMapper);
                            }
                            else if (detailedFace.gameObject.activeSelf)
                            {
                                detailedFace.gameObject.SetActive(false);
                            }
                        }
                    }
                }
            }
        }
    }
Exemple #18
0
    public bool UpdateFaceTracking()
    {
        if (bodyData == null || faceFrameSources == null || faceFrameReaders == null)
        {
            return(false);
        }

        for (int i = 0; i < this.bodyCount; i++)
        {
            if (faceFrameSources[i] != null)
            {
                if (!faceFrameSources[i].IsTrackingIdValid)
                {
                    faceFrameSources[i].TrackingId = 0;
                }

                if (bodyData[i] != null && bodyData[i].IsTracked)
                {
                    faceFrameSources[i].TrackingId = bodyData[i].TrackingId;
                }
            }

            if (faceFrameReaders[i] != null)
            {
                FaceFrame faceFrame = faceFrameReaders[i].AcquireLatestFrame();

                if (faceFrame != null)
                {
                    int index = GetFaceSourceIndex(faceFrame.FaceFrameSource);

                    if (ValidateFaceBox(faceFrame.FaceFrameResult))
                    {
                        faceFrameResults[index] = faceFrame.FaceFrameResult;
                    }
                    else
                    {
                        faceFrameResults[index] = null;
                    }

                    faceFrame.Dispose();
                    faceFrame = null;
                }
            }

            ///////// HD Face
            if (hdFaceFrameSources != null && hdFaceFrameSources[i] != null)
            {
                if (!hdFaceFrameSources[i].IsTrackingIdValid)
                {
                    hdFaceFrameSources[i].TrackingId = 0;
                }

                if (bodyData[i] != null && bodyData[i].IsTracked)
                {
                    hdFaceFrameSources[i].TrackingId = bodyData[i].TrackingId;
                }
            }

            if (hdFaceFrameReaders != null && hdFaceFrameReaders[i] != null)
            {
                HighDefinitionFaceFrame hdFaceFrame = hdFaceFrameReaders[i].AcquireLatestFrame();

                if (hdFaceFrame != null)
                {
                    if (hdFaceFrame.IsFaceTracked && (hdFaceAlignments[i] != null))
                    {
                        hdFaceFrame.GetAndRefreshFaceAlignmentResult(hdFaceAlignments[i]);
                    }

                    hdFaceFrame.Dispose();
                    hdFaceFrame = null;
                }
            }
        }

        return(true);
    }
Exemple #19
0
 public void Send(HighDefinitionFaceFrame frame, FaceAlignment alignment)
 {
     this.Send(frame.TrackingId, alignment);
 }
        void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            byte[] _pixelsFrame = null;

            var reference = e.FrameReference.AcquireFrame();

            if (this.frameSourceType == FrameSourceTypes.Color)
            {
                using (var frame = reference.ColorFrameReference.AcquireFrame())
                {
                    if (frame != null)
                    {
                        if (frame.RawColorImageFormat == ColorImageFormat.Bgra)
                        {
                            frame.CopyRawFrameDataToArray(_pixelsColor);
                        }
                        else
                        {
                            frame.CopyConvertedFrameDataToArray(_pixelsColor, ColorImageFormat.Bgra);
                        }
                        _pixelsFrame = _pixelsColor;
                    }
                }
            }
            else if (this.frameSourceType == FrameSourceTypes.Infrared)
            {
                using (var frame = reference.InfraredFrameReference.AcquireFrame())
                {
                    if (frame != null)
                    {
                        using (KinectBuffer infrBuffer = frame.LockImageBuffer())
                        {
                            if ((infraredFrameDescription.Width * infraredFrameDescription.Height) == (infrBuffer.Size / infraredFrameDescription.BytesPerPixel))
                            {
                                this.ProcessInfraredFrameData(ref _pixelsInfra, infrBuffer.UnderlyingBuffer, infrBuffer.Size);
                            }
                        }
                        _pixelsFrame = _pixelsInfra;
                    }
                }
            }
            else if (this.frameSourceType == FrameSourceTypes.Depth)
            {
                using (var frame = reference.DepthFrameReference.AcquireFrame())
                {
                    if (frame != null)
                    {
                        using (KinectBuffer depthBuffer = frame.LockImageBuffer())
                        {
                            if ((depthFrameDescription.Width * depthFrameDescription.Height) == (depthBuffer.Size / depthFrameDescription.BytesPerPixel))
                            {
                                ushort maxDepth = ushort.MaxValue;

                                ProcessDepthFrameData(ref _pixelsDepth, depthBuffer.UnderlyingBuffer, depthBuffer.Size, frame.DepthMinReliableDistance, maxDepth);
                            }
                        }
                        _pixelsFrame = _pixelsDepth;
                    }
                }
            }

            using (var frame = reference.BodyFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    _bodies = new Body[bodyCountTotal];
                    frame.GetAndRefreshBodyData(_bodies);

                    for (int i = 0; i < bodyCountTotal; i++)
                    {
                        FaceTracker curTrack = this.FaceTrackers[i];
                        if (!curTrack.Source.IsTrackingIdValid)
                        {
                            if (_bodies[i].IsTracked)
                            {
                                this.FaceTrackers[i].TrackingId = _bodies[i].TrackingId;
                                this._faces[i].TrackingId       = _bodies[i].TrackingId;
                            }
                        }
                        if (curTrack.Reader != null)
                        {
                            HighDefinitionFaceFrame hdFrame = curTrack.Reader.AcquireLatestFrame();

                            if (hdFrame != null)
                            {
                                this._faces[i].IsTracked = hdFrame.IsFaceTracked;
                                if (hdFrame.FaceModel != null && hdFrame.IsFaceTracked)
                                {
                                    hdFrame.GetAndRefreshFaceAlignmentResult(curTrack.Alignment);
                                    var vertices = curTrack.Model.CalculateVerticesForAlignment(curTrack.Alignment);
                                    this._faces[i].Update(vertices);
                                }
                            }
                        }
                    }
                }
            }

            KinectFrameEventArgs data = new KinectFrameEventArgs(_pixelsFrame, this.frameSourceType, _bodies, _faces);

            OnFrameArrived?.Invoke(this, data);
        }
Exemple #21
0
        private void DrawFaceBoundingBox(HighDefinitionFaceFrame frame, FaceTracker tracker, Color color)
        {
            frame.GetAndRefreshFaceAlignmentResult(tracker.Alignment);
            var vertices = tracker.Model.CalculateVerticesForAlignment(tracker.Alignment);

            if (vertices.Count > 0)
            {
                CameraSpacePoint verticeTop = vertices[(int)HighDetailFacePoints.ForeheadCenter];
                ColorSpacePoint  pointTop   = sensor.CoordinateMapper.MapCameraPointToColorSpace(verticeTop);

                CameraSpacePoint verticeLeft = vertices[(int)HighDetailFacePoints.Leftcheekbone];
                ColorSpacePoint  pointLeft   = sensor.CoordinateMapper.MapCameraPointToColorSpace(verticeLeft);

                CameraSpacePoint verticeRight = vertices[(int)HighDetailFacePoints.Rightcheekbone];
                ColorSpacePoint  pointRight   = sensor.CoordinateMapper.MapCameraPointToColorSpace(verticeRight);

                CameraSpacePoint verticeBottom = vertices[(int)HighDetailFacePoints.ChinCenter];
                ColorSpacePoint  pointBottom   = sensor.CoordinateMapper.MapCameraPointToColorSpace(verticeBottom);

                if (float.IsInfinity(pointTop.X) || float.IsInfinity(pointTop.Y))
                {
                    return;
                }
                if (float.IsInfinity(pointLeft.X) || float.IsInfinity(pointLeft.Y))
                {
                    return;
                }
                if (float.IsInfinity(pointRight.X) || float.IsInfinity(pointRight.Y))
                {
                    return;
                }
                if (float.IsInfinity(pointBottom.X) || float.IsInfinity(pointBottom.Y))
                {
                    return;
                }

                float  posX     = pointLeft.X;
                float  posY     = pointTop.Y;
                double width    = Math.Abs(pointRight.X - pointLeft.X);
                double height   = Math.Abs(pointTop.Y - pointBottom.Y);
                double lineSize = 5;

                Rectangle rect = CreateFaceBoxRectangle(color, lineSize, width, height);
                Canvas.SetLeft(rect, posX);
                Canvas.SetTop(rect, posY);

                canvas.Children.Add(rect);
                tracker.FaceBox.X      = posX;
                tracker.FaceBox.Y      = posY;
                tracker.FaceBox.Width  = width;
                tracker.FaceBox.Height = height;

                if (!tracker.CollectionEventCalled)
                {
                    if (tracker.ModelBuilder.CollectionStatus.HasFlag(FaceModelBuilderCollectionStatus.FrontViewFramesNeeded))
                    {
                        Rectangle rectFront = CreateFaceBoxRectangle(color, 5, 30, 30);
                        Canvas.SetLeft(rectFront, posX + width / 2);
                        Canvas.SetTop(rectFront, posY + height / 2);

                        canvas.Children.Add(rectFront);
                    }

                    if (tracker.ModelBuilder.CollectionStatus.HasFlag(FaceModelBuilderCollectionStatus.LeftViewsNeeded))
                    {
                        Rectangle rectLeft = CreateFaceBoxRectangle(color, 5, 30, 30);
                        Canvas.SetLeft(rectLeft, posX - width / 2);
                        Canvas.SetTop(rectLeft, posY + height / 2);

                        canvas.Children.Add(rectLeft);
                    }

                    if (tracker.ModelBuilder.CollectionStatus.HasFlag(FaceModelBuilderCollectionStatus.RightViewsNeeded))
                    {
                        Rectangle rectRight = CreateFaceBoxRectangle(color, 5, 30, 30);
                        Canvas.SetLeft(rectRight, posX + width + width / 2);
                        Canvas.SetTop(rectRight, posY + height / 2);

                        canvas.Children.Add(rectRight);
                    }

                    if (tracker.ModelBuilder.CollectionStatus.HasFlag(FaceModelBuilderCollectionStatus.TiltedUpViewsNeeded))
                    {
                        Rectangle rectUp = CreateFaceBoxRectangle(color, 5, 30, 30);
                        Canvas.SetLeft(rectUp, posX + width / 2);
                        Canvas.SetTop(rectUp, posY - height / 2);

                        canvas.Children.Add(rectUp);
                    }
                }
            }
        }
Exemple #22
0
        public static IReadOnlyList <CameraSpacePoint> Face(this HighDefinitionFaceFrame frame)
        {
            frame.GetAndRefreshFaceAlignmentResult(_faceAlignment);

            return(_faceModel.CalculateVerticesForAlignment(_faceAlignment));
        }