Exemplo n.º 1
0
        private async void Input_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Bitmap")
            {
                //todo call api
                if (callAPI)
                {
                    await getEmotion();
                }

                var bmp = (Bitmap)input.Bitmap.Clone();
                if (faces != null)
                {
                    using (Graphics g = Graphics.FromImage(bmp))
                    {
                        lock (facesLock)
                        {
                            foreach (var face in faces)
                            {
                                // Here we check if the image is known
                                //String name = checkKnownFace(bmp);
                                var faceRec  = face.FaceRectangle;
                                var emotions = face.FaceAttributes.Emotion.ToRankedList();
                                var emotion  = emotions.OrderByDescending(f => f.Value).FirstOrDefault().Key;

                                g.DrawRectangle(new Pen(new SolidBrush(System.Drawing.Color.Yellow), 2), new System.Drawing.Rectangle(faceRec.Left, faceRec.Top, faceRec.Width, faceRec.Height + 45));
                                g.FillRectangle(new SolidBrush(System.Drawing.Color.Yellow), new System.Drawing.Rectangle(faceRec.Left, faceRec.Top + faceRec.Height, faceRec.Width, 45));
                                g.DrawString(emotion, new Font("Arial", 18), new SolidBrush(System.Drawing.Color.Black), faceRec.Left + 5, faceRec.Top + faceRec.Height + 2);
                            }
                        }
                        g.Flush();
                    }
                }
                output.UpdateImages(bmp);
            }
        }