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}"; } }
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}"; } }
/// <summary> /// Loads groups and cleanup the ObservableCollection /// </summary> /// <returns></returns> private async Task LoadGroupsAsync() { PersonGroups.Clear(); var fscPersonGroups = await FaceService.ListPersonGroupsAsync(); fscPersonGroups.OrderBy(pg => pg.Name).ForEach(pg => PersonGroups.Add(pg)); }
private async Task LoadPersonGroupsAsync() { if (PersonGroups.Count > 0) { PersonGroups.Clear(); } var groups = await _client.GetPersonGroupsAsync(); foreach (var group in groups) { var groupItem = new PersonGroupItem() { Group = group }; try { var trainingResult = await _client.GetPersonGroupTrainingStatusAsync(group.PersonGroupId); groupItem.LastTrained = trainingResult.EndTime; } catch (ClientException ex) { // hopefully, this means the groupId had no entries for training Debug.WriteLine(ex.Message); } finally { PersonGroups.Add(groupItem); await LoadPersons(groupItem); } } }
/* * public async void Initializev2() * { * InitState = InitStates.InProgress; * try * { * LoadRoamingSettings(); * Windows.Storage.ApplicationData.Current.DataChanged += RoamingDataChanged; * da = new DataAccess(); * * if (localSettings.Values["DbConnString"] != null && localSettings.Values["CardConnString"] != null) * { * DbConnectionString = localSettings.Values["DbConnString"].ToString(); * CardConnString = localSettings.Values["CardConnString"].ToString(); * if (da.TestConnString(DbConnectionString) == true && da.TestConnString(CardConnString) == true) * { * da.StoreConnStrings(DbConnectionString, CardConnString); * op = new Operations(DbConnectionString, CardConnString); * * var selLocation = localSettings.Values["selectedLocation"]; * * if (selLocation != null) * { * string selectedLocation = localSettings.Values["selectedLocation"].ToString(); * * appLocation = await da.GetLocationById(selectedLocation); * if (appLocation != null && appLocation.isDisabled != true) * { * MinHours = await da.GetMinHours(); * * // Gets the default user group for students or trainee * string groupIdString = await da.GetGlobalSetting("DefaultTraineeGroup"); * int.TryParse(groupIdString, out int groupID); * defaultStudentGroup = await da.GetUserGroupById(groupID); * * // Gets the default user gorup for all other users * groupIdString = await da.GetGlobalSetting("DefaultGroup"); * int.TryParse(groupIdString, out groupID); * defaultOtherGroup = await da.GetUserGroupById(groupID); * * InitState = InitStates.Success; * return; * } * } * } * else * { * // Clears the saved connection string as it is invalid. * localSettings.Values["DbConnString"] = null; * localSettings.Values["CardConnString"] = null; * } * } * InitState = InitStates.Completed; * return; * } * catch (Exception) * { * InitState = InitStates.Failed; * } * } */ #endregion public async Task <bool> LoadRegisteredPeople() { try { PersonGroups.Clear(); IEnumerable <PersonGroup> personGroups = await FaceServiceHelper.ListPersonGroupsAsync(this.WorkspaceKey); PersonGroups.AddRange(personGroups.OrderBy(pg => pg.Name)); CurrentPersonGroup = personGroups.FirstOrDefault(); PersonsInCurrentGroup.Clear(); IList <Person> personsInGroup = await FaceServiceHelper.GetPersonsAsync(this.CurrentPersonGroup.PersonGroupId); foreach (Person person in personsInGroup.OrderBy(p => p.Name)) { this.PersonsInCurrentGroup.Add(person); } return(true); } catch (Exception ex) { await Util.GenericApiCallExceptionHandler(ex, "Failure loading Person Groups"); return(false); } }
/// <summary> /// Train model based on directory structure /// </summary> /// <param name="path"></param> public async Task TrainModel(string path) { //Clear the person group PersonGroups.Clear(); //check directory if (!Directory.Exists(path)) { throw new ArgumentException($"Trainer Group path does not exist: {path}"); } LogMessage($"Reading: {path}"); //find groups foreach (var strPersonGroup in Directory.GetDirectories(path)) { //Get group name var personGroupName = GetPathName(strPersonGroup); LogMessage($" Creating Group: {personGroupName}"); //try fing group var personGroup = (await faceClient.PersonGroup.ListAsync()).FirstOrDefault(g => g.Name == personGroupName); var personGroupId = String.Empty; //grouo not exists if (personGroup == null) { //create ID personGroupId = GetPathID(strPersonGroup); //Create person Group await faceClient.PersonGroup.CreateAsync(personGroupId, personGroupName); } else { //asign group id personGroupId = personGroup.PersonGroupId; } //Get Persons foreach (var strPerson in Directory.GetDirectories(strPersonGroup)) { //Get persons name var personName = GetPathName(strPerson); LogMessage($" Creating Person: {personName}"); //try get person Person person = (await faceClient.PersonGroupPerson.ListAsync(personGroupId)).FirstOrDefault(p => p.Name == personName); //create if not exists if (person == null) { person = await faceClient.PersonGroupPerson.CreateAsync(personGroupId, personName); } //max 0f 10 faces if (person.PersistedFaceIds != null && person.PersistedFaceIds.Count > 10) { continue; } //Get Faces foreach (string imagePath in Directory.GetFiles(strPerson, "*.jpg")) { LogMessage($" Creating Face: {imagePath}"); //read face using (Stream s = File.OpenRead(imagePath)) { //add do person await faceClient.PersonGroupPerson.AddFaceFromStreamAsync(personGroupId, person.PersonId, s); } } } LogMessage($" Treaining Group: {personGroupId}"); //train model await faceClient.PersonGroup.TrainAsync(personGroupId); } PersonGroups.Clear(); PersonGroups.AddRange(await faceClient.PersonGroup.ListAsync()); }