public override async Task <RecognizePersonResult> ExecuteAsync(RecognizePersonContext request)
        {
            var retResult = new RecognizePersonResult();

            SelectPictureResult pictureResult = null;

            if (request.UseCamera)
            {
                var pictureRequest = new TakePictureRequest {
                    CameraOption = request.CameraOption, MaxPixelDimension = 500
                };
                pictureResult = await TakePicture.ExecuteAsync(pictureRequest);
            }
            else
            {
                var choosePictureRequest = new ChoosePictureRequest {
                    MaxPixelDimension = 500
                };
                pictureResult = await ChoosePicture.ExecuteAsync(choosePictureRequest);
            }

            retResult.Notification.AddRange(retResult.Notification);

            if (retResult.IsValid() && pictureResult.TaskResult == TaskResult.Success)
            {
                var faceContext = new RecognizeFaceContext {
                    FaceImage = pictureResult.Image, GroupId = Constants.GroupId
                };
                var recogResult = await RecognizeCommand.ExecuteAsync(faceContext);

                retResult.Notification.AddRange(recogResult.Notification);

                if (retResult.IsValid())
                {
                    var personResult = await PersonStore.FindPersonAsync(recogResult.Person.PersonId.ToString());

                    if (personResult == null)
                    {
                        UserData userData = null;
                        if (recogResult.Person.UserData != null)
                        {
                            userData = JsonConvert.DeserializeObject <UserData>(recogResult.Person.UserData);
                        }
                        Mutant newPerson = new Mutant
                        {
                            Name = recogResult.Person.Name,
                            Id   = recogResult.Person.PersonId.ToString(),
                            Data = userData
                        };
                        await PersonStore.AddPersonAsync(newPerson);

                        personResult = newPerson;
                    }

                    retResult.Person = personResult;
                }
            }

            return(retResult);
        }
Esempio n. 2
0
        public override async Task <DetectPersonResult> ExecuteAsync(DetectPersonContext request)
        {
            var retResult = new DetectPersonResult();

            SelectPictureResult pictureResult;

            if (request.UseCamera)
            {
                var pictureRequest = new TakePictureRequest {
                    CameraOption = request.CameraOption, MaxPixelDimension = 500
                };
                pictureResult = await TakePicture.ExecuteAsync(pictureRequest);
            }
            else
            {
                var choosePictureRequest = new ChoosePictureRequest {
                    MaxPixelDimension = 500
                };
                pictureResult = await ChoosePicture.ExecuteAsync(choosePictureRequest);
            }

            retResult.Notification.AddRange(retResult.Notification);

            if (retResult.IsValid() && pictureResult.TaskResult == TaskResult.Success)
            {
                var faceContext = new DetectFaceContext
                {
                    FaceImage            = pictureResult.Image,
                    DetectFaceAttributes = request.DetectFaceAttributes,
                    DetectFaceId         = request.DetectFaceId,
                    DetectFaceLandmarks  = request.DetectFaceLandmarks
                };
                var recogResult = await DetectFace.ExecuteAsync(faceContext);

                retResult.Notification.AddRange(recogResult.Notification);

                if (retResult.IsValid())
                {
                    retResult.FaceData = recogResult.Face;
                }
            }

            return(retResult);
        }