public static async Task <AddPersistedFaceResult> AddPersonFaceAsync(string strPersonGroupId, Guid personId, Stream stream, string strUserData = null, FaceRectangle faceRectangle = null)
        {
            AddPersistedFaceResult addPersistedFaceResult = null;

            addPersistedFaceResult = await fsClient.AddPersonFaceAsync(strPersonGroupId, personId, stream, strUserData, faceRectangle);

            return(addPersistedFaceResult);
        }
Esempio n. 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 UpdatePerson(string personId)
        {
            _faceClient = new FaceAPI.FaceServiceClient(Properties.Settings.Default.FaceAPIKey, Properties.Settings.Default.FaceAPIHost);
            var groups = await _faceClient.ListPersonGroupsAsync();

            foreach (string imagePath in Directory.GetFiles("C:\\Temp\\Pics\\Sabina2"))
            {
                using (Stream s = File.OpenRead(imagePath))
                {
                    try
                    {
                        var persons = await _faceClient.ListPersonsAsync(_groupId);

                        Person person = persons.Where(pers => pers.Name == personId).FirstOrDefault();
                        Properties.Settings.Default.UploadStatus = String.Format("Updating {0} face: {1}", person.Name, imagePath);

                        await _faceClient.AddPersonFaceAsync(_groupId, person.PersonId, s);
                    }
                    catch (FaceAPIException fae)
                    {
                        Properties.Settings.Default.UploadStatus = "Error: " + fae.Message;
                    }
                }
            }
        }
Esempio n. 3
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);
                    }
                }
            }
        }
Esempio n. 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)
            {
            }
        }
Esempio n. 5
0
        private async Task UploadImagesForPerson(string dirPath, string personName)
        {
            Guid personId = Guid.Empty;

            PersonIdDic.TryGetValue(personName, out personId);
            foreach (string imagePath in Directory.GetFiles(dirPath, "*.jpg"))
            {
                try
                {
                    using (Stream s = File.OpenRead(imagePath))
                    {
                        //#3. upload face images of a specific person.
                        await _faceClient.AddPersonFaceAsync(personGroupId, personId, s);
                    }
                }
                catch
                {
                    continue;
                }
            }
        }
Esempio n. 6
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");
        }