I tried to call Azure's Computer Vision API using the C# code below but got the following response:
{"code":"404","message":"Resource not found"}
Any advice to get this work?
using System;
using System.IO;
using System.Threading.Tasks;
using AzureFunctions.Extensions.CognitiveServices.Bindings.Vision.Analysis;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage.Table;
namespace myCognitiveFunction
{
public static class myCognitiveFunction
{
[FunctionName("myCognitiveFunction")]
public static async Task RunAsync(
[BlobTrigger("images/{name}", Connection = "storageAccount")]Stream myBlob,
[VisionAnalysis(VisionKey = "Key", VisionUrl = "Url")]VisionAnalysisClient visionClient,
[Table("VisionAnalysis", Connection = "storageAccount")]IAsyncCollector<VisionResult> results,
string name, ILogger log)
{
var request = new VisionAnalysisRequest(myBlob);
var result = await visionClient.AnalyzeAsync(request);
var visionResult = new VisionResult(Guid.NewGuid().ToString(), "VisionAnalysis") { ResultJson = result.ToString() };
await results.AddAsync(visionResult);
log.LogInformation($"Results: {result.ToString()}");
}
}
public class VisionResult : TableEntity
{
public VisionResult(string id, string partitionKey)
{
this.RowKey = id;
this.PartitionKey = partitionKey;
}
public string ResultJson { get; set; }
}
}
First, Welcome to SO! It seems you've copied the code from the documentation without replacing the placeholders namely storageAccount
,Key
,Url
... which are required for the service to work. For example, in your case, the URL posted under your question should go in the VisionUrl
property as follows:
[VisionAnalysis(VisionKey = "YOUR_KEY", VisionUrl = "mycognitive1000.cognitiveservices.azure.com")]
The storage account is an Azure Blob Storage connection string. As for the Vision Key and Url, you can find a good tutorial and documentation on the Computer Vision API in the official docs. The tutorial explains as well how to have those parameters written within a separate configuration file as a best practice.