2
votes

I am trying to use the Computer Vision .NET SDK to call Azure Cognitive Computer Vision Service API to analyse an image.

My code is below:

List<VisualFeatureTypes> features1 = new List<VisualFeatureTypes>()
{
    VisualFeatureTypes.Categories, VisualFeatureTypes.Description,
    VisualFeatureTypes.Faces, VisualFeatureTypes.ImageType,
    VisualFeatureTypes.Tags, VisualFeatureTypes.Adult,
    VisualFeatureTypes.Color, VisualFeatureTypes.Brands,
    VisualFeatureTypes.Objects
};

ComputerVisionClient client =
    new ComputerVisionClient(new ApiKeyServiceClientCredentials(key))
    { Endpoint = endpoint};
ImageAnalysis results = await client.AnalyzeImageAsync(imageUrl, features1);

I am getting the following error message:

cannot convert type 'system.collections.generic.List<microsoft.azure.cognitiveservices.vision.computervision.models.visualfeaturetypes>' to type 'system.collections.generic.IList<microsoft.azure.cognitiveservices.vision.computervision.models.visualfeaturetypes?>'.

screenshot for reference

Any ideas how to resolve it?

2
Can you please share link to the sample that you are trying.Ram-msft

2 Answers

0
votes

Here is the sample for computer vision SDK to analyze image using computer vision.

public static async Task<ImageAnalysis> AnalyzeImageAsync(this IComputerVisionClient operations, string url, IList<VisualFeatureTypes?> visualFeatures = default(IList<VisualFeatureTypes?>), IList<Details?> details = default(IList<Details?>), string language = default(string), IList<DescriptionExclude?> descriptionExclude = default(IList<DescriptionExclude?>), CancellationToken cancellationToken = default(CancellationToken))
            {
                using (var _result = await operations.AnalyzeImageWithHttpMessagesAsync(url, visualFeatures, details, language, descriptionExclude, null, cancellationToken).ConfigureAwait(false))
                {
                    return _result.Body;
                }
            }
0
votes

I was having the same problem with the cast to the nullable type. This seems to work:

IList<VisualFeatureTypes?> visualFeatures = new List<VisualFeatureTypes?>();
            visualFeatures.Add(VisualFeatureTypes.Description);
            visualFeatures.Add(VisualFeatureTypes.Categories);
            visualFeatures.Add(VisualFeatureTypes.Tags);
            visualFeatures.Add(VisualFeatureTypes.Faces);
            visualFeatures.Add(VisualFeatureTypes.Brands);
            visualFeatures.Add(VisualFeatureTypes.Objects);
            visualFeatures.Add(VisualFeatureTypes.ImageType);

            return vision.AnalyzeImageInStreamAsync(imageStream, visualFeatures).GetAwaiter().GetResult();