Exemple #1
0
        private async Task DoBackgroudWork(IProgress <string> progress)
        {
            //step1: to create a person group
            progress.Report("Executing task to create person group...");
            await _faceClient.CreatePersonGroupAsync(personGroupId, "My Friends");

            //step2: to add persons into person group
            progress.Report("Executing task to add 'Ara' into person group...");
            var result = await _faceClient.CreatePersonAsync(personGroupId, "Ara");

            PersonIdDic.TryAdd("Ara", result.PersonId);

            progress.Report("Executing task to add 'Ron' into person group...");
            result = await _faceClient.CreatePersonAsync(personGroupId, "Ron");

            PersonIdDic.TryAdd("Ron", result.PersonId);

            //step3: to upload images for persons in group:
            progress.Report("Executing task to upload pictures of 'Ara'...");
            await UploadImagesForPerson(ArasPath, "Ara");

            progress.Report("Executing task to upload pictures of 'Ron'...");
            await UploadImagesForPerson(RonsPath, "Ron");

            //step4: to train the person group
            progress.Report(string.Format("Executing task to train the person group {0}...", personGroupId));
            await TrainPersonGroupTask();
        }
Exemple #2
0
        /// <summary> Function which submits a frame to the Face API. </summary>
        /// <param name="frame"> The video frame to submit. </param>
        /// <returns> A <see cref="Task{LiveCameraResult}"/> representing the asynchronous API call,
        ///     and containing the faces returned by the API. </returns>
        public async Task UploadFaces()
        {
            _faceClient = new FaceAPI.FaceServiceClient(Properties.Settings.Default.FaceAPIKey, Properties.Settings.Default.FaceAPIHost);
            var groups = await _faceClient.ListPersonGroupsAsync();

            var exists = false;

            foreach (var group in groups)
            {
                if (group.PersonGroupId.Equals(_groupId))
                {
                    exists = true;
                    break;
                }
            }
            if (exists)
            {
                var persons = await _faceClient.ListPersonsAsync(_groupId);

                foreach (var person in persons)
                {
                    await _faceClient.DeletePersonAsync(_groupId, person.PersonId);
                }
            }
            else
            {
                await _faceClient.CreatePersonGroupAsync(_groupId, "AtosEmployees");
            }

            var iterator = 0;

            foreach (string dir in Directory.GetDirectories("C:\\Temp\\Pics"))
            {
                var folderName            = dir.Split('\\')[3];
                CreatePersonResult person = await _faceClient.CreatePersonAsync(_groupId, "Person " + iterator ++ + " " + folderName);

                foreach (string imagePath in Directory.GetFiles(dir))
                {
                    using (Stream s = File.OpenRead(imagePath))
                    {
                        try
                        {
                            //await Task.Delay(5000);
                            Properties.Settings.Default.UploadStatus = String.Format("Uploading {0}: {1}", iterator, imagePath);

                            await _faceClient.AddPersonFaceAsync(_groupId, person.PersonId, s);
                        }
                        catch (FaceAPIException fae)
                        {
                            var finishedAt = "";
                        }
                        //await Task.Delay(5000);
                    }
                }
            }
        }
 public static async Task CreatePersonGroup(string strPersonGroupId, string strName, string strUserData = null)
 {
     try
     {
         await fsClient.CreatePersonGroupAsync(strPersonGroupId, strName, strUserData);
     }
     catch (Exception e)
     {
         //throw;
         return;
     }
 }
Exemple #4
0
        private async void CreateUserGroup_Click(object sender, RoutedEventArgs e)
        {
            const string myImageDir = @"C:\Images\";

            try
            {
                ////var personGroupExisits = await _faceClient.GetPersonGroupAsync(_personGroupId);

                ////if (personGroupExisits != null)
                ////{
                ////    await _faceClient.DeletePersonGroupAsync(_personGroupId);
                ////    MessageBox.Show($"Person Group Id: {personGroupExisits.Name} already exists, deleting group.");
                ////    await Task.Delay(1000);
                ////}

                await _faceClient.CreatePersonGroupAsync(_personGroupId, "myself");

                await Task.Delay(1000);

                CreatePersonResult myself = await _faceClient.CreatePersonAsync(_personGroupId, "Rob Mah");

                MessageBox.Show("Group created successfully.");

                var files = Directory.GetFiles(myImageDir, "*.jpg");
                int count = 1;

                foreach (string imagePath in files)
                {
                    using (Stream s = File.OpenRead(imagePath))
                    {
                        await _faceClient.AddPersonFaceAsync(_personGroupId, myself.PersonId, s);

                        MessageBox.Show($"Image {count} of {files.Count()} added.");
                        await Task.Delay(1000);
                    }
                    count++;
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #5
0
        /// <summary> Function which submits a frame to the Emotion API. </summary>
        /// <param name="frame"> The video frame to submit. </param>
        /// <returns> A <see cref="Task{LiveCameraResult}"/> representing the asynchronous API call,
        ///     and containing the emotions returned by the API. </returns>
        private async Task TrainCognitiveServicesAsync()
        {
            _faceClient = new FaceAPI.FaceServiceClient(Properties.Settings.Default.FaceAPIKey, Properties.Settings.Default.FaceAPIHost);

            var pgexists = await _faceClient.GetPersonGroupAsync(personGroupId);

            if (pgexists == null)
            {
                await _faceClient.CreatePersonGroupAsync(personGroupId, "My Friends");
            }

            // Define Jose
            CreatePersonResult Josefriend = await _faceClient.CreatePersonAsync(
                // Id of the PersonGroup that the person belonged to
                personGroupId,
                // Name of the person
                "Jose"
                );

            // Define Jose
            CreatePersonResult Aaronfriend = await _faceClient.CreatePersonAsync(
                // Id of the PersonGroup that the person belonged to
                personGroupId,
                // Name of the person
                "Aaron"
                );

            // Directory contains image files of Anna
            const string JoseImageDir = @"C:\Users\joseo\source\repos\FutureofWork-ServTechAPJ2018\FutureofWork-ServTech2018APJ\LiveCameraSample\Pictures\Jose\";

            foreach (string imagePath in Directory.GetFiles(JoseImageDir, "*.jpg"))
            {
                using (Stream s = File.OpenRead(imagePath))
                {
                    // Detect faces in the image and add to Anna
                    await _faceClient.AddPersonFaceAsync(
                        personGroupId, Josefriend.PersonId, s);
                }
            }
            // Do the same for Bill and Clare

            const string AaronImageDir = @"C:\Users\joseo\source\repos\FutureofWork-ServTechAPJ2018\FutureofWork-ServTech2018APJ\LiveCameraSample\Pictures\Aaron\";

            foreach (string imagePath in Directory.GetFiles(AaronImageDir, "*.jpg"))
            {
                using (Stream s = File.OpenRead(imagePath))
                {
                    // Detect faces in the image and add to Anna
                    await _faceClient.AddPersonFaceAsync(
                        personGroupId, Aaronfriend.PersonId, s);
                }
            }
            // Do the same for Bill and Clare


            await _faceClient.TrainPersonGroupAsync(personGroupId);

            TrainingStatus trainingStatus = null;

            while (true)
            {
                trainingStatus = await _faceClient.GetPersonGroupTrainingStatusAsync(personGroupId);

                if (trainingStatus.Status != Status.Running)
                {
                    break;
                }

                await Task.Delay(1000);
            }

            Console.Write("Training successfully completed");
        }
        public static async Task Train()
        {
            FaceAPI.FaceServiceClient _faceClient = new FaceAPI.FaceServiceClient("952a5cbdd78845948079fe7e2c61807d", "https://australiaeast.api.cognitive.microsoft.com/face/v1.0");

            string personGroupId = "myfriendsServtechAPJ";
            await _faceClient.CreatePersonGroupAsync(personGroupId, "My Friends");

            // Define Jose
            CreatePersonResult Josefriend = await _faceClient.CreatePersonAsync(
                // Id of the PersonGroup that the person belonged to
                personGroupId,
                // Name of the person
                "Jose"
                );

            // Define Jose
            CreatePersonResult Aaronfriend = await _faceClient.CreatePersonAsync(
                // Id of the PersonGroup that the person belonged to
                personGroupId,
                // Name of the person
                "Aaron"
                );

            // Directory contains image files of Anna
            const string JoseImageDir = @"C:\Users\joseo\source\repos\FutureofWork-ServTechAPJ2018\FutureofWork-ServTech2018APJ\LiveCameraSample\Pictures\Jose\";

            foreach (string imagePath in Directory.GetFiles(JoseImageDir, "*.jpg"))
            {
                using (Stream s = File.OpenRead(imagePath))
                {
                    // Detect faces in the image and add to Anna
                    await _faceClient.AddPersonFaceAsync(
                        personGroupId, Josefriend.PersonId, s);
                }
            }
            // Do the same for Bill and Clare

            const string AaronImageDir = @"C:\Users\joseo\source\repos\FutureofWork-ServTechAPJ2018\FutureofWork-ServTech2018APJ\LiveCameraSample\Pictures\Aaron\";

            foreach (string imagePath in Directory.GetFiles(AaronImageDir, "*.jpg"))
            {
                using (Stream s = File.OpenRead(imagePath))
                {
                    // Detect faces in the image and add to Anna
                    await _faceClient.AddPersonFaceAsync(
                        personGroupId, Aaronfriend.PersonId, s);
                }
            }
            // Do the same for Bill and Clare


            await _faceClient.TrainPersonGroupAsync(personGroupId);

            FaceAPI.Contract.TrainingStatus trainingStatus = null;
            while (true)
            {
                trainingStatus = await _faceClient.GetPersonGroupTrainingStatusAsync(personGroupId);

                if (trainingStatus.Status != Status.Running)
                {
                    break;
                }

                await Task.Delay(1000);
            }

            Console.Write("Training successfully completed");
        }