示例#1
0
 public RecognizedEventArgs(RecognitionItem item)
 {
     Item = item;
 }
示例#2
0
        /// <summary>
        ///  Asynchronously process a queue item
        /// </summary>
        public async Task <Person> ProcessRecognitionItem(RecognitionItem item)
        {
            Task <EmotionScores> emotionTask = RecognizeEmotions(item.ImageUrl, item.Face.FaceRectangle);

            #region Process of person
            Person person = item.Person;

            // if the person isn't recognized
            if (item.Person == null)
            {
                // Makes recognition to be sure the person isn't recognized
                var recognitionResults = await RecognizePersonsAsync(new[] { item.Face }, item.ImageUrl);

                if (recognitionResults.Any()) // be sure there is results
                {
                    person = recognitionResults.First().Person;

                    // If after that person is still not recognized, we create it
                    // and add a new visit
                    if (person == null)
                    {
                        person = await CreatePerson(item.Face);

                        _unit.VisitsRepository.AddOrUpdateVisit(person, item.DateOfRecognition);
                    }
                }
            }
            #endregion

            if (person != null)
            {
                #region Process of profilePictures
                ProfilePicture picture = item.ProfilePicture;

                // Creates a profile picture for new person
                if (item.ProfilePicture == null)
                {
                    picture = _unit.ProfilePicturesRepository
                              .CreateProfilePicture(person.PersonApiId, item.ImageUrl, item.Face, item.Confidence);

                    person.Visits.Last().ProfilePictures.Add(picture);
                }

                // Adds picture to oxford, update information and clean temporary folder
                // If an erorr occured during addind face for a new person, stops process and rollback
                if (!await AddFaceToPersonInOxford(person, picture, item.Face, item.ImageUrl))
                {
                    return(null);
                }
                picture.EmotionScores = await emotionTask;

                // Clean temporary image file
                if (item.ImageCounter == 0)
                {
                    File.Delete(MapPath(item.ImageUrl));
                }
                #endregion

                // trains the person group
                await TrainPersonGroupAsync();

                // Creates person is it's new
                if (person.Id == 0)
                {
                    _unit.PersonRepository.Insert(person);
                }

                await _unit.SaveAsync();
            }

            return(person);
        }
示例#3
0
 private void OnNewRecognition(RecognitionItem newItem)
 {
     Model.RecognitionItems.Add(newItem);
 }