Ejemplo n.º 1
0
        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
                });
            }
        }
Ejemplo n.º 2
0
        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);
                }
            });
        }
Ejemplo n.º 3
0
        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);
            }
        }