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 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}"; } }
/// <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)); }
public async Task InitializeAsync() { try { IsLoading = true; if (FaceService == null) { FaceService = await FaceServiceHelper.CreateNewFaceServiceAsync(); } var personGroupResult = await FaceService.ListPersonGroupsAsync(); personGroupResult.OrderBy(pg => pg.Name); personGroupResult.ForEach(pg => PersonGroups.Add(pg)); IsLoading = false; } catch (FaceAPIException ex)//Handle API-Exception { await MessageDialogHelper.MessageDialogAsync(ex.ErrorMessage); } catch (Exception ex) { await MessageDialogHelper.MessageDialogAsync(ex.Message); } }
private async Task AssignFaceToPersonAsync(Face face) { ContentDialog dialog = new ContentDialog(); dialog.IsPrimaryButtonEnabled = true; dialog.IsSecondaryButtonEnabled = true; dialog.PrimaryButtonText = "Okay"; dialog.SecondaryButtonText = "Cancel"; ListBox listBox = new ListBox(); var personsCombined = new List <Person>(); foreach (var groupItem in PersonGroups) { personsCombined.AddRange(groupItem.Persons); } listBox.ItemsSource = personsCombined; listBox.DisplayMemberPath = "Name"; dialog.Content = listBox; var result = await dialog.ShowAsync(); if (result == ContentDialogResult.Primary) { var person = listBox.SelectedItem as Person; if (person != null) { var groupItem = PersonGroups.First(g => g.Persons.Contains(person)); if (groupItem != null) { await AddPersonFaceAsync(groupItem, person.PersonId, face.FaceId); } } } }
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); } }
public string GetPersonGroupsForQuery() { var personGroups = PersonGroups.Select(f => f.PersonGroup.Name).ToArray(); var strPersonGroups = String.Join("','", personGroups); strPersonGroups = "'" + strPersonGroups + "'"; return(strPersonGroups); }
public async override Task OnInitializedAsync() { await base.OnInitializedAsync().ConfigureAwait(false); PersonGroups = await MakeRequest <List <PersonGroupDto> >(_personGroupListRequest); SelectedPersonGroupId = PersonGroups?.Select(g => g.PersonGroupId).FirstOrDefault(); }
public void DisplayGroups(PersonGroups data, string message) { Console.WriteLine($"\n{message}\n"); int counter = 1; foreach (var item in data.Groups) { DisplayCollection(item, $"Group {counter}"); ++counter; } }
private async void SaveGroupButton_OnClick(object sender, RoutedEventArgs e) { if (SelectedPersonGroupItem != null) { if (_isSaveNew) { await CreatePersonGroupAsync(SelectedPersonGroupItem.Group); PersonGroups.Add((SelectedPersonGroupItem)); _isSaveNew = false; } else { await UpdatePersonGroupAsync(SelectedPersonGroupItem.Group); await LoadPersonGroupsAsync(); } } }
public SearchPersonForm() { InitializeComponent(); mtxtYearin.Focus(); mtxtYearin.SelectAll(); mTextBoxID8.SelectAll(); textBoxID13.SelectAll(); textBoxRunNum.SelectAll(); textBoxName.SelectAll(); textBoxSname.SelectAll(); cbbCompany.SelectAll(); cbbBatt.SelectAll(); setBattCompanyValue(); AddEnterKeyDown(); btnNextPage.Enabled = false; btnPrevPage.Enabled = false; GVsSetAutoSizeColumns(); pgroup = PersonGroups.Prepare; DataControls.LoadComboBoxData(cbbProvince, DataDefinition.GetArmtownTab(), "ARMNAME", "ARMID"); }
/// <summary> /// Identify faces and persons inside a picture /// </summary> /// <param name="testImageFile"></param> /// <param name="onlyDetect"></param> /// <returns></returns> public async Task <FaceMessage> Identify(string testImageFile, bool onlyDetect = true) { //create return message FaceMessage message = new FaceMessage { ID = Guid.NewGuid(), Data = DateTime.Now, File = testImageFile, OnlyDetect = onlyDetect }; LogMessage($"Detecting Face: {testImageFile}"); //try read image for (int i = 0; i < 5; i++) { try { //read image using (Stream s = File.OpenRead(testImageFile)) { //detec faces message.DetectedFaces.AddRange( await faceClient.Face.DetectWithStreamAsync( s, true, false, FaceAttributes)); } } catch (Exception) { //probably lock problem with the image, so wait some time Thread.Sleep(100); } finally { //quit the loop i = 10; } } //Only detect faces if (onlyDetect || message.DetectedFaces.Count == 0) { return(message); } //get face id var faceIds = message.DetectedFaces.Select(face => (Guid)(face.FaceId ?? Guid.Empty)); //Get interest groups if (PersonGroups.Count == 0) { PersonGroups.AddRange(await faceClient.PersonGroup.ListAsync()); } //get id as list var ids = faceIds.ToList(); //look at groups foreach (var personGroup in PersonGroups) { try { LogMessage($"Group: {personGroup.Name}"); //look person groups message.IdentifyResults.AddRange(await faceClient.Face.IdentifyAsync(ids, personGroup.PersonGroupId)); //Lok identify results foreach (var identifyResult in message.IdentifyResults) { LogMessage($" Face: {identifyResult.FaceId}"); //look candidates foreach (var candidate in identifyResult.Candidates) { LogMessage($" Candidate({candidate.Confidence}): {candidate.PersonId}"); //try find person var person = await faceClient.PersonGroupPerson.GetAsync(personGroup.PersonGroupId, candidate.PersonId); //dont exist if (person == null) { continue; } //create person inside group return message.CandidateGroups.Add(new CandidateGroup { FaceID = identifyResult.FaceId, PersonGroupId = personGroup.PersonGroupId, PersonGroupName = personGroup.Name, PersonId = person.PersonId, PersonName = person.Name }); LogMessage($" Person: {person.Name} ({personGroup.Name})"); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } } return(message); }
public InMemoryUser(User dbUser, IEnumerable <UserProfile> initializedProfiles, int?timezoneOffset) { DBUser = dbUser; _login = dbUser.UserName; SiteId = dbUser.SiteId; _firstName = dbUser.FirstName; _lastName = dbUser.LastName; _email = dbUser.Email; _orgId = dbUser.OrgId; _department = dbUser.Department; _phone = dbUser.Phone; _language = dbUser.Language; _dbId = dbUser.Id; _timezoneOffset = timezoneOffset; _maximoPersonId = dbUser.MaximoPersonId; _personGroups = (dbUser.PersonGroups ?? new HashedSet <PersonGroupAssociation>()); if (initializedProfiles == null) { initializedProfiles = new List <UserProfile>(); } var userProfiles = initializedProfiles as UserProfile[] ?? initializedProfiles.ToArray(); _profiles = userProfiles; var roles = new List <Role>(); var dataConstraints = new List <DataConstraint>(); foreach (var profile in userProfiles) { roles.AddRange(profile.Roles); dataConstraints.AddRange(profile.DataConstraints); } if (dbUser.CustomRoles != null) { foreach (var role in dbUser.CustomRoles) { if (role.Exclusion) { roles.Remove(role.Role); } else { roles.Add(role.Role); } } } if (dbUser.PersonGroups != null) { foreach (var personGroup in dbUser.PersonGroups) { PersonGroups.Add(personGroup); } } if (dbUser.CustomConstraints != null) { foreach (var constraint in dbUser.CustomConstraints) { if (constraint.Exclusion) { dataConstraints.Remove(constraint.Constraint); } else { dataConstraints.Add(constraint.Constraint); } } } _roles = roles; _dataConstraints = dataConstraints; Identity = new GenericIdentity(_login); }
/// <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()); }