public async void CreatePersons() { // Create an empty PersonGroup string personGroupId = "myfriends"; //await faceClient.PersonGroup.CreateAsync(personGroupId, "My Friends"); await faceClient.CreatePersonGroupAsync(personGroupId, "My Friends"); //await faceClient.DeletePersonGroupAsync(personGroupId); // Define Anna var dad = await faceClient.CreatePersonAsync(personGroupId, "Dad"); var mom = await faceClient.CreatePersonAsync(personGroupId, "mom"); var girl = await faceClient.CreatePersonAsync(personGroupId, "girl"); //CreatePersonResult friend1 = await faceClient.PersonGroupPerson.CreateAsync( // // Id of the PersonGroup that the person belonged to // personGroupId, // // Name of the person // "Anna" //); // Define Bill and Clare in the same way // Directory contains image files of Anna string dadDir = $@"{urlBaseData}\PersonGroup\Family1-Dad"; string momDir = $@"{urlBaseData}\PersonGroup\Family1-Mom"; string girlDad = $@"{urlBaseData}\PersonGroup\Family1-Daughter"; await AddFaceToPerson(personGroupId, dad, dadDir); await AddFaceToPerson(personGroupId, mom, momDir); await AddFaceToPerson(personGroupId, girl, girlDad); await faceClient.TrainPersonGroupAsync(personGroupId); await WaitForTrainedPersonGroup(personGroupId); string familyPerson = $@"{urlBaseData}\identification1.jpg"; await IdentifyPersons(personGroupId, familyPerson); // Do the same for Bill and Clare }
private async Task CreatePersons(string selectPath) { Console.WriteLine(selectPath); foreach (var dir in Directory.EnumerateDirectories(selectPath)) { Console.WriteLine(dir); Console.WriteLine(Path.GetFileName(dir)); // Define Anna CreatePersonResult friend = await _faceServiceClient.CreatePersonAsync( // Id of the person group that the person belonged to personGroupId, // Name of the person Path.GetFileName(dir) ); Console.WriteLine("CreatePersonAsync--------------------------" + Path.GetFileName(dir)); foreach (var file in Directory.EnumerateFiles(dir, "*.jpg", SearchOption.AllDirectories)) { Console.WriteLine(file); Console.WriteLine(Path.GetFileName(file)); // Directory contains image files of folder using (Stream s = File.OpenRead(file)) { // Detect faces in the image and add to Anna await _faceServiceClient.AddPersonFaceAsync(personGroupId, friend.PersonId, s); Console.WriteLine("AddPersonFaceAsync------------------------------" + file); } } } }
/// <summary> /// Add a new person(profile) to the person group /// </summary> /// <param name="email">Email of the person to be added</param> public async void addPerson(string email, StorageFile sf) { try { // Define Person CreatePersonResult person = await faceServiceClient.CreatePersonAsync(szPersonGroupID, email); string imagePath = sf.Path; Debug.WriteLine(imagePath); await Task.Run(() => { Task.Yield(); stream = File.OpenRead(sf.Path); Debug.WriteLine("File read."); }); await faceServiceClient.AddPersonFaceAsync(szPersonGroupID, person.PersonId, stream); Debug.WriteLine("Face added."); } catch (Exception e) { Debug.WriteLine("ERROR:"); Debug.WriteLine(e.StackTrace); } train(); }
private async Task RegisterNameAsync(string person, string path, string personGroupId) { foreach (string imagePath in Directory.GetFiles(path, "*.jpg")) { // Define person CreatePersonResult friend1 = await faceServiceClient.CreatePersonAsync( // Id of the PersonGroup that the person belonged to personGroupId, // Name of the person person ); using (Stream s = File.OpenRead(imagePath)) { // Detect faces in the image and add to Anna await faceServiceClient.AddPersonFaceAsync( personGroupId, friend1.PersonId, s); } } var em = db.Tables["Employee"].Select("Emp_name like '" + person + "'"); if (em.Count() <= 0) { db.Employee.AddEmployeeRow(person); db.WriteXml(databaseName); } }
/// <summary> /// Asynchronously creates a new person in api and local database. /// Creates also the directory to store pictures of this person /// <see cref="PersonCreationFallBack(Guid?)" /> /// </summary> public async Task <Person> CreatePerson(Face face) { CreatePersonResult apiCreationResult = null; try { // Creates person on oxford api apiCreationResult = await _faceServiceClient.CreatePersonAsync(Global.OxfordPersonGroupId, $"{Guid.NewGuid()}"); return(_unit.PersonRepository.CreatePerson(apiCreationResult.PersonId, face)); } catch (FaceAPIException e) { LogManager.GetLogger(GetType()).Info("Error occured during creation of person on oxford api", e); return(null); } catch (Exception e) { // FallBack: Remove person on oxford to avoid ambiguous person in api database await PersonCreationFallBack(apiCreationResult?.PersonId); LogManager.GetLogger(GetType()).Info("General error occured during creation of person. See exception for more details", e); return(null); } }
/// <summary> /// Create a new PersonGroup, then proceed to send pictures of each listed user, uploading them from given directory /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnCreateGroup_Click(object sender, EventArgs e) { try { _groupId = txtGroupName.Text.ToLower().Replace(" ", ""); try { await faceServiceClient.DeletePersonGroupAsync(_groupId); } catch { } await faceServiceClient.CreatePersonGroupAsync(_groupId, txtGroupName.Text); foreach (var u in listUsers.Items) { CreatePersonResult person = await faceServiceClient.CreatePersonAsync(_groupId, u.ToString()); foreach (string imagePath in Directory.GetFiles(txtImageFolder.Text + "\\" + u.ToString())) { using (Stream s = File.OpenRead(imagePath)) { await faceServiceClient.AddPersonFaceAsync(_groupId, person.PersonId, s); } } await Task.Delay(1000); } MessageBox.Show("Group successfully created"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
/// <summary> /// Create a person into Face API and whitelist /// </summary> /// <param name="personName"></param> /// <param name="personFolder"></param> /// <returns></returns> private async Task <Guid> CreatePerson(string personName, StorageFolder personFolder) { var ret = await _faceApiClient.CreatePersonAsync(WhitelistId, personName); var personId = ret.PersonId; _whitelist.AddPerson(personId, personName, personFolder.Path); return(personId); }
private async void SetupPersonGroup() { const string lilianImageDir = @"Assets\PersonGroup\Lilian\"; try { //if (faceServiceClient.) <-- need to check if it exists first await faceServiceClient.CreatePersonGroupAsync(personGroup, personGroup); } catch (Exception ex) { Debug.WriteLine(ex.Message); return; } // Define Users CreatePersonResult lilian = await faceServiceClient.CreatePersonAsync( personGroup, "Lilian" ); foreach (string imagePath in Directory.GetFiles(lilianImageDir, "*.jpg")) { using (Stream s = File.OpenRead(imagePath)) { // Detect faces in the image and add to Lilian await faceServiceClient.AddPersonFaceAsync( personGroup, lilian.PersonId, s); } } //Train model try { await faceServiceClient.TrainPersonGroupAsync(personGroup); } catch (Exception ex) { Debug.WriteLine(ex.Message); } TrainingStatus trainingStatus = null; while (true) { trainingStatus = await faceServiceClient.GetPersonGroupTrainingStatusAsync(personGroup); if (trainingStatus.Status.ToString() != "running") { break; } await Task.Delay(1000); } }
public async Task <IActionResult> CreateUser([FromBody] PersonDocument doc) { var data = _faceClient.CreatePersonAsync(_personGroupKey, doc.Name); doc.PersonId = data.Result.PersonId; doc.Created = DateTime.Now; doc.Id = ObjectId.GenerateNewId().ToString(); await _db.Persons.InsertOneAsync(doc); return(this.Json(doc)); }
// Add a new user to the users list public async void addNewUser(String newUserName, String imagesFolderPath, String groupId) { CreatePersonResult person = await faceServiceClient.CreatePersonAsync(groupId, newUserName); foreach (string imagePath in Directory.GetFiles(imagesFolderPath)) { using (Stream s = File.OpenRead(imagePath)) { await faceServiceClient.AddPersonFaceAsync(groupId, person.PersonId, s); } } }
public async Task TrainFacialRecognizitionAsync(string personGroupId, string personGroupName, string filePath) { CreatePersonResult person = await faceServiceClient.CreatePersonAsync(personGroupId, personGroupName); foreach (string imagePath in Directory.GetFiles(filePath)) { using (Stream s = System.IO.File.OpenRead(imagePath)) { await faceServiceClient.AddPersonFaceAsync(personGroupId, person.PersonId, s); } } }
/// <summary> /// 사람 추가 /// </summary> /// <param name="personName"></param> /// <returns></returns> public async Task <Guid> CreatePersonAsync(string personName) { var persons = await faceServiceClient.GetPersonsAsync(_personGroupId); if (persons.Any(p => p.Name == personName)) { var per = persons.First(p => p.Name == personName); return(per.PersonId); } var result = await faceServiceClient.CreatePersonAsync(_personGroupId, personName); return(result.PersonId); }
public async Task <List <Stream> > CreatePerson(IEnumerable <Stream> trainingPathPerson, string namePerson) { CreatePersonResult person = await faceClient.CreatePersonAsync(PERSON_GROUP_ID, namePerson); var facesNotDetected = await AddFaceToPerson(PERSON_GROUP_ID, person, trainingPathPerson); await faceClient.TrainPersonGroupAsync(PERSON_GROUP_ID); await WaitForTrainedPersonGroup(PERSON_GROUP_ID); PersonCreateds += 1; return(facesNotDetected); }
public async void TestMethodAsync() { try { await faceServiceClient.CreatePersonGroupAsync(personGroupId, personGroupId); // Define Anna CreatePersonResult friend1 = await faceServiceClient.CreatePersonAsync( // Id of the person group that the person belonged to personGroupId, // Name of the person "Anna Simmons" ); // Directory contains image files of the person string friend1ImageDir = @"D:\Pictures\Anna"; foreach (string imagePath in Directory.GetFiles(friend1ImageDir, "*.jpg")) { using (Stream s = File.OpenRead(imagePath)) { // Detect faces in the image and add to Anna await faceServiceClient.AddPersonFaceAsync( personGroupId, friend1.PersonId, s); } } // Do the same for Bill and Clare await faceServiceClient.TrainPersonGroupAsync(personGroupId); TrainingStatus trainingStatus = null; while (true) { trainingStatus = await faceServiceClient.GetPersonGroupTrainingStatusAsync(personGroupId); if (!(trainingStatus.Status.Equals("running"))) { break; } await Task.Delay(1000); } } catch (Exception e) { } }
private async void BtnLoadToTrainer_Click(object sender, RoutedEventArgs e) { if (groupName == "" || personName == "") { MessageBox.Show("Blank group or person name"); return; } _(String.Format("Creating group {0}...", groupId)); try { await faceServiceClient.CreatePersonGroupAsync(groupId, groupName); } catch (FaceAPIException eCreatePersonGroupAsync) { _(String.Format("{0}", eCreatePersonGroupAsync.ErrorMessage)); } _("Creating person " + personName + "..."); try { CreatePersonResult person = await faceServiceClient.CreatePersonAsync(groupId, personName); foreach (String imagePath in imagePaths) { using (Stream s = File.OpenRead(imagePath)) { try { _(String.Format("Processing {0}...", imagePath)); await faceServiceClient.AddPersonFaceAsync(groupId, person.PersonId, s); } catch (FaceAPIException eAddPersonFaceAsync) { _(eAddPersonFaceAsync.ErrorMessage); } } } _("Done."); } catch (FaceAPIException eCreatePerson) { _(eCreatePerson.ErrorMessage); } }
private async Task <Unit> RegisterPerson() { var person = await client.CreatePersonAsync(group, Name); foreach (var imageData in Images) { using (var imageStream = await imageData.Source.OpenStreamForReadAsync()) { await client.AddPersonFaceAsync(group, person.PersonId, imageStream); } } await client.TrainPersonGroupAsync(group); Name = string.Empty; return(Unit.Default); }
public async void AddPresons(string friend1ImageDi) { try { await faceServiceClient.CreatePersonGroupAsync(personGroupId, "Athmane"); // Define Anna CreatePersonResult friend1 = await faceServiceClient.CreatePersonAsync( // Id of the person group that the person belonged to personGroupId, // Name of the person "Makour" ); const string friend1ImageDir = @"C:\Users\Athmane\Pictures\moi";//@"C:\Users\Athmane\Pictures\test";//"C:\Users\Athmane\Downloads\Cognitive-Face-Windows-master\Cognitive-Face-Windows-master\Data\PersonGroup\Family1-Mom"; foreach (string imagePath in Directory.GetFiles(friend1ImageDir, "*.JPEG")) { using (Stream s = File.OpenRead(imagePath)) { // Detect faces in the image and add to Anna await faceServiceClient.AddPersonFaceAsync( personGroupId, friend1.PersonId, s); } } await faceServiceClient.TrainPersonGroupAsync(personGroupId); TrainingStatus trainingStatus = null; while (true) { trainingStatus = await faceServiceClient.GetPersonGroupTrainingStatusAsync(personGroupId); if (trainingStatus.Status != Status.Running) { break; } await Task.Delay(1000); } } catch (Exception ec) { return; } }
private async void AddToFaceIdList() { string name = imageFolder.DisplayName; var person = await faceServiceClient.CreatePersonAsync(HeroOrVillanPersonGroup.PersonGroupId, name); var imageFiles = await imageFolder.GetFilesAsync(); foreach (var imageFile in imageFiles) { using (var s = await imageFile.OpenReadAsync()) { // Detect faces in the image and add to Anna await faceServiceClient.AddPersonFaceInPersonGroupAsync( HeroOrVillanPersonGroup.PersonGroupId, person.PersonId, imageStream : s.AsStream(), userData : name); } } }
public async Task <IActionResult> Register(string login, [FromBody] byte[] photo, string userName = "") { var user = new { login = login, userName = userName, photo = photo }; // проверить по логину запись в базе данных // если такая запись есть, обломать // ... // ... // ... //если такой записи нет, регистрируем - получаем новый PersonnId try { using (Stream imageFileStream = new MemoryStream(photo)) { //await faceServiceClient.CreatePersonGroupAsync(groupName, groupName); // считаем, что у нас уже зарегистрироавна группа CreatePersonResult person = await faceServiceClient.CreatePersonAsync(groupName, userName); AddPersistedFaceResult faceResult = await faceServiceClient.AddPersonFaceAsync(groupName, person.PersonId, imageFileStream); var result = new { RegisterResult = true, PersonId = person.PersonId }; return(Json(result)); } } catch (Exception ex) { var result = new { RegisterResult = false, Message = "Ошибка при регистрации, возможно такой пользователь уже зарегистрирован", ErrorMessage = ex.Data["ErrorMessage"], }; return(Json(result)); } }
/// <summary> /// Tab 3 Register a person with a bunch of registered face images in section 'Register Person' /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ResigterPersonButton_Click(object sender, RoutedEventArgs e) { int itemNum = Tab3PersonGroupIDComboBox.Items.Count; int selectedGroup = Tab3PersonGroupIDComboBox.SelectedIndex; bool flag1 = string.IsNullOrWhiteSpace(Tab3PersonNameTextBox.Text); bool flag2 = string.IsNullOrWhiteSpace(Tab3DirectoryOfRegisterPersonTextBox.Text); if (itemNum == 0) { MessageBox.Show("Please define the person group ID first in page 2"); } if (flag1) { MessageBox.Show("Please input the person name"); Tab3PersonNameTextBox.Focus(); } if (flag2) { MessageBox.Show("Please select a directory of register voter's images"); } if (selectedGroup == -1) { MessageBox.Show("Please select a group"); } if (itemNum != 0 && !flag1 && !flag2 && selectedGroup != -1) { string personGroupId = Tab3PersonGroupIDComboBox.Text; string personName = Tab3PersonNameTextBox.Text; CreatePersonResult myPerson = await faceServiceClient.CreatePersonAsync(personGroupId, personName); foreach (string imagePath in Directory.GetFiles(Tab3DirectoryOfRegisterPersonTextBox.Text)) { using (Stream s = File.OpenRead(imagePath)) { await faceServiceClient.AddPersonFaceAsync(personGroupId, myPerson.PersonId, s); } } MessageBox.Show("Succeed register person"); } }
public async Task <Guid> CreatePerson(IEnumerable <Stream> trainingPathPerson, string namePerson) { CreatePersonResult person = await faceClient.CreatePersonAsync(Constants.PERSON_GROUP_ID, namePerson); var facesNotDetected = await AddFaceToPerson(Constants.PERSON_GROUP_ID, person, trainingPathPerson); await faceClient.TrainPersonGroupAsync(Constants.PERSON_GROUP_ID); await WaitForTrainedPersonGroup(Constants.PERSON_GROUP_ID); PersonCreateds += 1; People.Add(new Person() { Name = namePerson, PersonId = person.PersonId }); return(person.PersonId); }
private async Task <String> addperson(Stream path, String personId) { try { CreatePersonResult persons = await faceServiceClient.CreatePersonAsync(groupId, personId); var personIds = persons.PersonId; using (path) { var persistedperson = await faceServiceClient.AddPersonFaceAsync(groupId, personIds, path); await faceServiceClient.TrainPersonGroupAsync(groupId); return("Success"); } } catch (Exception e) { return(e.Message); } }
private async void btnCreatePerson_Click(object sender, RoutedEventArgs e) { CreatePersonResult person = await faceServiceClient.CreatePersonAsync( // Id of the person group that the person belonged to txtExisitingPersonGroupID.Text, // Name of the person txtPersonName.Text ); foreach (string imagePath in Directory.GetFiles(txtFolderURL.Text, "*.jpg")) { using (Stream s = File.OpenRead(imagePath)) { // Detect faces in the image and add to the Person await faceServiceClient.AddPersonFaceAsync(txtExisitingPersonGroupID.Text, person.PersonId, s); } } //Call the training method await faceServiceClient.TrainPersonGroupAsync(txtExisitingPersonGroupID.Text); TrainingStatus trainingStatus = null; while (true) { trainingStatus = await faceServiceClient.GetPersonGroupTrainingStatusAsync(txtExisitingPersonGroupID.Text); if (trainingStatus.Status.ToString() != "running") { break; } await Task.Delay(1000); } addToDatabase(txtPersonName.Text, txtPassword.Text, txtExisitingPersonGroupID.Text, person.PersonId.ToString()); txtMessage2.Text = "Person: " + txtPersonName.Text + " was Successfully Created!"; }
public async Task <IActionResult> Register(string key, int faceIndex, string name) { // get the file from Storage var storageObject = _storageService.Get(key) as object[]; var responseModel = storageObject[0] as ResponseModel; var file = storageObject[1] as IFormFile; // create new person CreatePersonResult person = await _faceService.CreatePersonAsync(_personGroupId, name); string filePath = Path.Combine(Directory.GetCurrentDirectory(), "images", key); using (Stream fileStream = new FileStream(filePath, FileMode.Open)) { // register face - person await _faceService.AddPersonFaceAsync(_personGroupId, person.PersonId, fileStream, null, responseModel.Faces[faceIndex].FaceRectangle); } // train the person group await _faceService.TrainPersonGroupAsync(_personGroupId); // wait until training is done TrainingStatus trainingStatus = null; while (true) { trainingStatus = await _faceService.GetPersonGroupTrainingStatusAsync(_personGroupId); if (trainingStatus.Status != Status.Running) { break; } await Task.Delay(1000); } // remove from storage _storageService.Remove(key); return(Ok()); }
private async void CreatePerson_Click(object sender, RoutedEventArgs e) { string name = textBox.Text; Console.WriteLine(name + " " + "added"); // Define Anna CreatePersonResult friend1 = await faceServiceClient.CreatePersonAsync( // Id of the person group that the person belonged to personGroupId, // Name of the person name ); var openDlg = new Microsoft.Win32.OpenFileDialog(); openDlg.Filter = "JPEG Image(*.jpeg)|*.jpeg"; bool?result = openDlg.ShowDialog(this); if (!(bool)result) { return; } string filePath = openDlg.FileName; using (Stream s = File.OpenRead(filePath)) { // Detect faces in the image and add to Anna await faceServiceClient.AddPersonFaceAsync( personGroupId, friend1.PersonId, s); } trainGroup(); }
private async void createPersonAndAddFace() { // Create a person System.Guid personId; try { string userData = Newtonsoft.Json.JsonConvert.SerializeObject( new { Name = this.Name.Text }); Console.Out.WriteLine("User Data is " + userData); CreatePersonResult res = await faceServiceClient.CreatePersonAsync(this.personGroupId, this.Name.Text, userData : userData); Console.Out.WriteLine("Created Peson with Id " + res.PersonId); personId = res.PersonId; } catch (FaceAPIException f) { MessageBox.Show(f.ErrorCode, f.ErrorMessage); return; } this.addFaceAndTrainData(imagePath, personId); }
private async Task <Guid> AddPersonAsync(string personName) { try { Log("Add Person " + personName); CreatePersonResult personResult = await faceServiceClient.CreatePersonAsync(personGroupId, personName); Log("Person added with id " + personResult.PersonId); return(personResult.PersonId); } // Catch and display Face API errors. catch (FaceAPIException f) { Log(f.ErrorMessage); return(Guid.Empty); } // Catch and display all other errors. catch (Exception e) { Log(e.Message); return(Guid.Empty); } }
////통신 //public static void sendImage() //{ // //클라이언트 소켓 생성 // Socket mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); // System.Diagnostics.Debug.WriteLine("소켓생성성공"); // //서버와 연결 // String IP = "192.168.24.233"; // mySocket.Connect(IP, 11111); // System.Diagnostics.Debug.WriteLine("소켓생성성공"); // //파일의 엶 // String name = webCam.GetImageName(); // System.Diagnostics.Debug.WriteLine("파일열기성공"); // FileStream fileStr = new FileStream(name, FileMode.Open, FileAccess.Read); // //파일 크기를 가져옴 // int fileLength = (int)fileStr.Length; // System.Diagnostics.Debug.WriteLine("파일크기 가져오기 성공"); // //파일크기를 서버에 전송하기 위해 바이트 배열로 변환 // byte[] buffer = BitConverter.GetBytes(fileLength); // System.Diagnostics.Debug.WriteLine("변환성공"); // //파일을 보낼 횟수 // int count = fileLength / 1024 + 1; // //파일을 읽기 위해 BinaryRead 객체 생성 // BinaryReader reader = new BinaryReader(fileStr); // System.Diagnostics.Debug.WriteLine("객체 생성성공"); // //파일송신작업 // for(int i=0; i < count; i++) // { // //파일을 읽음 // buffer = reader.ReadBytes(1024); // //읽은 파일을 서버로 전송 // mySocket.Send(buffer); // } // System.Diagnostics.Debug.WriteLine("서버전송성공"); // //종료작업 // reader.Close(); // mySocket.Close(); //} //Define people for the person group and detect,add person private async Task CreatePersonGroup() { System.Diagnostics.Debug.WriteLine("그룹만들기 시작"); //Call the Face API. try { await faceServiceClient.CreatePersonGroupAsync(personGroupId, "Approved_People"); System.Diagnostics.Debug.WriteLine("그룹만들기"); // Define Bill CreatePersonResult friend1 = await faceServiceClient.CreatePersonAsync( //Id of the person group that the person belonged to personGroupId, // Name of the person "Bill"); System.Diagnostics.Debug.WriteLine("Bill 추가"); //Define Clare CreatePersonResult friend2 = await faceServiceClient.CreatePersonAsync( //Id of the person group that the person belonged to personGroupId, //Name of the person "Clare"); System.Diagnostics.Debug.WriteLine("Clare 추가"); //Define 연경 CreatePersonResult friend3 = await faceServiceClient.CreatePersonAsync( //id of the person group that the person belonged to personGroupId, //name of the person "YeonKyeong"); System.Diagnostics.Debug.WriteLine("연경 추가"); foreach (string imagePath in Directory.GetFiles(friend1ImagerDir, "*.jpg")) { using (Stream s = File.OpenRead(imagePath)) { await faceServiceClient.AddPersonFaceAsync( personGroupId, friend1.PersonId, s); } System.Diagnostics.Debug.WriteLine("Bill에 얼굴추가"); }//Bill foreach (string imagePath in Directory.GetFiles(friend2ImagerDir, "*.jpg")) { using (Stream s = File.OpenRead(imagePath)) { await faceServiceClient.AddPersonFaceAsync( personGroupId, friend2.PersonId, s); } System.Diagnostics.Debug.WriteLine("Clare에 얼굴추가"); }//Clare foreach (string imagePath in Directory.GetFiles(friend3ImagerDir, "*.jpg")) { using (Stream s = File.OpenRead(imagePath)) { await faceServiceClient.AddPersonFaceAsync( personGroupId, friend3.PersonId, s); } System.Diagnostics.Debug.WriteLine("연경에 얼굴추가"); }//연경 } //Catch and display Face API errors. catch (FaceAPIException f) { MessageBox.Show(f.ErrorMessage, f.ErrorCode); System.Diagnostics.Debug.WriteLine("그룹만들기 FaceAPIException=" + f); } //Catch and display all other errors. catch (Exception e) { MessageBox.Show(e.Message, "Error"); System.Diagnostics.Debug.WriteLine("그룹만들기 오류 Exception=" + e); } }
private async void button1_Click(object sender, RoutedEventArgs e) { personGroupId = "1"; try { await faceServiceClient.DeletePersonGroupAsync(personGroupId); } catch (Microsoft.ProjectOxford.Face.FaceAPIException exc) { Debug.WriteLine(exc.ErrorCode); } try { await faceServiceClient.CreatePersonGroupAsync(personGroupId, "PG"); } catch (Microsoft.ProjectOxford.Face.FaceAPIException exc) { Debug.WriteLine(exc.ErrorCode); } String[] listOfPersons = { "person1" }; CreatePersonResult[] person = new CreatePersonResult[listOfPersons.Length]; string[] personImageDir = new string[listOfPersons.Length]; for (int i = 0; i < listOfPersons.Length; i++) { person[i] = await faceServiceClient.CreatePersonAsync(personGroupId, listOfPersons[i]); FolderPicker folderPicker = new FolderPicker(); folderPicker.FileTypeFilter.Add(".jpg"); folderPicker.FileTypeFilter.Add(".jpeg"); folderPicker.FileTypeFilter.Add(".png"); folderPicker.FileTypeFilter.Add(".bmp"); folderPicker.ViewMode = PickerViewMode.Thumbnail; StorageFolder photoFolder = await folderPicker.PickSingleFolderAsync(); if (photoFolder == null) { return; } var files = await photoFolder.GetFilesAsync(); foreach (var file in files) { var inputStream = await file.OpenReadAsync(); Stream stream = inputStream.AsStreamForRead(); await faceServiceClient.AddPersonFaceAsync(personGroupId, person[i].PersonId, stream); } } await faceServiceClient.TrainPersonGroupAsync(personGroupId); TrainingStatus trainingStatus = null; while (true) { trainingStatus = await faceServiceClient.GetPersonGroupTrainingStatusAsync(personGroupId); if (!trainingStatus.Status.Equals("running")) { break; } await Task.Delay(1000); } }
public async Task CreatePersonAsync(string name, string description, byte[] imgdata) { var response = await faceServiceClient.CreatePersonAsync(groupId, name, description); await AddFaceAsync(response.PersonId, imgdata); }