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
                });
            }
        }
Exemple #2
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);
            }
        }