Пример #1
0
        private void DisplaySmilieResult(WriteableBitmap writeableBitmap, FaceRestAPI.FaceAPI result)
        {
            int countHappy = 0;
            int countSad = 0;
            foreach (var tag in result.photos[0].tags)
            {
                // Uses the segment's center and half width, height
                var c = tag.center;
                Debug.WriteLine("Center ({0} ,{1}), size ({2}, {3})", c.x, c.y, tag.width,
                                tag.height);
                var destRect = new Rect(writeableBitmap.PixelWidth * 0.01 * (tag.center.x - tag.width / 2),
                                        writeableBitmap.PixelHeight * 0.01 * (tag.center.y - tag.height / 2),
                                        writeableBitmap.PixelWidth * 0.01 * tag.width,
                                        writeableBitmap.PixelHeight * 0.01 * tag.height);
                var whichFace = ChooseFace(tag.attributes);
                if (whichFace == _smilieWriteableBitmap)
                    countHappy++;
                else
                    countSad++;
                var sourceRect = new Rect(0, 0, whichFace.PixelWidth, whichFace.PixelHeight);
                writeableBitmap.Blit(destRect, whichFace, sourceRect);
            }

            writeableBitmap.Invalidate();
            SelectedImage.Source = writeableBitmap;

            writeableBitmap.SaveToFile(AppConstants.IsoFileName, (stream) => { /* do nothing */ });
            ShowDisplay(DisplayState.Finished);

            NavigateToPhotoPage(countHappy, countSad);
        }
Пример #2
0
        private void ProcessImage(WriteableBitmap writeable)
        {
            var verySimpleBitmap = new VerySimpleBitmap(writeable.PixelWidth, writeable.PixelHeight);
            writeable.Pixels.CopyTo(verySimpleBitmap.Pixels, 0);
            var detectedSegments = faceLight.Process(verySimpleBitmap);

            var percentage = 0;
            switch (detectedSegments.Count())
            {
                case 0:
                    percentage = 0;
                    break;
                case 1:
                    percentage = 90;
                    break;
                default:
                    percentage = 99;
                    break;
            }

            Debug.WriteLine("{0} segments detected", detectedSegments.Count());
            foreach (var segment in detectedSegments)
            {
                if (segment.Width > 0 && segment.Height > 0)
                {
                    // Uses the segment's center and half width, height
                    var c = segment.Center;
                    Debug.WriteLine("Center ({0} ,{1}), size ({2}, {3})", c.X, c.Y, segment.Width,
                                    segment.Height);
                    var destRect = new Rect(segment.Center.X - segment.Width / 2,
                                              segment.Center.Y - segment.Height / 2,
                                              segment.Width,
                                              segment.Height);
                    var sourceRect = new Rect(0, 0, _chimpWriteableBitmap.PixelWidth, _chimpWriteableBitmap.PixelHeight);
                    writeable.Blit(destRect, _chimpWriteableBitmap, sourceRect);
                }
            }

            writeable.Invalidate();
            SelectedImage.Source = writeable;
            writeable.SaveToFile(AppConstants.IsoFileName, (stream) => { /* do nothing */ });
            ShowDisplay(DisplayState.Finished);
            NavigateToPhotoPage(percentage);
        }