0

Im trying to use Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction feature by submitting an image by using pickphoto cross media and geting a result of a predicition. I have tried to pass the image as url or a stream and keep getting a badrequest. I know that I have the correct prediction key and endpoint because i works for training telling me is the way I pass the image into the method. What is the correct way to transform the image from Cross Media pick photo package into the

private async void UplodatePictureButton_Clicked(object sender, EventArgs e)
{
    await CrossMedia.Current.Initialize();
    MediaFile file;
    if (!CrossMedia.Current.IsPickPhotoSupported)
    {
        await DisplayAlert("No upload", "Picking a photo is not supported", "OK");
        return;

    }
    file = await CrossMedia.Current.PickPhotoAsync();
    if (file == null)
    {
        return;
    }

    MainImage.Source = ImageSource.FromStream(() =>
    {
        var stream = file.GetStream();

        return stream;
    });


    // Create the Api, passing in the training key
    CustomVisionTrainingClient trainingApi = new CustomVisionTrainingClient()
    {
        ApiKey = trainingKey,
        Endpoint = SouthCentralUsEndpointTraining
    };
    var projects = trainingApi.GetProjects();
    var project = projects.FirstOrDefault(p => p.Name == "Car");
    CustomVisionPredictionClient endpoint = new CustomVisionPredictionClient()
    {
        ApiKey = predictionKey,
        Endpoint = SouthCentralUsEndpointPrediction
    };


    var result = endpoint.ClassifyImageUrl(project.Id, project.Name, new Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.Models.ImageUrl(file.Path));



    foreach (var c in result.Predictions)
    {
        Console.WriteLine($"\t{c.TagName}: {c.Probability:P1}");
    }


}

Unhandled Exception: Microsoft.Azure.CognitiveService.Vision.CustomerVision.Prediction.Models.CustomVisionErrorException: Operation returned an invalid status code "BadRequest" Expect a prediction.

Here is the picture of the code: code Here is the picture of the problem: problem

AskYous
  • 4,332
  • 9
  • 46
  • 82

1 Answers1

2

I got the same "Bad Request Message" while trying to do a endpoint.DetectImage(projectId, iteractionName, stream). The thing is that last week it was working Perfect. I have noticed that it only happens with large images arround 2 mb