【问题标题】:Bing Reverse Image search from URL必应从 URL 反向图像搜索
【发布时间】:2020-03-05 12:59:42
【问题描述】:

我正在尝试从图像 url 进行 bing 反向图像搜索,但我无法让它返回错误请求以外的任何内容。这是我的代码

var client = new VisualSearchClient(new ApiKeyServiceClientCredentials("cred"));
var req = System.Net.WebRequest.Create(imageUrl);
using Stream stream = req.GetResponse().GetResponseStream();
var visualSearchResults = client.Images.VisualSearchMethodAsync(image: stream, knowledgeRequest: (string)null).Result;

我也尝试过使用 WebClient

var client = new VisualSearchClient(new ApiKeyServiceClientCredentials("cred"));
WebClient wc = new WebClient();
using Stream s = wc.OpenRead(imageUrl);
var visualSearchResults = client.Images.VisualSearchMethodAsync(image: s, knowledgeRequest: (string)null).Result;

有谁知道我怎样才能做到这一点?

【问题讨论】:

  • 通过 Fiddler 之类的工具跟踪请求/响应,您应该能够看到有关您遇到的 Bad Request 错误的更多详细信息。
  • 文档说“如果在请求正文中传递图像二进制文件,则不需要 knowledgeRequest 参数”,但错误请求的详细信息显示 KnowledgeRequest 参数的值无效。如果我包含一个 VisualSearchRequest 对象而不是 null 作为 KnowledgeRequest 参数,我仍然会得到同样的错误。
  • 正如@GauravMantri所说,检查响应内容,它可能有更多关于错误的细节。我已经实现了与您类似的对 VisualSearch 的调用,但使用来自文件的流,并且效果很好

标签: azure microsoft-cognitive bing azure-cognitive-services


【解决方案1】:

我最终通过将图像下载到 MemoryStream 中使其工作

var ms = new MemoryStream(new WebClient().DownloadData(imageUrl));
var visualSearchResults = client.Images.VisualSearchMethodAsync(image: ms, knowledgeRequest: (string)null).Result;

【讨论】:

    猜你喜欢
    • 2011-10-16
    • 2010-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-10
    相关资源
    最近更新 更多