public async Task Enrich(Photo photo, SourceDataDto sourceData) { await Task.Run(() => { photo.PhotoCategories = new List <PhotoCategory>(); foreach (var category in sourceData.ImageAnalysis.Categories) { var catModel = _categoryRepository.GetByCondition(t => t.Name == category.Name).FirstOrDefault(); if (catModel == null) { catModel = new Category { Name = category.Name }; } var photoCategory = new PhotoCategory() { Photo = photo, Category = catModel, Score = category.Score }; photo.PhotoCategories.Add(photoCategory); } }); }
public async Task Enrich(Photo photo, SourceDataDto sourceData) { photo.ObjectProperties = new List <ObjectProperty>(); foreach (var detectedObject in sourceData.ImageAnalysis.Objects) { var propertyName = _propertyNameRepository.GetByCondition(t => t.Name == detectedObject.ObjectProperty).FirstOrDefault(); if (propertyName == null) { propertyName = new PropertyName { Name = detectedObject.ObjectProperty, }; await _propertyNameRepository.InsertAsync(propertyName); } photo.ObjectProperties.Add(new ObjectProperty { PropertyName = propertyName, Rectangle = GeoWrapper.GetRectangle(detectedObject.Rectangle, photo.Scale), Confidence = detectedObject.Confidence }); } }
public async Task Enrich(Photo photo, SourceDataDto sourceData) { await Task.Run(() => { photo.PhotoTags = new List <PhotoTag>(); // Workaround for bug, when service returns the same tags var tags = sourceData.ImageAnalysis.Tags.GroupBy(t => t.Name.ToLower()).Select(t => new { Name = t.Key, Confidence = t.Max(v => v.Confidence) }); foreach (var tag in tags) { var tagModel = _tagRepository.GetByCondition(t => t.Name == tag.Name).FirstOrDefault() ?? new Tag { Name = tag.Name, }; var photoTag = new PhotoTag { Photo = photo, Tag = tagModel, Confidence = tag.Confidence }; photo.PhotoTags.Add(photoTag); } }); }
public async Task Enrich(Photo photo, SourceDataDto path) { await Task.Run(() => { Task.Delay(new Random().Next(500, 1500)); Debug.WriteLine(this.GetType().Name); }); }
public async Task Enrich(Photo photo, SourceDataDto sourceData) { await Task.Run(() => { photo.IsAdultContent = sourceData.ImageAnalysis.Adult.IsAdultContent; photo.AdultScore = sourceData.ImageAnalysis.Adult.AdultScore; photo.IsRacyContent = sourceData.ImageAnalysis.Adult.IsRacyContent; photo.RacyScore = sourceData.ImageAnalysis.Adult.RacyScore; }); }
public async Task Enrich(Photo photo, SourceDataDto sourceData) { await Task.Run(() => { photo.IsBW = sourceData.ImageAnalysis.Color.IsBWImg; photo.AccentColor = sourceData.ImageAnalysis.Color.AccentColor; photo.DominantColorBackground = sourceData.ImageAnalysis.Color.DominantColorBackground; photo.DominantColorForeground = sourceData.ImageAnalysis.Color.DominantColorForeground; photo.DominantColors = string.Join(",", sourceData.ImageAnalysis.Color.DominantColors); }); }
public async Task Enrich(Photo photo, SourceDataDto sourceData) { var thumbnail = await _client.GenerateThumbnailInStreamAsync(50, 50, new MemoryStream(photo.PreviewImage), true); await using (var memoryStream = new MemoryStream()) { await thumbnail.CopyToAsync(memoryStream); photo.Thumbnail = memoryStream.ToArray(); } }
public async Task Enrich(Photo photo, SourceDataDto sourceData) { await Task.Run(() => { photo.Captions = new List <Caption>(); foreach (var caption in sourceData.ImageAnalysis.Description.Captions) { photo.Captions.Add(new Caption { Confidence = caption.Confidence, Text = caption.Text }); } }); }
public async Task Enrich(Photo photo, SourceDataDto sourceData) { await Task.Run(() => { photo.Name = Path.GetFileNameWithoutExtension(sourceData.AbsolutePath); photo.RelativePath = Path.GetDirectoryName(Path.GetRelativePath(photo.Storage.Folder, sourceData.AbsolutePath)); photo.Files = new List <File> { new() { Name = Path.GetFileName(sourceData.AbsolutePath) } }; IEnumerable <Directory> directories = ImageMetadataReader.ReadMetadata(sourceData.AbsolutePath); var exifIfd0Directory = directories.OfType <ExifIfd0Directory>().FirstOrDefault(); var exifSubIfdDirectory = directories.OfType <ExifSubIfdDirectory>().FirstOrDefault(); var gpsDirectory = directories.OfType <GpsDirectory>().FirstOrDefault(); if (exifSubIfdDirectory != null || exifIfd0Directory != null) { photo.TakenDate = GetTakenDate(new Directory[] { exifIfd0Directory, exifSubIfdDirectory }); } if (exifSubIfdDirectory != null) { photo.Height ??= GetHeight(exifSubIfdDirectory); photo.Width ??= GetWidth(exifSubIfdDirectory); } if (exifIfd0Directory != null) { photo.Orientation ??= GetOrientation(exifIfd0Directory); } if (gpsDirectory != null) { photo.Location = GeoWrapper.GetLocation(gpsDirectory); } }); }
public async Task Enrich(Photo photo, SourceDataDto source) { using (var stream = new MemoryStream()) { using (var image = new MagickImage(source.AbsolutePath)) { image.AutoOrient(); source.OriginalImage = image.Clone(); photo.Height = image.Height; photo.Width = image.Width; photo.Orientation = (int?)image.Orientation; ImageHelper.ResizeImage(image, out var scale); image.Format = MagickFormat.Jpg; await image.WriteAsync(stream); photo.Scale = scale; source.PreviewImage = image.Clone(); } photo.PreviewImage = stream.ToArray(); } }
public async Task Enrich(Photo photo, SourceDataDto source) { source.ImageAnalysis = await _client.AnalyzeImageInStreamAsync(new MemoryStream(photo.PreviewImage), _features); }
public async Task Enrich(Photo photo, SourceDataDto sourceData) { try { var detectedFaces = await _faceService.DetectFacesAsync(photo.PreviewImage); if (!detectedFaces.Any()) { return; } photo.Faces = new List <Face>(); var faceGuids = detectedFaces.Where(IsAbleToIdentify).Select(f => f.FaceId).ToList(); IList <IdentifyResult> identifyResults = new List <IdentifyResult>(); if (faceGuids.Any()) { identifyResults = await _faceService.IdentifyAsync(faceGuids); } foreach (var detectedFace in detectedFaces) { var face = new Face { PhotoId = photo.Id, IdentityStatus = IdentityStatus.NotIdentified, Image = await CreateFacePreview(detectedFace, sourceData.PreviewImage, 1), Rectangle = GeoWrapper.GetRectangle(detectedFace.FaceRectangle, photo.Scale) }; var attributes = detectedFace.FaceAttributes; if (attributes != null) { face.Age = attributes.Age; face.Gender = attributes.Gender == Gender.Male; face.Smile = attributes.Smile; face.FaceAttributes = JsonConvert.SerializeObject(attributes); } var identifyResult = identifyResults.SingleOrDefault(f => f.FaceId == detectedFace.FaceId); if (identifyResult != null) { IdentifyFace(face, identifyResult, photo.TakenDate); } else if (IsAbleToIdentify(detectedFace, photo.Scale)) { face.Image = await CreateFacePreview(detectedFace, sourceData.OriginalImage, photo.Scale); identifyResult = await _faceService.FaceIdentityAsync(face); IdentifyFace(face, identifyResult, photo.TakenDate); } photo.Faces.Add(face); } } catch (Exception e) { Console.WriteLine(e); } }