Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json")
                                .AddUserSecrets("8A5141D1-33BC-4B1E-8051-F57FB87FC5C5")
                                .Build();

            var settings = new ProfileImageServiceSettings();

            configuration.Bind(settings);

            var removeBgClient        = new RemoveBgClient(new HttpClient(), settings);
            var faceApiClient         = new FaceApiClient(new HttpClient(), settings);
            var photoProcessorService = new PhotoProcessorService(faceApiClient, removeBgClient)
            {
                Validate = face =>
                {
                    Console.WriteLine($"Validating face '{face.FaceId}'...");
                    return(true);
                }
            };

            var sourcePhoto    = new ReadOnlyMemory <byte>(File.ReadAllBytes("assets/adult-1868750_1280.jpg"));
            var processedFaces = await photoProcessorService.ProcessPhoto(sourcePhoto);

            foreach (var processedFace in processedFaces)
            {
                await using var rawFile = File.Create("output/raw.png");
                await rawFile.WriteAsync(processedFace.TransparentPhoto);

                await using var profileImageFile = File.Create("output/profileImage.png");
                await profileImageFile.WriteAsync(processedFace.ProfileImage);
            }
        }
        public TestFixture()
        {
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json", true)
                                .AddUserSecrets("8A5141D1-33BC-4B1E-8051-F57FB87FC5C5")
                                .Build();

            Settings = new ProfileImageServiceSettings();

            configuration.Bind(Settings);

            Directory.CreateDirectory("test-output");
        }
Ejemplo n.º 3
0
 public FaceApiClient(HttpClient httpClient, ProfileImageServiceSettings settings)
 {
     _httpClient             = httpClient;
     _httpClient.BaseAddress = new Uri(settings.ComputerVisionBaseUrl);
     _httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", settings.ComputerVisionKey2);
 }
Ejemplo n.º 4
0
 public RemoveBgClient(HttpClient httpClient, ProfileImageServiceSettings settings)
 {
     _httpClient             = httpClient;
     _httpClient.BaseAddress = new Uri("https://api.remove.bg/");
     _httpClient.DefaultRequestHeaders.Add("X-Api-Key", settings.RemoveBgApiKey);
 }