Beispiel #1
0
        /// <summary>
        /// Gets the configured person group from the Face API or creates one if it doesn't exist already.
        /// </summary>
        /// <param name="groupId">The ID of the group to create or activate.</param>
        /// <param name="groupName">The name of the group to create or activate.</param>
        /// <param name="groupMembers">The pipe separated list of group members to initialize this group with.</param>
        private async void SetGroup(string groupId, string groupName, string groupMembers)
        {
            // store the group locally from now on
            personGroupId = groupId;

            // get the group from the api service
            var groups = await faceServiceClient.ListPersonGroupsAsync();

            var group = groups.FirstOrDefault(g => g.PersonGroupId.Equals(groupId, StringComparison.CurrentCultureIgnoreCase));

            // when the group isn't null, we're finished
            if (group != null)
            {
                return;
            }

            // but if the group doesn't exist, create the group
            await faceServiceClient.CreatePersonGroupAsync(groupId, groupName);

            // and add the default members if supplied
            if (!string.IsNullOrEmpty(groupMembers))
            {
                foreach (var member in groupMembers.Split('|'))
                {
                    await CreatePerson(member);
                }
            }
        }
Beispiel #2
0
        private async Task LoadGroup()
        {
            try
            {
                // Récupère les groupes
                var groups = await _faceClient.ListPersonGroupsAsync();

                if (!groups.Any())
                {
                    // Première utilisation de l'api
                    await _faceClient.CreatePersonGroupAsync("1", "Miriot");

                    await _faceClient.TrainPersonGroupAsync(_miriotPersonGroupId);
                }
                else
                {
                    // Récupère l'id du premier groupe
                    _miriotPersonGroupId = groups.FirstOrDefault()?.PersonGroupId;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Beispiel #3
0
        private async void FetchPersonGroup_Click(object sender, RoutedEventArgs e)
        {
            personGroupId = "enter your group ID here"
                            personGroupName       = "enter your group name";
            PersonGroupStatusTextBlock.Foreground = new SolidColorBrush(Colors.Black);
            authKey = "enter your azure key";

            await ApiCallAllowed(true);

            faceServiceClient = new FaceServiceClient(authKey);

            if (null != faceServiceClient)
            {
                // You may experience issues with this below call, if you are attempting connection with
                // a service location other than 'West US'
                PersonGroup[] groups = await faceServiceClient.ListPersonGroupsAsync();

                var matchedGroups = groups.Where(p => p.PersonGroupId == personGroupId);

                if (matchedGroups.Count() > 0)
                {
                    knownGroup = matchedGroups.FirstOrDefault();

                    PersonGroupStatusTextBlock.Text = "Joined Group: " + knownGroup.Name; //"Please enter the following details below";// + knownGroup.Name;//"Successfully Joined Social Lens";//
                }

                if (null == knownGroup)
                {
                    PersonGroupStatusTextBlock.Text = "Could not find group. Make sure that you have entered the proper group name ";// + knownGroup.Name;
                }
                PersonGroupStatusTextBlock.Foreground = new SolidColorBrush(Colors.Green);
            }
        }
        private async void GetPersonGroups()
        {
            try
            {
                PersonGroup[] personGroups = await _faceServiceClient.ListPersonGroupsAsync();

                if (personGroups == null || personGroups.Length == 0)
                {
                    StatusText = "No person groups found.";
                    return;
                }

                PersonGroups.Clear();

                foreach (PersonGroup personGroup in personGroups)
                {
                    PersonGroups.Add(personGroup);
                }
            }
            catch (FaceAPIException ex)
            {
                StatusText = $"Failed to fetch person groups: {ex.ErrorMessage}";
            }
            catch (Exception ex)
            {
                StatusText = $"Failed to fetch person groups: {ex.Message}";
            }
        }
        private async Task UpdatePersonGroupList()
        {
            PersonGroup[] personGroups = Array.Empty <PersonGroup>();
            string        cogSrvcKey   = !string.IsNullOrWhiteSpace(txtCognitiveServicesAPIKey.Text) ? txtCognitiveServicesAPIKey.Text.Trim() : !string.IsNullOrWhiteSpace(_options.CSKey) ? _options.CSKey : string.Empty;
            string        cogSrvcEP    = !string.IsNullOrWhiteSpace(txtCognitiveServicesEndpoint.Text) ? txtCognitiveServicesEndpoint.Text.Trim() : !string.IsNullOrWhiteSpace(_options.CSEndpoint) ? _options.CSEndpoint : string.Empty;
            string        faceEndpoint = !string.IsNullOrWhiteSpace(txtCognitiveServicesEndpoint.Text) ? $"{txtCognitiveServicesEndpoint.Text.Trim()}face/v1.0" : !string.IsNullOrWhiteSpace(_options.FaceEndpoint) ? _options.FaceEndpoint : string.Empty;

            if (!string.IsNullOrWhiteSpace(cogSrvcKey) && !string.IsNullOrWhiteSpace(cogSrvcEP))
            {
                try
                {
                    _faceClient  = new FaceServiceClient(cogSrvcKey, faceEndpoint);
                    personGroups = await _faceClient.ListPersonGroupsAsync(cogSrvcKey);
                }
                catch
                {
                }
            }

            if (personGroups.Length > 0)
            {
                cmbPersonGroups.SelectedText = string.Empty;
                cmbPersonGroups.Items.Clear();
                cmbPersonGroups.Items.Add(string.Empty);
                for (int i = 0; i < personGroups.Length; i++)
                {
                    PersonGroup personGroup = personGroups[i];
                    cmbPersonGroups.Items.Add(personGroup.PersonGroupId);
                }
            }
        }
Beispiel #6
0
        public async Task ResetFaceGroups()
        {
            try
            {
                var groups = await Service.ListPersonGroupsAsync();

                foreach (var group in groups)
                {
                    await Service.DeletePersonGroupAsync(group.PersonGroupId);
                }

                await Service.CreatePersonGroupAsync(LoyalCustomerGroup, LoyalCustomerGroup);

                await Service.CreatePersonGroupAsync(AnonymousCustomerGroup, AnonymousCustomerGroup);
            }
            catch (FaceAPIException ex)
            {
                switch (ex.ErrorCode)
                {
                case "BadArgument":
                    break;

                default:
                    break;
                }
                //errorDescription = "IdentifyFace: " + ex.ErrorCode;
                //currentLog.Info(errorDescription);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private async void GetPersonGroups()
        {
            try
            {
                PersonGroup[] personGroups = await _faceServiceClient.ListPersonGroupsAsync();

                if (personGroups == null || personGroups.Length == 0)
                {
                    return;
                }

                PersonGroups.Clear();

                foreach (PersonGroup group in personGroups)
                {
                    PersonGroups.Add(group);
                }
            }
            catch (FaceAPIException ex)
            {
                SystemResponse = $"Failed to get person groups: {ex.ErrorMessage}";
            }
            catch (Exception ex)
            {
                SystemResponse = $"Failed to get person groups: {ex.Message}";
            }
        }
Beispiel #8
0
        /// <summary>
        /// 放入人員群組的資料
        /// </summary>
        public async void BindPersonGroup(System.Windows.Forms.ComboBox cbx, FaceServiceClient face, string strSelectItemValue)
        {
            cbx.Items.Clear();
            PersonGroup[] objGroup = await face.ListPersonGroupsAsync();

            int intChoiceIndex = 0;

            for (int i = 0; i < objGroup.Length; i++)
            {
                Models.CognitiveModels.ListItem item = new Models.CognitiveModels.ListItem()
                {
                    Text  = objGroup[i].Name,
                    Value = objGroup[i].PersonGroupId,
                };

                cbx.Items.Add(item);

                if (strSelectItemValue == item.Value)
                {
                    intChoiceIndex = i;
                }
            }

            if (objGroup.Length > 0)
            {
                cbx.SelectedIndex = intChoiceIndex;
            }
        }
        public static async Task CreatePersonGroupIfNotExistsAsync(string personGroupId, string personGroupName)
        {
            try
            {
                var listOfPersonGroups = await _faceServiceClient.ListPersonGroupsAsync();

                if (listOfPersonGroups.Length == 0)
                {
                    await _faceServiceClient.CreateLargePersonGroupAsync(personGroupId, personGroupName);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("" + e);
                throw;
            }
        }
        public static async Task <(Face[] faces, Person person, Emotion[] emotions)> DetectAndIdentifyFace(Bitmap image)
        {
            FaceServiceClient    fsc = new FaceServiceClient(Settings.Instance.FaceApiKey, FaceApiEndpoint);
            EmotionServiceClient esc = new EmotionServiceClient(Settings.Instance.EmotionApiKey);

            //FACE Detection
            //TODO add detection interval as param
            Emotion[] emotions = null;
            Person    person   = null;

            Face[] faces = null;


            //Detect and identify only once per 10 seconds
            if (lastFaceDetectTime.AddSeconds(10) < DateTime.Now)
            {
                lastFaceDetectTime = DateTime.Now;

                MemoryStream memoryStream = new MemoryStream();
                image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);

                //We need to seek to begin
                memoryStream.Seek(0, SeekOrigin.Begin);
                faces = await fsc.DetectAsync(memoryStream, true, true, new List <FaceAttributeType>() { FaceAttributeType.Age, FaceAttributeType.Gender });

                if (faces.Any())
                {
                    var rec = new Microsoft.ProjectOxford.Common.Rectangle[] { faces.First().FaceRectangle.ToRectangle() };
                    //Emotions

                    //We need to seek to begin, due to problems with parallel access we needed to create new memory stream
                    memoryStream = new MemoryStream();
                    image.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                    memoryStream.Seek(0, SeekOrigin.Begin);

                    //We call Emotion API and we include face rectangle information,
                    //as this way the call is cheaper, as emotion api does not have to run face detection
                    emotions = await esc.RecognizeAsync(memoryStream, rec);


                    //Person Identification
                    var groups = await fsc.ListPersonGroupsAsync();

                    var groupId = groups.First().PersonGroupId;

                    //We are interested only in first candidate
                    var identifyResult = await fsc.IdentifyAsync(groupId, new Guid[] { faces.First().FaceId }, 1);

                    var candidate = identifyResult?.FirstOrDefault()?.Candidates?.FirstOrDefault();

                    if (candidate != null)
                    {
                        person = await fsc.GetPersonAsync(groupId, candidate.PersonId);
                    }
                }
            }
            return(faces, person, emotions);
        }
Beispiel #11
0
        /// <summary>
        /// Create a person group with ID and name provided if none can be found in the service.
        /// </summary>
        private async void CreatePersonGroupButton_ClickAsync(object sender, RoutedEventArgs e)
        {
            personGroupId   = PersonGroupIdTextBox.Text;
            personGroupName = PersonGroupNameTextBox.Text;
            PersonGroupStatusTextBlock.Foreground = new SolidColorBrush(Colors.Black);
            authKey = AuthKeyTextBox.Text;

            if (string.IsNullOrWhiteSpace(personGroupId) == false && string.IsNullOrWhiteSpace(personGroupName) == false && string.IsNullOrWhiteSpace(authKey) == false)
            {
                PersonGroupCreateErrorText.Visibility = Visibility.Collapsed;
                await ApiCallAllowed(true);

                faceServiceClient = new FaceServiceClient(authKey);

                if (null != faceServiceClient)
                {
                    // You may experience issues with this below call, if you are attempting connection with
                    // a service location other than 'West US'
                    PersonGroup[] groups = await faceServiceClient.ListPersonGroupsAsync();

                    var matchedGroups = groups.Where(p => p.PersonGroupId == personGroupId);

                    if (matchedGroups.Count() > 0)
                    {
                        knownGroup = matchedGroups.FirstOrDefault();

                        PersonGroupStatusTextBlock.Text = "Found existing: " + knownGroup.Name;
                    }

                    if (null == knownGroup)
                    {
                        await ApiCallAllowed(true);

                        await faceServiceClient.CreatePersonGroupAsync(personGroupId, personGroupName);

                        knownGroup = await faceServiceClient.GetPersonGroupAsync(personGroupId);

                        PersonGroupStatusTextBlock.Text = "Created new group: " + knownGroup.Name;
                    }

                    if (PersonGroupStatusTextBlock.Text != "- Person Group status -")
                    {
                        PersonGroupStatusTextBlock.Foreground = new SolidColorBrush(Colors.Green);
                    }
                    else
                    {
                        PersonGroupStatusTextBlock.Foreground = new SolidColorBrush(Colors.Red);
                    }
                }
            }
            else
            {
                PersonGroupCreateErrorText.Text       = "Make sure you provide: a Person Group ID, a Person Group Name, and the Authentication Key in the section above.";
                PersonGroupCreateErrorText.Visibility = Visibility.Visible;
            }
        }
Beispiel #12
0
        public static async Task <PersonGroup[]> GetPersonGroups(string CSKey, FaceServiceClient FaceClient)
        {
            PersonGroup[] personGroups = null;
            if (!string.IsNullOrWhiteSpace(CSKey))
            {
                personGroups = await FaceClient.ListPersonGroupsAsync(CSKey);
            }

            return(personGroups);
        }
Beispiel #13
0
        private async Task InitializeFaceServiceAsync(FaceServiceClient faceService)
        {
            try
            {
                var personGroups = await faceService.ListPersonGroupsAsync();

                identifyPersonGroupId = (personGroups.FirstOrDefault(p => p.Name.ContainsIgnoreCase("See4Me") || p.UserData.ContainsIgnoreCase("See4Me") || p.Name.ContainsIgnoreCase("_default") || p.UserData.ContainsIgnoreCase("_default")) ?? personGroups.FirstOrDefault())?.PersonGroupId;
            }
            catch { }
            finally
            {
                faceServiceInitialized = true;
            }
        }
Beispiel #14
0
        public static async Task UpdatePersonGroupList(string CSKey, string FaceEndpoint, FaceServiceClient FaceClient)
        {
            PersonGroup[] personGroups = Array.Empty <PersonGroup>();
            personGroups = await FaceClient.ListPersonGroupsAsync(CSKey);

            _frmOptions.cmbPersonGroups.SelectedText = string.Empty;
            _frmOptions.cmbPersonGroups.Items.Clear();
            _frmOptions.cmbPersonGroups.Items.Add(string.Empty);
            for (int i = 0; i < personGroups.Length; i++)
            {
                PersonGroup personGroup = personGroups[i];
                _frmOptions.cmbPersonGroups.Items.Add(personGroup.PersonGroupId);
            }
            _frmOptions.cmbPersonGroups.Refresh();
        }
Beispiel #15
0
        /// <summary>
        /// 放入人員群組的動作
        /// </summary>
        private async void BindPersonGroups()
        {
            lbxPersonGroup.Items.Clear();

            PersonGroup[] objPersonGroups = await face.ListPersonGroupsAsync();

            for (int i = 0; i < objPersonGroups.Length; i++)
            {
                lbxPersonGroup.Items.Add(
                    new Models.CognitiveModels.ListItem()
                {
                    Text  = objPersonGroups[i].Name,
                    Value = objPersonGroups[i].PersonGroupId,
                });
            }
        }
Beispiel #16
0
        /// <summary>
        /// Creates the default PersonGroup
        /// </summary>
        /// <returns></returns>
        public async Task CreateGroupIfNotExists()
        {
            try
            {
                var groups = await _faceApiClient.ListPersonGroupsAsync();

                if (!groups.Any(g => g.PersonGroupId == MAGIC_MIRROR_GROUP))
                {
                    await _faceApiClient.CreatePersonGroupAsync(MAGIC_MIRROR_GROUP, MAGIC_MIRROR_GROUP);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                // TODO: logging
            }
        }
Beispiel #17
0
        private async static void ViewPersonGroup()
        {
            var personGroups = await _faceServiceClient.ListPersonGroupsAsync();

            if (!personGroups.Any())
            {
                Console.WriteLine("No existing Person Groups available yet");
                return;
            }

            foreach (var personGroup in personGroups)
            {
                Console.WriteLine($"PersonGroupId: {personGroup.PersonGroupId}");
                Console.WriteLine($"Name: {personGroup.Name}");
                Console.WriteLine("===================================");
            }
        }
Beispiel #18
0
        static async void ListPersonGroup(FaceServiceClient faceCli)
        {
            // Lock input
            inputMode = false;
            Console.WriteLine("");
            Console.WriteLine("Getting Person Group:");
            var groups = await faceCli.ListPersonGroupsAsync();

            foreach (var group in groups)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Group Id: " + group.PersonGroupId);
                Console.ForegroundColor = ConsoleColor.Gray;
            }
            paintMenu();
            // release input
            inputMode = true;
        }
Beispiel #19
0
        private async void btntrain_Click(object sender, RoutedEventArgs e)
        {
            // Create an empty person group
            string persongrpid = "smartapp";

            PersonGroup[] persons = await fClient.ListPersonGroupsAsync();

            bool found = false;

            foreach (PersonGroup person in persons)
            {
                if (person.Name == "smart app")
                {
                    found = true;
                }
            }
            if (!found)
            {
                await fClient.CreatePersonGroupAsync(persongrpid, "smart app");
            }
            // Define myself
            // Id of the person group that the person belonged to
            CreatePersonResult friend1 = await fClient.CreatePersonAsync(persongrpid, txtname.Text);

            await fClient.AddPersonFaceAsync(persongrpid, friend1.PersonId, st);

            await fClient.TrainPersonGroupAsync(persongrpid);

            TrainingStatus trainstat = null;

            while (true)
            {
                trainstat = await fClient.GetPersonGroupTrainingStatusAsync(persongrpid);

                if (trainstat.Status.ToString() != "running")
                {
                    break;
                }
            }
            MainPage.floor = txtfloor.Text;
            var dialog = new MessageDialog("training done");
            await dialog.ShowAsync();
        }
Beispiel #20
0
        private async Task <string> GetPersonGroupId()
        {
            if (string.IsNullOrEmpty(_personGroupId))
            {
                var groups = await _client.ListPersonGroupsAsync(top : 1);

                if (groups.Any())
                {
                    _personGroupId = groups.First().PersonGroupId;
                }
                else
                {
                    _personGroupId = Guid.NewGuid().ToString();
                    await _client.CreatePersonGroupAsync(_personGroupId, _personGroupId);
                }
            }

            return(_personGroupId);
        }
        /// <summary>
        /// Create a person group with ID and name provided if none can be found in the service.
        /// </summary>
        private async void CreatePersonGroupButton_ClickAsync(object sender, RoutedEventArgs e)
        {
            personGroupId   = PersonGroupIdTextBox.Text;
            personGroupName = PersonGroupNameTextBox.Text;
            PersonGroupStatusTextBlock.Foreground = new SolidColorBrush(Colors.Black);
            authKey           = AuthKeyTextBox.Text;
            faceServiceClient = new FaceServiceClient(authKey);

            if (null != faceServiceClient)
            {
                // You may experience issues with this below call, if you are attempting connection with
                // a service location other than 'West US'
                PersonGroup[] groups = await faceServiceClient.ListPersonGroupsAsync();

                var matchedGroups = groups.Where(p => p.PersonGroupId == personGroupId);

                if (matchedGroups.Count() > 0)
                {
                    knownGroup = matchedGroups.FirstOrDefault();

                    PersonGroupStatusTextBlock.Text = "Found existing: " + knownGroup.Name;
                }

                if (null == knownGroup)
                {
                    await faceServiceClient.CreatePersonGroupAsync(personGroupId, personGroupName);

                    knownGroup = await faceServiceClient.GetPersonGroupAsync(personGroupId);

                    PersonGroupStatusTextBlock.Text = "Created new group: " + knownGroup.Name;
                }

                if (PersonGroupStatusTextBlock.Text != "- Person Group status -")
                {
                    PersonGroupStatusTextBlock.Foreground = new SolidColorBrush(Colors.Green);
                }
                else
                {
                    PersonGroupStatusTextBlock.Foreground = new SolidColorBrush(Colors.Red);
                }
            }
        }
Beispiel #22
0
        private async void FetchPersonGroup_Click(object sender, RoutedEventArgs e)
        {
            personGroupId   = PersonGroupIdTextBox.Text;
            personGroupName = PersonGroupNameTextBox.Text;
            PersonGroupStatusTextBlock.Foreground = new SolidColorBrush(Colors.Black);
            authKey = AuthKeyTextBox.Text;

            await ApiCallAllowed(true);

            faceServiceClient = new FaceServiceClient(authKey);

            if (null != faceServiceClient)
            {
                // You may experience issues with this below call, if you are attempting connection with
                // a service location other than 'West US'
                PersonGroup[] groups = await faceServiceClient.ListPersonGroupsAsync();

                var matchedGroups = groups.Where(p => p.PersonGroupId == personGroupId);

                if (matchedGroups.Count() > 0)
                {
                    knownGroup = matchedGroups.FirstOrDefault();

                    PersonGroupStatusTextBlock.Text = "Found existing: " + knownGroup.Name;
                }

                if (null == knownGroup)
                {
                    PersonGroupStatusTextBlock.Text = "Could not find group: " + knownGroup.Name;
                }

                if (PersonGroupStatusTextBlock.Text.ToLower().Contains("found"))
                {
                    PersonGroupStatusTextBlock.Foreground = new SolidColorBrush(Colors.Green);
                }
                else
                {
                    PersonGroupStatusTextBlock.Foreground = new SolidColorBrush(Colors.Red);
                }
            }
        }
Beispiel #23
0
        public async Task TrainAll()
        {
            var personGroups = await _faceServiceClient.ListPersonGroupsAsync();

            foreach (var pg in personGroups)
            {
                await _faceServiceClient.TrainPersonGroupAsync(pg.PersonGroupId);

                TrainingStatus trainingStatus = null;
                while (true)
                {
                    trainingStatus = await _faceServiceClient.GetPersonGroupTrainingStatusAsync(pg.PersonGroupId);

                    if (trainingStatus.Status.ToString() != "running")
                    {
                        break;
                    }
                    await Task.Delay(1000);
                }
            }
        }
Beispiel #24
0
        static async void DeletePersonGroup(FaceServiceClient faceCli)
        {
            inputMode = false;

            var groups = await faceCli.ListPersonGroupsAsync();



            foreach (var group in groups)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Group Id: " + group.PersonGroupId);
                Console.ForegroundColor = ConsoleColor.Gray;
            }


            Console.WriteLine("");
            Console.WriteLine("Enter the name of person you wish to delete: ");
            string personGroupId = Console.ReadLine();

            try
            {
                await faceCli.DeletePersonGroupAsync(personGroupId);

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Group : " + personGroupId + " successfully deleted");
                Console.ForegroundColor = ConsoleColor.Gray;
                inputMode = true;
                paintMenu();
            }
            catch (FaceAPIException ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.ErrorMessage);
                Console.ForegroundColor = ConsoleColor.Gray;
                inputMode = true;
                paintMenu();
            }
        }
Beispiel #25
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("Into Page_Loaded");

            // Init Face Service Client
            faceServiceClient = new FaceServiceClient(AppConstants.FaceApiSubscriptionKey,
                                                      AppConstants.FaceServicesBaseUrl);

            // Clean-up possible PersonGroup objects (including persons attached to them)
            try
            {
                var pgList = await faceServiceClient.ListPersonGroupsAsync();

                foreach (var pg in pgList)
                {
                    await faceServiceClient.DeletePersonGroupAsync(pg.PersonGroupId);
                }

                // Init PersonGroup
                Debug.WriteLine($"Initializing Person Group: {PersonGroup}");

                await faceServiceClient.CreatePersonGroupAsync(PersonGroup, PersonGroup);

                BtnInitCam.IsEnabled = true;
            }
            catch (FaceAPIException ex)
            {
                Debug.WriteLine($"Error deleting old PersonGroup objects: {ex.ErrorMessage}");
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Exception in Page_Loaded: {ex.Message}");
            }

            Debug.WriteLine("Out of: Page_Loaded");
        }
Beispiel #26
0
 public async Task <PersonGroup[]> GetListOfPersonGroups()
 {
     return(await FaceServiceClient.ListPersonGroupsAsync());
 }
Beispiel #27
0
 public async Task <PersonGroup[]> GetPersonGroups()
 {
     return(await faceClient.ListPersonGroupsAsync());
 }
Beispiel #28
0
        static async Task SetupFaceVerification(string personGroupId)
        {
            try
            {
                bool groupExists  = false;
                var  personGroups = await _faceServiceClient.ListPersonGroupsAsync();

                foreach (PersonGroup personGroup in personGroups)
                {
                    if (personGroup.PersonGroupId == personGroupId)
                    {
                        groupExists = true;
                    }
                }
                if (!groupExists)
                {
                    await _faceServiceClient.CreatePersonGroupAsync(personGroupId, "All Employees");

                    _dadId = await CreatePerson(personGroupId, "John");

                    _momId = await CreatePerson(personGroupId, "Samantha");

                    _daughterId = await CreatePerson(personGroupId, "Natasha");

                    string imageDir = @"C:\Dev\GitHub\Cognitive-Face-Windows\Data\PersonGroup\Family1-Dad\";
                    await DetectFacesAndAddtoPerson(imageDir, personGroupId, _dadId);

                    imageDir = @"C:\Dev\GitHub\Cognitive-Face-Windows\Data\PersonGroup\Family1-Mom\";
                    await DetectFacesAndAddtoPerson(imageDir, personGroupId, _momId);

                    imageDir = @"C:\Dev\GitHub\Cognitive-Face-Windows\Data\PersonGroup\Family1-Daughter\";
                    await DetectFacesAndAddtoPerson(imageDir, personGroupId, _daughterId);

                    await _faceServiceClient.TrainPersonGroupAsync(personGroupId);

                    while (true)
                    {
                        TrainingStatus trainingStatus = null;
                        try
                        {
                            trainingStatus = await _faceServiceClient.GetPersonGroupTrainingStatusAsync(personGroupId);

                            Console.WriteLine("...Train status: CreatedDateTime: " + trainingStatus.CreatedDateTime + ", Status:" + trainingStatus.Status);

                            if (trainingStatus.Status != Status.Running)
                            {
                                break;
                            }

                            await Task.Delay(1000);
                        }
                        catch (FaceAPIException ex)
                        {
                            Console.WriteLine(ex.ErrorCode);
                            Console.WriteLine(ex.ErrorMessage);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("That PersonGroup already exists, skipping setup...");
                }
            }
            catch (FaceAPIException oops)
            {
                Console.WriteLine(oops.ErrorCode);
                Console.WriteLine(oops.ErrorMessage);

                // Since it's just a poc...
                throw;
            }
        }
Beispiel #29
0
 public async Task <IEnumerable <PersonGroup> > GetPersonGroupsAsync(string userDataFilter = null)
 {
     return((await RunTaskWithAutoRetryOnQuotaLimitExceededError <PersonGroup[]>(() => faceClient.ListPersonGroupsAsync())).Where(group => string.IsNullOrEmpty(userDataFilter) || string.Equals(group.UserData, userDataFilter)));
 }
        /// <summary>
        /// Check if Person Group exists and retrieve that Person Group object to work with.
        /// </summary>
        /// <param name="sender">A sender object</param>
        /// <param name="e">RoutedEventArgs</param>
        /// <remarks>
        /// <para>Can't work with Persons until Person Group has been fetched.</para>
        /// </remarks>
        private async void FetchPersonGroup_Click(object sender, RoutedEventArgs e)
        {
            //Clear Globals
            authKey         = AuthKeyTextBox.Text;
            personGroupId   = PersonGroupIdTextBox.Text;
            personGroupName = PersonGroupNameTextBox.Text;

            //Reset UI Globals
            PersonStatusTextBlock.Text         = "";
            UpdateUserDataStatusTextBlock.Text = "";
            SubmissionStatusTextBlock.Text     = "";
            TrainStatusTextBlock.Text          = "";

            //Reset UI Colors
            PersonStatusTextBlock.Foreground         = new SolidColorBrush(Colors.Black);
            UpdateUserDataStatusTextBlock.Foreground = new SolidColorBrush(Colors.Black);
            SubmissionStatusTextBlock.Foreground     = new SolidColorBrush(Colors.Black);
            TrainStatusTextBlock.Foreground          = new SolidColorBrush(Colors.Black);
            PersonGroupStatusTextBlock.Foreground    = new SolidColorBrush(Colors.Black);

            //Prep API Call
            await ApiCallAllowed(true);

            faceServiceClient = new FaceServiceClient(authKey);

            //Logic
            if (null != faceServiceClient && authKey != "")
            {
                try
                {
                    // You may experience issues with this below call, if you are attempting connection with
                    // a service location other than 'West US'
                    PersonGroup[] groups = await faceServiceClient.ListPersonGroupsAsync();

                    var matchedGroups = groups.Where(p => p.PersonGroupId == personGroupId);

                    if (matchedGroups.Count() > 0)
                    {
                        knownGroup = matchedGroups.FirstOrDefault();

                        PersonGroupStatusTextBlock.Text = "Found existing: " + knownGroup.Name;

                        AddPersonButtons(knownGroup);
                    }

                    if (null == knownGroup)
                    {
                        PersonGroupStatusTextBlock.Text = "Could not find group: " + personGroupId;
                    }

                    if (PersonGroupStatusTextBlock.Text.ToLower().Contains("found"))
                    {
                        PersonGroupStatusTextBlock.Foreground = new SolidColorBrush(Colors.Green);
                    }
                    else
                    {
                        PersonGroupStatusTextBlock.Foreground = new SolidColorBrush(Colors.Red);
                    }
                }
                catch (Exception ex)
                {
                    PersonGroupStatusTextBlock.Text       = "Verify that your Group ID and API Key are correct.";
                    PersonGroupStatusTextBlock.Foreground = new SolidColorBrush(Colors.Red);
                    Debug.WriteLine(ex.ToString());
                }
            }
            else
            {
                PersonGroupStatusTextBlock.Text       = "Verify that your Group ID and API Key are correct.";
                PersonGroupStatusTextBlock.Foreground = new SolidColorBrush(Colors.Red);
            }
        }