private async Task <ProcessedFace> ProcessFace(ReadOnlyMemory <byte> sourcePhotoMemory, Face face) { var processedFace = new ProcessedFace(face); using var sourcePhoto = Image.Load(sourcePhotoMemory.Span); { var debugImage = DrawDebugImage(sourcePhoto, face, InflationFactor); processedFace.DebugImage = debugImage.SaveAsJpeg(); } var croppedPhoto = CropFace(sourcePhoto, face, InflationFactor); processedFace.CroppedPhoto = croppedPhoto.SaveAsPng(); processedFace.TransparentPhoto = await _backgroundRemovalApiClient.RemoveBackground(processedFace.CroppedPhoto); var transparentPhoto = Image.Load(processedFace.TransparentPhoto.Span, new PngDecoder()); var profileImage = CreateProfileImage(transparentPhoto); processedFace.ProfileImage = profileImage.SaveAsPng(); return(processedFace); }
public async Task <string> SaveProcessedFaceAsync(ProcessedFace processedFace, CancellationToken cancellationToken = default) { await SaveMemoryToBlob(processedFace.TransparentPhoto, $"{processedFace.Face.FaceId}_raw.png", cancellationToken); return(await SaveMemoryToBlob(processedFace.ProfileImage, $"{processedFace.Face.FaceId}.png", cancellationToken)); }