/// <summary> /// Adds the user to group. /// </summary> /// <returns>Person or null.</returns> /// <param name="userName">User name.</param> /// <param name="userData">User data.</param> /// <param name="imageBytes">Image bytes.</param> /// <param name="faceRect">Face rectangle.</param> public Person AddUserToGroup(string userName, string userData, byte[] imageBytes, FaceRectangle faceRect) { // create the user-group if needed if (userGroupId != initedGroupId) { GetOrGreateUserGroup(); } if (userGroupId != initedGroupId) { return(null); } if (faceManager != null) { // add person Person person = faceManager.AddPersonToGroup(userGroupId, userName, userData); if (person != null) { // if(faceRect != null) // { // faceRect.Left -= 10; // faceRect.Top -= 10; // faceRect.Width += 20; // faceRect.Height += 20; // } PersonFace personFace = null; if (imageBytes != null) { personFace = faceManager.AddFaceToPerson(userGroupId, person.personId, string.Empty, faceRect, imageBytes); } if (personFace != null) { person.persistedFaceIds = new string[1]; person.persistedFaceIds[0] = personFace.persistedFaceId; // train the group faceManager.TrainPersonGroup(userGroupId); // wait for training to complete bool isTrained = false; int retries = 0; while (!isTrained && retries++ < 5) { Thread.Sleep(1000); isTrained = faceManager.IsPersonGroupTrained(userGroupId); } } } return(person); } return(null); }