Example #1
0
        static float[] GetEmbedding(Bitmap image)
        {
            var faces = _faceDetectorLight.Forward(image);

            using var cropped = Imaging.Crop(image, faces.First());
            var points = _faceLandmarksExtractor.Forward(cropped);

            using var aligned = FaceLandmarksExtractor.Align(cropped, points);
            return(_faceEmbedder.Forward(aligned));
        }
Example #2
0
        static string[] GetEmotionAndBeauty(Bitmap image, Rectangle face)
        {
            using var cropped = Imaging.Crop(image, face);
            var points = _faceLandmarksExtractor.Forward(cropped);

            using var aligned = FaceLandmarksExtractor.Align(cropped, points);
            var emotion      = _faceEmotionClassifier.Forward(aligned);
            var emotionLabel = FaceEmotionClassifier.Labels[emotion.Argmax()];
            var beauty       = _faceBautyClassifier.Forward(aligned);
            var beautyLabel  = $"{Math.Round(2 * beauty.Max(), 1)}/10.0";

            Console.WriteLine($"--> classified as [{emotionLabel}] emotion and [{beautyLabel}] beauty");

            return(new string[] { emotionLabel, beautyLabel });
        }
Example #3
0
        static string[] GetRaceAndAge(Bitmap image, Rectangle face)
        {
            using var cropped = Imaging.Crop(image, face);
            var points = _faceLandmarksExtractor.Forward(cropped);

            using var aligned = FaceLandmarksExtractor.Align(cropped, points);
            var race      = _faceRaceClassifier.Forward(aligned);
            var raceLabel = FaceRaceClassifier.Labels[race.Argmax()];
            var age       = _faceAgeClassifier.Forward(aligned);
            var ageLabel  = FaceAgeClassifier.Labels[age.Argmax()];

            Console.WriteLine($"--> classified as [{raceLabel}] race and [{ageLabel}] age");

            return(new string[] { raceLabel, ageLabel });
        }
Example #4
0
        static void Main()
        {
            Console.WriteLine("FaceONNX: Face landmarks extraction");
            var files = Directory.GetFiles(@"..\..\..\images");
            var path  = @"..\..\..\results";

            Directory.CreateDirectory(path);

            using var faceDetector           = new FaceDetector();
            using var faceLandmarksExtractor = new FaceLandmarksExtractor();
            var painter = new Painter()
            {
                PointPen     = new Pen(Color.Yellow, 4),
                Transparency = 0,
            };

            Console.WriteLine($"Processing {files.Length} images");

            foreach (var file in files)
            {
                using var bitmap = new Bitmap(file);
                var filename = Path.GetFileName(file);
                var faces    = faceDetector.Forward(bitmap);
                Console.WriteLine($"Image: [{filename}] --> detected [{faces.Length}] faces");

                foreach (var face in faces)
                {
                    var points = faceLandmarksExtractor.Forward(bitmap, face);

                    foreach (var point in points)
                    {
                        var paintData = new PaintData()
                        {
                            Points = point,
                            Title  = string.Empty,
                        };

                        painter.Draw(bitmap, paintData);
                        bitmap.Save(Path.Combine(path, filename));
                    }
                }
            }

            Console.WriteLine("Done.");
            Console.ReadKey();
        }