【问题标题】:Vision API C# - reading stored image's URL in AzureVision API C# - 在 Azure 中读取存储图像的 URL
【发布时间】:2016-12-25 02:44:41
【问题描述】:
    //If the user uploaded an image, read it, and send it to the Vision API
if (activity.Attachments.Any() && activity.Attachments.First().ContentType.Contains("image"))
{
   //stores image url (parsed from attachment or mess`enter code here`age)
   string uploadedImageUrl = activity.Attachments.First().ContentUrl; ;
   uploadedImageUrl = HttpUtility.UrlDecode(uploadedImageUrl.Substring(uploadedImageUrl.IndexOf("file=") + 5));

   using (Stream imageFileStream = File.OpenRead(uploadedImageUrl))
   {
       try
       {
            analysisResult = await visionClient.AnalyzeImageAsync(imageFileStream, visualFeatures);
       }
       catch (Exception e)
       {
            analysisResult = null; //on error, reset analysis result to null
       }
   }
}
//Else, if the user did not upload an image, determine if the message contains a url, and send it to the Vision API
else
{
    try
    {
        analysisResult = await visionClient.AnalyzeImageAsync(activity.Text, visualFeatures);
    }
    catch (Exception e)
    {
        analysisResult = null; //on error, reset analysis result to null
    }
}  

我正在尝试上面的代码。我从这里得到代码:https://docs.botframework.com/en-us/bot-intelligence/vision/#example-vision-bot

按原样,代码可以在本地运行时执行它可以执行的操作,但是在我将机器人发布到 Azure 并从那里运行后,从上传的文件中读取图像的 URL 不起作用。

我尝试通过将 Visual Studio 直接附加到我在 Azure 中发布的 webapp bot 来进行调试。看起来 webapp 无法从 Azure 服务器临时存储位置读取存储图像的 URL,或者无法访问临时存储位置。

这一行:

uploadedImageUrl = HttpUtility.UrlDecode(uploadedImageUrl.Substring(uploadedImageUrl.IndexOf("file=") + 5));

显示这个值: "https://bcattachmentsprod.blob.core.windows.net/at4984/Gv4cOx6OdSl-原创"

那么,这一行:

using (Stream imageFileStream = File.OpenRead(uploadedImageUrl))

将值更改为: "s://bcattachmentsprod.blob.core.windows.net/at4984/Gv4cOx6OdSl-original"

然后它就停止了。

有人遇到过这样的问题吗?我该如何解决这个问题?

谢谢!

【问题讨论】:

    标签: c# azure botframework microsoft-cognitive


    【解决方案1】:

    如果您有图像 URL,您应该简单地使用该 URL 调用 AnalyzeImageAsync,而不是像您一样创建流。 File 类应该用于本地驱动器/网络上的文件。通过创建流,您将图像下载到 VM 一次,然后将其上传到视觉服务,从而使工作加倍。

    【讨论】:

    • 发送图像的 URL 在本地和 Azure 中为此 sn-p 工作。我想知道是否有解决此问题的方法。嗯...
    • 还有什么问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-24
    • 2018-07-11
    • 2019-12-31
    • 1970-01-01
    • 2017-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多