コード例 #1
0
        // Create a new PersonGroup in which new users will be added
        public async void createNewGroup(String groupId, String groupName)
        {
            await faceServiceClient.DeletePersonGroupAsync(groupId);


            await faceServiceClient.CreatePersonGroupAsync(groupId, groupName);
        }
コード例 #2
0
ファイル: Model.cs プロジェクト: tung1404/ai_newlife
        private async Task DeleteExistPersonGroup()
        {
            bool groupExists = false;

            // Test whether the group already exists
            try
            {
                Console.WriteLine("Request: Group {0} will be used for build person database. Checking whether group exists.", personGroupId);
                await _faceServiceClient.GetPersonGroupAsync(personGroupId);

                groupExists = true;
                Console.WriteLine("Response: Group {0} exists.", personGroupId);
            }
            catch (FaceAPIException ex)
            {
                if (ex.ErrorCode != "PersonGroupNotFound")
                {
                    Console.WriteLine("Response: {0}. {1}", ex.ErrorCode, ex.ErrorMessage);
                    return;
                }
                else
                {
                    Console.WriteLine("Response: Group {0} does not exist before.", personGroupId);
                }
            }
            if (groupExists)
            {
                await _faceServiceClient.DeletePersonGroupAsync(personGroupId);
            }
        }
        /// <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());
            }
        }
コード例 #4
0
        public async Task <bool> CreateGroupAsync()
        {
            try
            {
                var groups = await faceClient.ListPersonGroupsAsync();

                if (groups.Any(e => e.PersonGroupId == Constants.PERSON_GROUP_ID))
                {
                    await faceClient.DeletePersonGroupAsync(Constants.PERSON_GROUP_ID);
                }

                await faceClient.CreatePersonGroupAsync(Constants.PERSON_GROUP_ID, Constants.PERSON_GROUP_ID);

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
コード例 #5
0
 private void BtnDeleteGroup_Click(object sender, RoutedEventArgs e)
 {
     _("Deleting " + groupId);
     try
     {
         faceServiceClient.DeletePersonGroupAsync(groupId);
         _(groupId + " deleted.");
     }catch (FaceAPIException ex)
     {
         _(ex.ErrorMessage);
     }
 }
コード例 #6
0
 private async void DeleteGroupAsync(String g)
 {
     try
     {
         _("Deleting from Cloud service...");
         await faceServiceClient.DeletePersonGroupAsync(g);
     }catch (FaceAPIException e)
     {
         _(e.Message);
     }
     _("Done.");
 }
コード例 #7
0
        private async void deletePersonGroupButton_Click(object sender, EventArgs e)
        {
            PersonGroup selectedPersonGroup = personGroups[personGroupSelector.SelectedIndex];
            await faceServiceClient.DeletePersonGroupAsync(selectedPersonGroup.PersonGroupId);

            personGroups = await GetPersonGroups();

            personGroupSelector.Items.Clear();
            foreach (PersonGroup personGroup in personGroups)
            {
                personGroupSelector.Items.Add(personGroup.Name);
            }
            personGroupSelector.SelectedIndex = 0;
            personGroupSelector.Text          = "";
            deletePersonGroupButton.Enabled   = false;
            deletePersonButton.Enabled        = false;
            personSelector.SelectedIndex      = -1;
            personSelector.Text = "";
        }
コード例 #8
0
        /// <summary>
        /// Delete the person group
        /// </summary>
        public async void delete()
        {
            await faceServiceClient.DeletePersonGroupAsync(szPersonGroupID);

            Debug.WriteLine("Person group deleted: " + szPersonGroupID);
        }
コード例 #9
0
 /// <summary>
 /// 刪除人員群組
 /// </summary>
 public async void DeletePersonGroup()
 {
     await faceServiceClient.DeletePersonGroupAsync(personGroupId);
 }
コード例 #10
0
        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);
            }
        }
コード例 #11
0
        private async void deletion_Click(object sender, RoutedEventArgs e)
        {
            await faceServiceClient.DeletePersonGroupAsync(personGroupId);

            Console.WriteLine("Group deleted");
        }
コード例 #12
0
 public Task DeletePersonGroupAsync(string personGroupId)
 {
     return(innerClient.DeletePersonGroupAsync(personGroupId));
 }
コード例 #13
0
        private async Task <bool> add_person_async(string person_group_id)
        {
            try {
                // Check if group already exist
                // If yes => delete
                PersonGroup[] person_groups = await face_service_client.ListPersonGroupsAsync();

                foreach (PersonGroup pg in person_groups)
                {
                    if (pg.PersonGroupId == person_group_id)
                    {
                        await face_service_client.DeletePersonGroupAsync(person_group_id);
                    }
                }

                // Create group
                await face_service_client.CreatePersonGroupAsync(person_group_id, person_group_id);

                // Get all directory in "person dir"
                foreach (string person_name_dir_path in preson.get_all_person_dir())
                {
                    // Get only last directory
                    string dir_person_name = person_name_dir_path.Split(Path.DirectorySeparatorChar).Last();//.Replace("_","");

                    //Create person with current groupe
                    CreatePersonResult cpr = await face_service_client.CreatePersonAsync(person_group_id, dir_person_name);

                    // TODO Add "*.id" file
                    //add_person_id_file(person_name_dir_path, cpr.PersonId.ToString());

                    // Get all photos
                    foreach (string person_photo in Directory.EnumerateFiles(person_name_dir_path, "*.*", SearchOption.AllDirectories).Where(n => Path.GetExtension(n) != ".id").ToList())
                    {
                        if (File.Exists(person_photo))
                        {
                            Debug.WriteLine($"Add person photo: {person_photo}"); //TODO

                            // PROGRESS
                            update_progress("Add person", $"Process person: {dir_person_name.Split('_')[0]}", ++progress);
                            using (Stream stream = File.OpenRead(person_photo)) {
                                // If the person photo containe no face => throw error
                                try {
                                    // Detect faces in the image and add to Anna
                                    await face_service_client.AddPersonFaceAsync(person_group_id, cpr.PersonId, stream);
                                } catch { Console.WriteLine("Person photo containe no face"); }
                            }
                        }
                    }
                }

                // PROGRESS
                update_progress("Training group", $"Process group: {person_group_id}", progress);

                // Training person group
                await face_service_client.TrainPersonGroupAsync(person_group_id);

                TrainingStatus trainingStatus = null;
                while (true)
                {
                    trainingStatus = await face_service_client.GetPersonGroupTrainingStatusAsync(person_group_id);

                    if (trainingStatus.Status.ToString() != "running")
                    {
                        break;
                    }

                    await Task.Delay(1000);
                }

                Debug.WriteLine("Training ok");
            } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(false); }
            return(true);
        }
コード例 #14
0
 public async Task DeletePersonGroup(string personGroupId)
 {
     // delete person group
     await faceServiceClient.DeletePersonGroupAsync(personGroupId);
 }
コード例 #15
0
        private async void RegisterFaces()
        {
            this.BrowseButton.IsEnabled = false;
            Title = "Please wait ...";

            // Create an empty person group
            string personGroupId = "mykids";
            var    pg            = await faceServiceClient.GetPersonGroupAsync(personGroupId);

            if (pg != null)
            {
                await faceServiceClient.DeletePersonGroupAsync(personGroupId);
            }

            await faceServiceClient.CreatePersonGroupAsync(personGroupId, "My Kids");

            // Define Micah
            CreatePersonResult micah = await faceServiceClient.CreatePersonAsync(
                // Id of the person group that the person belonged to
                personGroupId,
                // Name of the person
                "Micah"
                );

            // Define Jon
            //CreatePersonResult jon = await faceServiceClient.CreatePersonAsync(
            //    // Id of the person group that the person belonged to
            //    personGroupId,
            //    // Name of the person
            //    "Jon"
            //);

            // Directory contains image files of Micah
            string micahImageDir = @"C:\temp\samples\micah";
            var    counter       = 0;

            foreach (string imagePath in Directory.GetFiles(micahImageDir, "*.png"))
            {
                if (counter == 15)
                {
                    counter = 0;
                    Thread.Sleep(61000);
                }

                using (Stream s = File.OpenRead(imagePath)) {
                    // Detect faces in the image and add to Anna
                    await faceServiceClient.AddPersonFaceAsync(
                        personGroupId, micah.PersonId, s);
                }
                counter++;
            }

            // Do the same for Jon
            //string jonImageDir = @"C:\Users\Johannes\Pictures\jon";

            //foreach (string imagePath in Directory.GetFiles(jonImageDir, "*.jpg")) {
            //    using (Stream s = File.OpenRead(imagePath)) {
            //        // Detect faces in the image and add to Anna
            //        await faceServiceClient.AddPersonFaceAsync(
            //            personGroupId, jon.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);
            }

            this.BrowseButton.IsEnabled = true;
            Title = "Ready...";
        }
コード例 #16
0
 public async Task DeleteGroup()
 {
     await faceClient.DeletePersonGroupAsync(PERSON_GROUP_ID);
 }
コード例 #17
0
 public async Task DeleteGroup(string customGroupId)
 {
     _msgManager.WriteMessage("Deleting person group...");
     await _faceServiceClient.DeletePersonGroupAsync(customGroupId);
 }
コード例 #18
0
        public async Task <bool> CreateWhitelistFromFolderAsync(string whitelistId, StorageFolder whitelistFolder = null, IProgress <int> progress = null)
        {
            bool   isSuccess   = true;
            double progressCnt = 0;

            WhitelistId = whitelistId;
            _whitelist  = new FaceApiWhitelist(WhitelistId);

            try
            {
                // whitelist folder default to picture library
                if (whitelistFolder == null)
                {
                    whitelistFolder = await KnownFolders.PicturesLibrary.GetFolderAsync("WhiteList");
                }

                _whitelistFolder = whitelistFolder;

                // detele person group if already exists
                try
                {
                    // An exception throwed if the person group doesn't exist
                    await _faceApiClient.GetPersonGroupAsync(whitelistId);

                    UpdateProgress(progress, ++progressCnt);

                    await _faceApiClient.DeletePersonGroupAsync(whitelistId);

                    UpdateProgress(progress, ++progressCnt);

                    Debug.WriteLine("Deleted old group");
                }
                catch (FaceAPIException fe)
                {
                    if (fe.ErrorCode == "PersonGroupNotFound")
                    {
                        Debug.WriteLine("The person group doesn't exist");
                    }
                    else
                    {
                        throw fe;
                    }
                }

                await _faceApiClient.CreatePersonGroupAsync(WhitelistId, "White List");

                UpdateProgress(progress, ++progressCnt);

                await BuildWhiteListAsync(progress, progressCnt);
            }

            catch (FaceAPIException fe)
            {
                isSuccess = false;
                Debug.WriteLine("FaceAPIException in CreateWhitelistFromFolderAsync : " + fe.ErrorMessage);
            }
            catch (Exception e)
            {
                isSuccess = false;
                Debug.WriteLine("Exception in CreateWhitelistFromFolderAsync : " + e.Message);
            }

            // progress to 100%
            UpdateProgress(progress, 100);

            return(isSuccess);
        }
コード例 #19
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Create an empty person group
            // string personGroupId = "ncr13";
            // await faceServiceClient.CreatePersonGroupAsync(personGroupId, "");
            bool groupExists = false;

            try
            {
                //MainWindow.Log("Request: Group {0} will be used to build a person database. Checking whether the group exists.", GroupName);
                Title = String.Format("Request: Group {0} will be used to build a person database. Checking whether the group exists.", personGroupId);
                await faceServiceClient.GetPersonGroupAsync(personGroupId);

                groupExists = true;
                //MainWindow.Log("Response: Group {0} exists.", GroupName);
                Title = String.Format("Response: Group {0} exists.", personGroupId);
            }
            catch (FaceAPIException ex)
            {
                if (ex.ErrorCode != "PersonGroupNotFound")
                {
                    //MainWindow.Log("Response: {0}. {1}", ex.ErrorCode, ex.ErrorMessage);
                    Title = String.Format("Response: {0}. {1}", ex.ErrorCode, ex.ErrorMessage);
                    return;
                }
                else
                {
                    // MainWindow.Log("Response: Group {0} did not exist previously.", GroupName);
                    Title = String.Format("Response: Group {0} did not exist previously.", personGroupId);
                }
            }

            if (groupExists)
            {
                var cleanGroup = System.Windows.MessageBox.Show(string.Format("Requires a clean up for group \"{0}\" before setting up a new person database. Click OK to proceed, group \"{0}\" will be cleared.", personGroupId), "Warning", MessageBoxButton.OKCancel);
                if (cleanGroup == MessageBoxResult.OK)
                {
                    await faceServiceClient.DeletePersonGroupAsync(personGroupId);
                }
                else
                {
                    return;
                }
            }

            //MainWindow.Log("Request: Creating group \"{0}\"", GroupName);

            Title = String.Format("Request: Creating group \"{0}\"", personGroupId);
            try
            {
                await faceServiceClient.CreatePersonGroupAsync(personGroupId, personGroupId);

                // MainWindow.Log("Response: Success. Group \"{0}\" created", personGroupId);
                Title = String.Format("Response: Success. Group \"{0}\" created", personGroupId);
            }
            catch (FaceAPIException ex)
            {
                //MainWindow.Log("Response: {0}. {1}", ex.ErrorCode, ex.ErrorMessage);
                Title = String.Format("Response: {0}. {1}", ex.ErrorCode, ex.ErrorMessage);
                return;
            }


            // Define Anna
            CreatePersonResult friend1 = await faceServiceClient.CreatePersonAsync(
                // Id of the person group that the person belonged to
                personGroupId,
                // Name of the person
                "Anna"
                );

            // Define Toshif
            CreatePersonResult friend2 = await faceServiceClient.CreatePersonAsync(
                // Id of the person group that the person belonged to
                personGroupId,
                // Name of the person
                "Toshif"
                );

            // Define Clare
            CreatePersonResult friend3 = await faceServiceClient.CreatePersonAsync(
                // Id of the person group that the person belonged to
                personGroupId,
                // Name of the person
                "Clare"
                );

            /*// Define Toshif
             * CreatePersonResult friend4 = await faceServiceClient.CreatePersonAsync(
             *  // Id of the person group that the person belonged to
             *  personGroupId,
             *  // Name of the person
             *  "Toshif"
             * );
             */


            // Directory contains image files of Anna
            const string friend1ImageDir = @"D:\Pictures\MyBuddies\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);
                }
            }

            const string friend2ImageDir = @"D:\Pictures\MyBuddies\Toshif\";

            foreach (string imagePath in Directory.GetFiles(friend2ImageDir, "*.jpg"))
            {
                using (Stream s = File.OpenRead(imagePath))
                {
                    // Detect faces in the image and add to Bill
                    await faceServiceClient.AddPersonFaceAsync(
                        personGroupId, friend2.PersonId, s);
                }
            }

            const string friend3ImageDir = @"D:\Pictures\MyBuddies\Clare\";

            foreach (string imagePath in Directory.GetFiles(friend3ImageDir, "*.jpg"))
            {
                using (Stream s = File.OpenRead(imagePath))
                {
                    // Detect faces in the image and add to Clare
                    await faceServiceClient.AddPersonFaceAsync(
                        personGroupId, friend3.PersonId, s);
                }
            }

            /*const string friend4ImageDir = @"D:\Pictures\MyBuddies\Toshif\";
             *
             * foreach (string imagePath in Directory.GetFiles(friend4ImageDir, "*.jpg"))
             * {
             *  using (Stream s = File.OpenRead(imagePath))
             *  {
             *      // Detect faces in the image and add to Toshif
             *      await faceServiceClient.AddPersonFaceAsync(
             *          personGroupId, friend4.PersonId, s);
             *  }
             * }
             */

            Title = String.Format("Success...Group Scaning Completed.");
        }