/// <summary>
        /// Handles the LandmarksFound event of the Camera control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="LandmarksEventArgs"/> instance containing the event data.</param>
        private void Camera_LandmarksFound(object sender, LandmarksEventArgs e)
        {
            try
            {
                Dispatcher.Invoke(() =>
                    {
                        Children.Clear();

                        foreach (var landmark in e.Landmarks)
                        {
                            double scaleX = this.ActualWidth / e.Width;
                            double scaleY = this.ActualHeight / e.Height;
                            var rect = new System.Windows.Shapes.Rectangle
                            {
                                Stroke = new SolidColorBrush(Colors.Yellow),
                                StrokeThickness = 1,
                                Margin = new Thickness((landmark.Value.X - 1) * scaleX, (landmark.Value.Y - 1) * scaleY, 0, 0),
                                Width = 2 * scaleX,
                                Height = 2 * scaleY
                            };
                            Children.Add(rect);
                        }
                    });
            }
            catch (TaskCanceledException)
            {
                // Do nothing.
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Handles the <see cref="E:LandmarksFound" /> event.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="LandmarksEventArgs"/> instance containing the event data.</param>
 private void OnLandmarksFound(object sender, LandmarksEventArgs e)
 {
     if (LandmarksFound != null)
     {
         LandmarksFound(sender, e);
     }
 }
        /// <summary>
        /// Handles the LandmarksFound event of the Camera control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="LandmarksEventArgs"/> instance containing the event data.</param>
        private void Camera_LandmarksFound(object sender, LandmarksEventArgs e)
        {
            try
            {
                Dispatcher.Invoke(() =>
                {
                    Children.Clear();

                    foreach (var landmark in e.Landmarks)
                    {
                        double scaleX = this.ActualWidth / e.Width;
                        double scaleY = this.ActualHeight / e.Height;
                        var rect      = new System.Windows.Shapes.Rectangle
                        {
                            Stroke          = new SolidColorBrush(Colors.Yellow),
                            StrokeThickness = 1,
                            Margin          = new Thickness((landmark.Value.X - 1) * scaleX, (landmark.Value.Y - 1) * scaleY, 0, 0),
                            Width           = 2 * scaleX,
                            Height          = 2 * scaleY
                        };
                        Children.Add(rect);
                    }
                });
            }
            catch (TaskCanceledException)
            {
                // Do nothing.
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Called when a face is detected.
        /// </summary>
        /// <param name="module">The module.</param>
        private void OnFaceCallback(PXCMFaceModule module)
        {
            PXCMRectI32 bounds;

            using (var faceData = module.CreateOutput())
            {
                faceData.Update();
                var faces = faceData.QueryFaces();
                foreach (var face in faces)
                {
                    var detection = face.QueryDetection();
                    detection.QueryBoundingRect(out bounds);
//                    Debug.WriteLine("{0} Face detected: {1}", Time(), bounds);

                    var landmarkData = face.QueryLandmarks();
                    if (landmarkData != null)
                    {
                        PXCMFaceData.LandmarkPoint[] landmarks;
                        landmarkData.QueryPoints(out landmarks);

                        var landmarkDict = new Dictionary <string, Point>();

                        foreach (PXCMFaceData.LandmarkPoint landmark in landmarks)
                        {
                            landmarkDict.Add("LANDMARK_" + landmark.source.index, new Point(landmark.image.x, landmark.image.y));

                            /*Debug.WriteLine("{0}/{1} at {2},{3},{4}",
                             *  landmark.source.index,
                             *  landmark.source.alias,
                             *  landmark.image.x,
                             *  landmark.image.y,
                             *  landmark.confidenceImage);
                             */
                        }

                        var landmarkArgs = new LandmarksEventArgs(landmarkDict, Resolution.Item1.width, Resolution.Item1.height);
                        OnLandmarksFound(this, landmarkArgs);
                    }

                    // Expression
                    var expressionValues = new Dictionary <string, double>();
                    var expressionData   = face.QueryExpressions();
                    if (expressionData != null)
                    {
                        foreach (PXCMFaceData.ExpressionsData.FaceExpression expression in Enum.GetValues(typeof(PXCMFaceData.ExpressionsData.FaceExpression)))
                        {
                            PXCMFaceData.ExpressionsData.FaceExpressionResult score;
                            expressionData.QueryExpression(expression, out score);
                            expressionValues.Add(expression.ToString(), score.intensity / 100d);
//                            Debug.WriteLine("{0} Expression: {1} == {2}", Time(), expression, score.intensity / 100d);
                        }
                    }
                    OnFaceFound(this, new FaceEventArgs(new Rectangle(bounds.x, bounds.y, bounds.w, bounds.h), expressionValues, Resolution.Item1.width, Resolution.Item1.height));
                    OnDataAvailable(this, new DataEventArgs(expressionValues));
                }
            }
        }