コード例 #1
0
ファイル: MainViewModel.cs プロジェクト: hernandoz/VisionAI
        async Task PredictPhoto(MediaFile photo)
        {
            var endpoint = new PredictionEndpoint
            {
                ApiKey = await KeyService.GetPredictionKey()
            };

            var results = await endpoint.PredictImageAsync(Guid.Parse(await KeyService.GetProjectId()),
                                                           photo.GetStream());

            AllPredictions = results.Predictions
                             .Where(p => p.Probability > Probability)
                             .ToList();


            // Create the Api, passing in the training key
            CustomVisionTrainingClient trainingApi = new CustomVisionTrainingClient()
            {
                ApiKey   = KeyService.TK,
                Endpoint = KeyService.SouthCentralUsEndpoint
            };

            // Find the object detection domain

            //var domains = trainingApi.GetDomains();
            //var objDetectionDomain = domains.FirstOrDefault(d => d.Type == "ObjectDetection");

            //upload to service
            trainingApi.CreateImagesFromData(Guid.Parse(await KeyService.GetProjectId()), photo.GetStream(), null);
        }
コード例 #2
0
ファイル: App.xaml.cs プロジェクト: nomada2/ObjectDetector
 protected override async void OnStart()
 {
     if (string.IsNullOrWhiteSpace(await KeyService.GetPredictionKey()) ||
         string.IsNullOrWhiteSpace(await KeyService.GetProjectId()))
     {
         await MainPage.Navigation.PushModalAsync(SettingsPage.CreateSettingsPage(), false);
     }
 }
コード例 #3
0
        async Task Ok()
        {
            IsEnabled = false;
            try
            {
                var client = new CustomVisionPredictionClient
                {
                    ApiKey   = PredictionKey,
                    Endpoint = Endpoint
                };

                if (Guid.TryParse(ProjectId, out var pId))
                {
                    var imagePath = "ObjectDetector.Images.single.png";
                    var assembly  = typeof(SettingsViewModel).GetTypeInfo().Assembly;

                    using (var stream = assembly.GetManifestResourceStream(imagePath))
                    {
                        await client.DetectImageWithNoStoreAsync(pId, publishName, stream);
                    }

                    await KeyService.SetPredictionKey(PredictionKey);

                    await KeyService.SetProjectId(ProjectId);

                    await KeyService.SetPublishName(PublishName);

                    await KeyService.SetEndpoint(Endpoint);

                    Analytics.TrackEvent("Updating keys");

                    await Application.Current.MainPage.Navigation.PopModalAsync();
                }
                else
                {
                    Analytics.TrackEvent("Failed updating keys", new Dictionary <string, string> {
                        { "Error", "The project Id is not a valid GUID" }
                    });
                    await Application.Current.MainPage.DisplayAlert("Error", "The project Id is not a valid GUID", "OK");
                }
            }
            catch (Exception ex)
            {
                Analytics.TrackEvent("Failed updating keys", new Dictionary <string, string> {
                    { "Error", "The project Id and prediction key don't match an existing project" }
                });
                Crashes.TrackError(ex, new Dictionary <string, string> {
                    { "Action", "Testing key and project id" }
                });
                await Application.Current.MainPage.DisplayAlert("Error", "The project Id and prediction key don't match an existing project", "OK");
            }
            finally
            {
                IsEnabled = true;
            }
        }
コード例 #4
0
        public async Task SetUp()
        {
            try
            {
                PredictionKey = await KeyService.GetPredictionKey();

                ProjectId = await KeyService.GetProjectId();
            }
            finally
            {
                IsEnabled = true;
            }
        }
コード例 #5
0
        async Task PredictPhoto(MediaFile photo)
        {
            var endpoint = new PredictionEndpoint
            {
                ApiKey = await KeyService.GetPredictionKey()
            };

            var results = await endpoint.PredictImageAsync(Guid.Parse(await KeyService.GetProjectId()),
                                                           photo.GetStream());

            AllPredictions = results.Predictions
                             .Where(p => p.Probability > Probability)
                             .ToList();
        }
コード例 #6
0
        async Task PredictPhoto(MediaFile photo)
        {
            var endpoint = new CustomVisionPredictionClient
            {
                ApiKey   = await KeyService.GetPredictionKey(),
                Endpoint = await KeyService.GetEndpoint()
            };

            var results = await endpoint.DetectImageAsync(Guid.Parse(await KeyService.GetProjectId()),
                                                          await KeyService.GetPublishName(),
                                                          photo.GetStream());

            AllPredictions = results.Predictions
                             .Where(p => p.Probability > Probability)
                             .ToList();
        }
コード例 #7
0
        public async Task SetUp()
        {
            if (string.IsNullOrWhiteSpace(PredictionKey) &&
                string.IsNullOrWhiteSpace(ProjectId) &&
                string.IsNullOrWhiteSpace(PublishName) &&
                string.IsNullOrWhiteSpace(Endpoint))
            {
                try
                {
                    PredictionKey = await KeyService.GetPredictionKey();

                    ProjectId = await KeyService.GetProjectId();

                    PublishName = await KeyService.GetPublishName();

                    Endpoint = await KeyService.GetEndpoint();
                }
                finally
                {
                    IsEnabled = true;
                }
            }
        }
コード例 #8
0
        public SettingsViewModel()
        {
#pragma warning disable RECS0165 // Asynchronous methods should return a Task instead of void
            OpenCustomVisionCommand = new Command(async() => await Xamarin.Essentials.Launcher.OpenAsync("https://customvision.ai"));
            OkCommand = new Command(async() => await Ok(), () => !string.IsNullOrWhiteSpace(PredictionKey) && !string.IsNullOrWhiteSpace(ProjectId) && Guid.TryParse(ProjectId, out var g));
            ConfigureCanCancelCommand = new Command(async() => CanCancel = !string.IsNullOrWhiteSpace(await KeyService.GetPredictionKey()) && !string.IsNullOrWhiteSpace(await KeyService.GetProjectId()));
            CancelCommand             = new Command(async() => await Application.Current.MainPage.Navigation.PopModalAsync());
#pragma warning restore RECS0165 // Asynchronous methods should return a Task instead of void

            IsEnabled = false;
        }