Beispiel #1
0
 public override async Task InitAsync()
 {
     await ExecuteAsync(async() =>
     {
         FacePhoto = "face_default";
         _persons  = await FaceApiService.GetPersons();
     });
 }
Beispiel #2
0
 public override async Task InitAsync()
 {
     await ExecuteAsync(async() =>
     {
         var persons = await FaceApiService.GetPersons();
         Persons     = new ObservableCollection <Person>(persons);
     });
 }
Beispiel #3
0
        public override async Task InitAsync()
        {
            await ExecuteAsync(async() =>
            {
                HasToShowPicker = true;
                var persons     = await FaceApiService.GetPersons();

                Persons        = new ObservableCollection <Person>(persons);
                PersonSelected = persons?.FirstOrDefault();
            });
        }
Beispiel #4
0
        async Task <bool> IsValidPhoto()
        {
            var facesDetected = await FaceApiService.DetectFaces(GetByteArray(_photo));

            if (facesDetected == null || facesDetected.Count == 0)
            {
                await Application.Current.MainPage.DisplayAlert(
                    "Foto no válida",
                    "No hemos detectado ninguna cara en la foto que has tomado. Saca una foto en la que salga tu cara.",
                    "Ok");

                return(false);
            }
            else if (facesDetected.Count == 1)
            {
                var persons = await FaceApiService.GetPersons();

                foreach (var face in facesDetected)
                {
                    bool existsFaceId = persons.FirstOrDefault(person => person.PersistedFaceIds.Contains(face.FaceId)) != null;
                    if (existsFaceId)
                    {
                        await Application.Current.MainPage.DisplayAlert(
                            "Foto no válida",
                            $"En el grupo {_personGroup.Name} ya hay una persona creada asociada a la cara a la que le has sacado la foto.",
                            "Ok");

                        return(false);
                    }
                }
            }
            else
            {
                foreach (var face in facesDetected)
                {
                    await Application.Current.MainPage.DisplayAlert(
                        "Foto no válida",
                        "En la foto sólo puede haber una cara",
                        "Ok");

                    return(false);
                }
            }

            return(true);
        }
Beispiel #5
0
        async Task OnAddImage()
        {
            await ExecuteAsync(async() =>
            {
                await CheckPermissionAndAskIfIsNeeded(Permission.Camera);
                await CheckPermissionAndAskIfIsNeeded(Permission.Storage);

                _photo = await GetFacePhotoTaked();
                if (_photo == null)
                {
                    return;
                }
                PhotoTaked       = _photo.Path;
                byte[] byteArray = GetByteArray(_photo);

                var detectResults = await FaceApiService.DetectFaces(byteArray);

                if (!(await IsPhotoValid(detectResults)))
                {
                    return;
                }

                var identifyResults = await FaceApiService.Identify(new IdentifyFaceRequest()
                {
                    FaceIds = detectResults.Select(x => x.FaceId).ToList(),
                    MaxNumOfCandidatesReturned = 10,
                    PersonGroupId       = _personGroup.PersonGroupId,
                    ConfidenceThreshold = 0.5
                });

                var persons = await FaceApiService.GetPersons();

                if (detectResults == null || identifyResults == null || persons == null)
                {
                    return;
                }

                FacesDetected = identifyResults.Select(res => new FaceDetectedItemViewModel()
                {
                    FaceId         = res.FaceId,
                    FaceRectangle  = detectResults.FirstOrDefault(detResults => detResults.FaceId == res.FaceId).FaceRectangle,
                    FaceAttributes = detectResults.FirstOrDefault(detResults => detResults.FaceId == res.FaceId).FaceAttributes,
                    PersonName     = persons?.FirstOrDefault(p => p.PersonId == res.Candidates?.FirstOrDefault(cand => cand.PersonId == p.PersonId)?.PersonId)?.Name
                }).ToList();
            });
        }