Пример #1
0
        private static async Task<SoftwareBitmapSource> CropPhoto(StorageFile photo, FaceRectangle rectangle)
        {
            using (var imageStream = await photo.OpenReadAsync())
            {
                var decoder = await BitmapDecoder.CreateAsync(imageStream);
                if (decoder.PixelWidth >= rectangle.Left + rectangle.Width || decoder.PixelHeight >= rectangle.Top + rectangle.Height)
                {
                    var transform = new BitmapTransform
                    {
                        Bounds = new BitmapBounds
                        {
                            X = (uint)rectangle.Left,
                            Y = (uint)rectangle.Top,
                            Height = (uint)rectangle.Height,
                            Width = (uint)rectangle.Width
                        }
                    };

                    var softwareBitmapBGR8 = await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied, transform, ExifOrientationMode.IgnoreExifOrientation, ColorManagementMode.DoNotColorManage);
                    SoftwareBitmapSource bitmapSource = new SoftwareBitmapSource();
                    await bitmapSource.SetBitmapAsync(softwareBitmapBGR8);

                    return bitmapSource;
                }
                return null;
            }
        }
Пример #2
0
        //PQ caralho não padronizaram essa merda??
        //Porra véi... é uma estrutura que representa um retângulo...

        public static Rectangle ToRectangle(this Face.Contract.FaceRectangle rectangle)
        => new Rectangle
        {
            Height = rectangle.Height,
            Width  = rectangle.Width,
            Left   = rectangle.Left,
            Top    = rectangle.Top
        };
Пример #3
0
 public static Rectangle[] ToRectangle(this Microsoft.ProjectOxford.Face.Contract.FaceRectangle faceRectangle)
 => new Rectangle[]
 {
     new Rectangle {
         Height = faceRectangle.Height,
         Left   = faceRectangle.Left,
         Top    = faceRectangle.Top,
         Width  = faceRectangle.Width
     }
 };
Пример #4
0
 private FaceAPI.Contract.Face CreateFace(FaceAPI.Contract.FaceRectangle rect)
 {
     return(new FaceAPI.Contract.Face {
         FaceRectangle = new FaceAPI.Contract.FaceRectangle {
             Left = rect.Left,
             Top = rect.Top,
             Width = rect.Width,
             Height = rect.Height
         }
     });
 }
Пример #5
0
        private int GetMatchingIndex(Microsoft.ProjectOxford.Face.Contract.FaceRectangle rectID, List <Microsoft.ProjectOxford.Common.Rectangle> rectsE)
        {
            int[] D = new int[rectsE.Count()];
            for (int k = 0; k < D.Length; k++)
            {
                D[k] = RectDist(rectID, rectsE[k]);
            }

            int minD = D.Min();
            int minI = D.ToList().IndexOf(minD);

            return(minI);
        }
Пример #6
0
        static async Task addFace()
        {
            Console.WriteLine("Person:");
            Console.WriteLine("1.   Caleb");
            Console.WriteLine("2.   Adna");
            Console.WriteLine("3.   Jordan");
            Console.WriteLine("4.   Nicole");
            Console.WriteLine("5.   Nat");
            choice = Convert.ToInt32(Console.ReadLine()) - 1;
            Console.WriteLine("Paste URL of picture:");
            input = Console.ReadLine();
            Console.WriteLine("Loading...");
            Microsoft.ProjectOxford.Face.Contract.Face[] face = await client.DetectAsync(input);

            Microsoft.ProjectOxford.Face.Contract.FaceRectangle faceRect = face[0].FaceRectangle;
            AddPersistedFaceResult result = await client.AddPersonFaceAsync("rejected", ids[choice], input, null, faceRect);

            Console.WriteLine("Face added");
        }
Пример #7
0
 private static void runFaceAPI(
     string _filePath, 
     out FaceRectangle[] _rects, 
     out FaceLandmarks[] _landmarks)
 {
     string key = "1cdb412565ae43879ea8133525e89040";
     FaceAPI faceAPI = new FaceAPI(key);
     var detectResult = faceAPI.detectFaces(_filePath);
     Task.WaitAll(detectResult);
     if (detectResult.Result)
     {
         _rects = faceAPI.getFaceRectangles();
         _landmarks = faceAPI.getFaceLandmarks();
     }
     else
     {
         _rects = new FaceRectangle[0];
         _landmarks = new FaceLandmarks[0];
     }
 }
Пример #8
0
        private static Rectangle convertRectangleFormation(
            FaceRectangle _rectangle, string fileName)
        {
            Rectangle rect = new Rectangle(
                _rectangle.Left,
                _rectangle.Top,
                _rectangle.Width,
                _rectangle.Height);

            Image im = Image.FromFile(fileName);
            if (rect.Width + rect.Left > im.Width)
            {
                rect.Width = im.Width - rect.Left;
            }
            if (rect.Height + rect.Top > im.Height)
            {
                rect.Height = im.Height - rect.Top;
            }

            return rect;
        }
Пример #9
0
 private static PointF convertPointFormation(
     FeatureCoordinate _landmark,
     FaceRectangle _rectangle)
 {
     PointF retPoint = new PointF();
     retPoint.X = (float)((_landmark.X - _rectangle.Left) / _rectangle.Width);
     retPoint.Y = (float)((_landmark.Y - _rectangle.Top) / _rectangle.Height);
     return retPoint;
 }
Пример #10
0
 private static PointF[] convertLandmarkFormation(
     ref FaceLandmarks _landmarks,
     ref FaceRectangle _rectangle)
 {
     PointF[] retLandmarks = new PointF[27]{
         convertPointFormation(_landmarks.EyebrowLeftOuter, _rectangle),
         convertPointFormation(_landmarks.EyebrowLeftInner, _rectangle),
         convertPointFormation(_landmarks.EyebrowRightOuter, _rectangle),
         convertPointFormation(_landmarks.EyebrowRightInner, _rectangle),
         convertPointFormation(_landmarks.EyeLeftOuter, _rectangle),
         convertPointFormation(_landmarks.EyeLeftTop, _rectangle),
         convertPointFormation(_landmarks.EyeLeftInner, _rectangle),
         convertPointFormation(_landmarks.EyeLeftBottom, _rectangle),
         convertPointFormation(_landmarks.PupilLeft, _rectangle),
         convertPointFormation(_landmarks.EyeRightOuter, _rectangle),
         convertPointFormation(_landmarks.EyeRightTop, _rectangle),
         convertPointFormation(_landmarks.EyeRightInner, _rectangle),
         convertPointFormation(_landmarks.EyeRightBottom, _rectangle),
         convertPointFormation(_landmarks.PupilRight, _rectangle),
         convertPointFormation(_landmarks.NoseRootLeft, _rectangle),
         convertPointFormation(_landmarks.NoseLeftAlarTop, _rectangle),
         convertPointFormation(_landmarks.NoseLeftAlarOutTip, _rectangle),
         convertPointFormation(_landmarks.NoseTip, _rectangle),
         convertPointFormation(_landmarks.NoseRightAlarOutTip, _rectangle),
         convertPointFormation(_landmarks.NoseRightAlarTop, _rectangle),
         convertPointFormation(_landmarks.NoseRootRight, _rectangle),
         convertPointFormation(_landmarks.MouthLeft, _rectangle),
         convertPointFormation(_landmarks.UpperLipTop, _rectangle),
         convertPointFormation(_landmarks.MouthRight, _rectangle),
         convertPointFormation(_landmarks.UnderLipBottom, _rectangle),
         convertPointFormation(_landmarks.UpperLipBottom, _rectangle),
         convertPointFormation(_landmarks.UnderLipTop, _rectangle)
     };
     return retLandmarks;
 }
Пример #11
0
 private void PositionRectangle(FaceRectangle faceRect)
 {
     Width = faceRect.Width;
     Height = faceRect.Height;
     Left = faceRect.Left;
     Top = faceRect.Top;
 }
Пример #12
0
 private static Rectangle convertRectangleFormation(
     FaceRectangle _rectangle)
 {
     return new Rectangle(
         _rectangle.Left,
         _rectangle.Top,
         _rectangle.Width,
         _rectangle.Height);
 }