コード例 #1
0
        private void InitializeServices()
        {
            _webCamService = new WebCamService();
            _webCamService.ImageChanged += _webCamService_ImageChanged;

            _rekognitionService = new RekognitionService();
        }
コード例 #2
0
        private async void Button_Clicked(object sender, EventArgs e)
        {
            var cameraStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Camera);

            var storageStatus = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Storage);

            if (cameraStatus != PermissionStatus.Granted || storageStatus != PermissionStatus.Granted)
            {
                var results = await CrossPermissions.Current.RequestPermissionsAsync(new[] { Permission.Camera, Permission.Storage });

                cameraStatus  = results[Permission.Camera];
                storageStatus = results[Permission.Storage];
            }

            if (cameraStatus == PermissionStatus.Granted && storageStatus == PermissionStatus.Granted)
            {
                var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
                {
                    Directory = "Sample",
                    Name      = "test.jpg"
                });

                if (file == null)
                {
                    return;
                }

                image.Source = ImageSource.FromFile(file.Path);

                var rekognition = new RekognitionService();
                var faceList    = await rekognition.GetFaceDetailsFromLocalFileAsync(file.Path);

                var faceCount = faceList.Count();
                var face      = faceList.FirstOrDefault();

                await DisplayAlert("Rekognition", $"Detected: {faceCount} Person\n\nAgeRange: {face.AgeRangeLow} - {face.AgeRangeLow}\nGender: {face.Gender}\nGender Confidence: {face.GenderConfidence}%\nHappiness: {face.HappinessConfidence}%", "OK");
            }
            else
            {
                await DisplayAlert("Permissions Denied", "Unable to take photos.", "OK");

                //On iOS you may want to send your user to the settings screen.
                //CrossPermissions.Current.OpenAppSettings();
            }
        }
コード例 #3
0
        public void CompareShouldReturnExternalImageId()
        {
            var configuration = new Mock <IConfiguration>();

            var configurationSection = new Mock <IConfigurationSection>();

            var mockAwsConfiguration = new Mock <IOptions <AwsConfiguration> >();

            mockAwsConfiguration.Setup(a => a.Value).Returns(new AwsConfiguration()
            {
                awsAccessKey = "VoVypAUN/NsenNmO6PLy73S9uyJ0BRU4R/1DdkNP8cWGNAQMaKVINuF6BqF6qhXx", awsAccessSecret = "1mMfRRkNOBBYMFw1jtcq05o2/p97KIVgUfDJ4m/jvkuEs5WJC8XL2G1J6PiSyFHZ6g+xicmAxTLA3AmCL2NoPg=="
            });

            RekognitionService service = new RekognitionService(mockAwsConfiguration.Object);

            string path = @"TestImage/karla.jpg";

            byte[] bytes = System.IO.File.ReadAllBytes(path);

            string id = service.Compare(bytes).Result;

            Assert.Equal("1", id);
        }
コード例 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            var rekognition = new RekognitionService();
            var task        = rekognition.GetFaceDetailsFromLocalFileAsync(@"D:\family.jpg");
            var res         = task.Result;

            Debug.WriteLine($"DEBUG: {res.Count} detected.");

            var i = 1;

            foreach (var face in res)
            {
                Console.WriteLine($"No. {i}\n" +
                                  $"Gender: {face.Gender}, Confidence: {face.GenderConfidence}%\n" +
                                  $"AgeRange {face.AgeRangeLow} ~ {face.AgeRangeHigh}\n" +
                                  $"Happiness: {face.HappinessConfidence}%\n\n");
                i++;
            }

            Console.ReadLine();
        }