public byte[] GetMedia(string id) { SampleMedia media = _samples.Single(x => x.Id == id); using var fileStream = new FileStream(media.Path, FileMode.Open); return(fileStream.ToByteArray()); }
public void BuildSampleStore() { var root = new DirectoryInfo(GetTestMediaPath()); foreach (FileInfo file in root.GetFiles("*.jpg")) { var media = new SampleMedia { Id = Guid.NewGuid().ToString("N"), Path = file.FullName, Name = file.Name, }; _samples.Add(media); } }
public async Task <IEnumerable <FaceDetectionInfo> > ExtractFacesAsync(string id) { SampleMedia media = _samples.Single(x => x.Id == id); using var fileStream = new FileStream(media.Path, FileMode.Open); IEnumerable <FaceDetectionResponse> faces = await _faceDetectionService .DetectFacesAsync(fileStream, default); IList <FaceDetectionInfo> infos = faces.Select(f => new FaceDetectionInfo { Box = f.Box, Id = Guid.NewGuid() }).ToList(); fileStream.Position = 0; var image = Image.Load(fileStream); IEnumerable <BoxExtractionInput> inputs = infos.Select(f => new BoxExtractionInput { Box = f.Box, Id = f.Id }); IEnumerable <BoxExtractionResult> images = await _faceExtractorService .ExtractBoxesAsync(image, inputs, ThumbnailSizeName.M, default); foreach (BoxExtractionResult img in images) { FaceDetectionInfo info = infos.Single(x => x.Id == img.Id); info.Image = img.Thumbnail.Data.ToDataUrl("jpg"); } return(infos); }