public async Task <bool> RemoveImageFromWhitelistAsync(StorageFile imageFile, string personName = null)
        {
            bool isSuccess = true;

            if (!FaceApiUtils.ValidateImageFile(imageFile))
            {
                isSuccess = false;
            }
            else
            {
                // If personName is null use the folder name as person name
                if (string.IsNullOrEmpty(personName))
                {
                    personName = await FaceApiUtils.GetParentFolderNameAsync(imageFile);
                }

                var personId = _whitelist.GetPersonIdByName(personName);
                var faceId   = _whitelist.GetFaceIdByFilePath(imageFile.Path);
                if (personId == Guid.Empty || faceId == Guid.Empty)
                {
                    isSuccess = false;
                }
                else
                {
                    await RemoveFace(personId, faceId);

                    // train whitelist
                    isSuccess = await TrainingWhitelistAsync();
                }
            }
            return(isSuccess);
        }
        public async Task <bool> AddImageToWhitelistAsync(StorageFile imageFile, string personName = null)
        {
            bool isSuccess = true;

            // imageFile should be valid image file
            if (!FaceApiUtils.ValidateImageFile(imageFile))
            {
                isSuccess = false;
            }
            else
            {
                var filePath = imageFile.Path;

                // If personName is null/empty, use the folder name as person name
                if (string.IsNullOrEmpty(personName))
                {
                    personName = await FaceApiUtils.GetParentFolderNameAsync(imageFile);
                }

                // If person name doesn't exists, add it
                var personId = _whitelist.GetPersonIdByName(personName);
                if (personId == Guid.Empty)
                {
                    var folder = await imageFile.GetParentAsync();

                    personId = await CreatePerson(personName, folder);
                }

                // detect faces
                //   var faceId = await DetectFaceFromImage(imageFile);
                //   await AddFace(personId, imageFile.Path);
                Task task = StartAddFaceImageTask(imageFile, personId);
                task.ContinueWith((taskDone) =>
                {
                    var detectTask = taskDone as Task <Tuple <string, ClientContract.AddPersistedFaceResult> >;
                    // Update something on UI
                    var faceDetectionResult = detectTask.Result;
                    if (faceDetectionResult != null && faceDetectionResult.Item2 != null)
                    {
                        _whitelist.AddFace(personId, faceDetectionResult.Item2.PersistedFaceId, faceDetectionResult.Item1);
                    }
                    else
                    {
                        Debug.WriteLine("Error detecting face in image " + imageFile.Path);
                    }
                }).Wait();

                // train whitelist
                isSuccess = await TrainingWhitelistAsync();
            }

            return(isSuccess);
        }
Exemplo n.º 3
0
        public async Task <bool> AddImageToWhitelistAsync(StorageFile imageFile, string personName = null)
        {
            bool isSuccess = true;

            // imageFile should be valid image file
            if (!FaceApiUtils.ValidateImageFile(imageFile))
            {
                isSuccess = false;
            }
            else
            {
                var filePath = imageFile.Path;

                // If personName is null/empty, use the folder name as person name
                if (string.IsNullOrEmpty(personName))
                {
                    personName = await FaceApiUtils.GetParentFolderNameAsync(imageFile);
                }

                // If person name doesn't exists, add it
                var personId = _whitelist.GetPersonIdByName(personName);
                if (personId == Guid.Empty)
                {
                    var folder = await imageFile.GetParentAsync();

                    personId = await CreatePerson(personName, folder);
                }

                // detect faces
                var faceId = await DetectFaceFromImage(imageFile);
                await AddFace(personId, faceId, imageFile.Path);

                // train whitelist
                isSuccess = await TrainingWhitelistAsync();
            }

            return(isSuccess);
        }