Beispiel #1
0
        private async void Search_person(object sender, RoutedEventArgs e)
        {
            if (fileDatas != null && PersonName.Text != "")
            {
                const string personGroupId   = "default";
                const string personGroupName = "Default";
                // Group
                try
                {
                    await FaceServiceClient.CreatePersonGroupAsync(
                        personGroupId,
                        personGroupName
                        );
                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                }

                // Person
                string personId = PersonName.Text;
                var    person   = await FaceServiceClient.CreatePersonInPersonGroupAsync(
                    personGroupId,
                    personId
                    );

                // Train person
                foreach (var fileData in fileDatas)
                {
                    await FaceServiceClient.AddPersonFaceInPersonGroupAsync(
                        personGroupId,
                        person.PersonId,
                        await fileData.OpenStreamForReadAsync()
                        );
                }

                await FaceServiceClient.TrainPersonGroupAsync(personGroupId);

                // ReSharper disable once SuspiciousTypeConversion.Global
                while ((await FaceServiceClient.GetPersonGroupTrainingStatusAsync(personGroupId)).Status.Equals("running"))
                {
                    await Task.Delay(1000);
                }


                Frame.Navigate(typeof(SelectTargetPage), personId);
            }
            else
            {
                Validate.Content = "You must Upload a file and write the person's name";
            }
        }
        //Registers new face to API and returns GUID.
        private async Task <Guid> RegisterFace(string guid, FaceServiceClient client)
        {
            CreatePersonResult person = null;

            try
            {
                person = await client.CreatePersonInPersonGroupAsync(_groupId, guid);
            } catch (Exception ex)
            {
                _logger.LogWarning("Failed to register new face.");
                _logger.LogWarning(ex.Message);
            }

            if (person != null)
            {
                return(person.PersonId);
            }
            return(Guid.Empty);
        }