Пример #1
0
        /// <summary>
        /// Asynchronously put a recognition item into queue
        /// </summary>
        public async Task Enqueue(IList <RecognitionItem> recognitionItems)
        {
            // Write work items
            foreach (var recognitionItem in recognitionItems)
            {
                // Gets recognized person
                var person = recognitionItem.Person;

                if (person != null)
                {
                    // add or update visit for person
                    _unit.VisitsRepository.AddOrUpdateVisit(person, recognitionItem.DateOfRecognition);
                    // Create a new profile picture
                    ProfilePicture newPicture = _unit.ProfilePicturesRepository.CreateProfilePicture
                                                    (person.PersonApiId, recognitionItem.ImageUrl, recognitionItem.Face, recognitionItem.Confidence);

                    person.Visits.Last().ProfilePictures.Add(newPicture);

                    // Update person's statistics
                    person.UpdateAge(recognitionItem.Face.FaceAttributes.Age);
                    person.UpdateGender(GenderValuesHelper.Parse(recognitionItem.Face.FaceAttributes.Gender));

                    _unit.PersonRepository.Update(person);

                    // Updates recognition item
                    recognitionItem.ProfilePictureId = newPicture.Id;
                }

                _unit.RecognitionItemsRepository.Insert(recognitionItem);
                await _unit.SaveAsync();
            }
        }
Пример #2
0
        public Entities.Person CreatePerson(Guid personApiId, Face face)
        {
            // Creates a new person entity
            var person = new Entities.Person {
                PersonApiId = personApiId
            };

            person.UpdateAge(face.FaceAttributes.Age);
            person.UpdateGender(GenderValuesHelper.Parse(face.FaceAttributes.Gender));

            // Creates directory to store person's pictures
            Directory.CreateDirectory(MapPath($"{Global.PersonsDatabaseDirectory}{personApiId}"));

            return(person);
        }
Пример #3
0
        // Converts a recognition item entity to person data transfert object
        public static PersonDto ToPersonDto(this RecognitionItem recognitionItem)
        {
            var lastVisit = recognitionItem.Person?.Visits.LastOrDefault();

            var age = recognitionItem.Person != null
                ? DateHelpers.ConvertDateOfBirthToAge(recognitionItem.Person.DateOfBirth)
                : recognitionItem.Face.FaceAttributes.Age;

            var gender = recognitionItem.Person?.Gender ??
                         GenderValuesHelper.Parse(recognitionItem.Face.FaceAttributes.Gender);

            return(new PersonDto
            {
                RecognitionId = recognitionItem.Id,
                FirstName = recognitionItem.Person?.FirstName,
                IsRecognized = recognitionItem.Person != null,
                PersonId = recognitionItem.Person?.PersonApiId ?? default(Guid),
                NbPasses = lastVisit?.NbPasses ?? 0,
                ReasonOfVisit = lastVisit?.Reason,
                Age = (int)age,
                Gender = gender,
            });
        }
Пример #4
0
        public ProfilePicture CreateProfilePicture(Guid personApiId, string imagePath, Face face, double confidence)
        {
            // generates a new path for picture and create a picture with a face box at this location
            string newPath = $"{Global.PersonsDatabaseDirectory}{personApiId}/{Guid.NewGuid()}.jpg";

            ImageHelpers.CreateImageWithRectangleFace(MapPath(imagePath), MapPath(newPath), face.FaceRectangle);

            // Adds a new profile picture for this person
            ProfilePicture newPicture = new ProfilePicture
            {
                Confidence    = confidence,
                Gender        = GenderValuesHelper.Parse(face.FaceAttributes.Gender),
                FaceRectangle = face.FaceRectangle,
                Uri           = newPath,
                Glasses       = face.FaceAttributes.Glasses,
                Moustache     = face.FaceAttributes.FacialHair.Moustache,
                Beard         = face.FaceAttributes.FacialHair.Beard,
                Sideburns     = face.FaceAttributes.FacialHair.Sideburns
            };

            newPicture.Age = face.FaceAttributes.Age;

            return(newPicture);
        }