Microsoft计算机视觉API返回404资源未找到

时间:2020-02-04 21:05:36

标签: c# azure computer-vision microsoft-cognitive azure-cognitive-services

我尝试使用下面的C#代码调用Azure的Computer Vision API,但收到以下响应:

{"code":"404","message":"Resource not found"}

有什么建议可以完成这项工作吗?

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; }

    }
}

网址:https://mycognitive1000.cognitiveservices.azure.com/

1 个答案:

答案 0 :(得分:1)

首先,欢迎来到SO!看来您已经从文档中复制了代码,而没有替换服务工作所需的占位符storageAccountKeyUrl...。例如,在您的情况下,在您的问题下发布的URL应该进入VisionUrl属性中,如下所示:

[VisionAnalysis(VisionKey = "YOUR_KEY", VisionUrl = "mycognitive1000.cognitiveservices.azure.com")]

存储帐户是一个Azure Blob Storage连接字符串。至于Vision Key和Url,您可以在官方文档的Computer Vision API上找到不错的教程和文档。本教程还介绍了如何将这些参数写在单独的配置文件中,这是最佳实践。