static void FaceDetectorFPSTest(SessionOptions options, Bitmap bitmap) { int tic, toc, time; float average; var faceDetector = new FaceDetector(options); Console.WriteLine($"FPS test for [{faceDetector}]"); Console.WriteLine($"Initializing GPU device [{gpuId}]"); tic = Environment.TickCount; _ = faceDetector.Forward(bitmap); toc = Environment.TickCount - tic; Console.WriteLine($"Finished in [{toc}] mls."); time = 0; Console.WriteLine($"Running FPS test for [{iterations}] iterations"); for (int i = 0; i < iterations; i++) { tic = Environment.TickCount; _ = faceDetector.Forward(bitmap); toc = Environment.TickCount - tic; time += toc; } average = time / (float)iterations; Console.WriteLine($"FPS --> [{oneSecond / average}]\n"); }
static void Main() { Console.WriteLine("FaceONNX: Face semantic segmentation"); var files = Directory.GetFiles(@"..\..\..\images"); var path = @"..\..\..\results"; using var faceDetector = new FaceDetector(); using var faceParser = new FaceParser(); Directory.CreateDirectory(path); 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 labels = faceParser.Forward(bitmap, face); foreach (var label in labels) { using var segmentated = FaceParser.ToBitmap(label); segmentated.Save(Path.Combine(path, filename)); } } } Console.WriteLine("Done."); Console.ReadKey(); }
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(); }