Get label percentages from Google Vision API

758 views Asked by At

I would like to use the Google Vision API for label detection. For this I am using a .NET library. This is my code:

        var client = ImageAnnotatorClient.Create();
        // Load the image file into memory
        var image = Image.FromFile("trui3.jpg");
        // Performs label detection on the image file
        var response = client.DetectLabels(image);
        foreach (var annotation in response)
        {
            if (annotation.Description != null)
                Console.WriteLine(annotation.Description);
        }
        Console.ReadKey();

It works very well. It displays all the labels. But on the Google website it also displays the percentages of the labels. See the image for an example.

How can I achieve this by using the .NET library?

Vision API from Google website.

1

There are 1 answers

0
Paul-Jan On BEST ANSWER

Annotations have a Score (see further down the C# example page), which falls in the [0,1] range.

if (annotation.Description != null)
{
  Console.WriteLine($"{annotation.Description} ({annotation.Score}");
}