コード例 #1
0
        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);
        }
コード例 #2
0
        public async Task <List <string> > FaceRecognizeAsync(StorageFile imageFile)
        {
            var recogResult = new List <string>();

            if (!FaceApiUtils.ValidateImageFile(imageFile))
            {
                throw new FaceRecognitionException(FaceRecognitionExceptionType.InvalidImage);
            }

            // detect all faces in the image
            var faceIds = await DetectFacesFromImage(imageFile);

            // try to identify all faces to person
            var identificationResults = await _faceApiClient.IdentifyAsync(WhitelistId, faceIds);

            // add identified person name to result list
            foreach (var result in identificationResults)
            {
                if (result.Candidates.Length > 0)
                {
                    var personName = _whitelist.GetPersonNameById(result.Candidates[0].PersonId);
                    Debug.WriteLine("Face ID Confidence: " + Math.Round(result.Candidates[0].Confidence * 100, 1) + "%");
                    recogResult.Add(personName);
                }
            }

            return(recogResult);
        }
コード例 #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);
        }