Exemplo n.º 1
0
        private async Task IdentifyImageAsync(MediaFile image)
        {
            if (Connectivity.NetworkAccess == NetworkAccess.None)
            {
                UserDialogs.Instance.Alert("Se necesita conexión a la red para realizar esta operación.", "Desconectado", "Aceptar");
                return;
            }
            ;



            //TODO: Apply permissions recommendations: https://github.com/jamesmontemagno/MediaPlugin#permission-recommendations
            //TODO: return null exception and pick it up for AppCenter and display Userdialog (https://github.com/aritchie/userdialogs/blob/master/docs/progress.md)

            if (image == null)
            {
                return;
            }

            using (UserDialogs.Instance.Loading("Analizando..."))
            {
                var fileStream = image.GetStream();

                App.SourceImage = ImageSource.FromStream(() =>
                {
                    return(image.GetStream());
                });



                ImagePrediction result = null;

                try
                {
                    result = await _predictionService.ClassifyImageAsync(App.CustomVisionProjectId, "default", fileStream);
                }
                catch (Exception ex)
                {
                    Crashes.TrackError(ex);
                    await UserDialogs.Instance.AlertAsync("Error analizando imagen. No se pudo conectar con el servicio.", "Error");

                    return;
                }

                try
                {
                    var vm = await CreateResultViewModelAsync(result);

                    await Navigation.PushAsync(new IdentificationResultsPage(vm));
                }
                catch { return; }
            }
        }
Exemplo n.º 2
0
 public static async Task <ImagePrediction> ClassifyImageWithRetryAsync(this ICustomVisionPredictionClient predictionApi, Guid projectId, Func <Task <Stream> > imageStreamCallback, string publishedName)
 {
     return(await RunTaskWithAutoRetryOnQuotaLimitExceededError(async() => await predictionApi.ClassifyImageAsync(projectId, publishedName, await imageStreamCallback())));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Classify an image and saves the result.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='projectId'>
 /// The project id.
 /// </param>
 /// <param name='publishedName'>
 /// Specifies the name of the model to evaluate against.
 /// </param>
 /// <param name='imageData'>
 /// Binary image data. Supported formats are JPEG, GIF, PNG, and BMP. Supports
 /// images up to 4MB.
 /// </param>
 /// <param name='application'>
 /// Optional. Specifies the name of application using the endpoint.
 /// </param>
 public static ImagePrediction ClassifyImage(this ICustomVisionPredictionClient operations, System.Guid projectId, string publishedName, Stream imageData, string application = default(string))
 {
     return(operations.ClassifyImageAsync(projectId, publishedName, imageData, application).GetAwaiter().GetResult());
 }