【问题标题】:How to send raw image data to MS Computer Vision API using R?如何使用 R 将原始图像数据发送到 MS Computer Vision API?
【发布时间】:2018-05-28 05:46:05
【问题描述】:

我正在使用计算机视觉 API 使用 R 进行手写分析。我可以在传递图像 URL 时得到结果。但我想将二进制图像数据传递给 API。那是什么格式?使用this link 使用在线控制台进行 POST 时。

选择 'application/octet-stream' 只会在请求正文中显示 [Binary Image Data]。我在[]["body":data] 中使用了base64 图像格式以及许多其他方式,但出现无效图像输入错误。 base64不正确吗?我需要转换成其他格式吗?

我在网上看到我们需要将图像作为 blob 传递。

我用来发布的 R 代码如下。目前您可以看到我在正文中使用 url,如何将本地 PC 存储中的图像作为 blob 传递到那里?

APIresponse = POST(url = cogapi,content_type('application/json'),add_headers(.headers = c('Ocp-Apim-Subscription-Key' = '*************************')),body=list(url = img_url),encode = "json")

【问题讨论】:

  • 它没有提到需要在 base64 中的图像 - 您是否尝试在后期操作中按原样发布二进制图像?你用什么代码来发帖?请将其添加到您的问题中。
  • 添加了上面的 POST 查询。目前它的应用程序/json,我正在使用一个 URL。我想将图像 blob 与 application/octet-straem 一起使用,但不知道如何在 R 中创建该 blob,然后在 POST 上方传递

标签: r ocr microsoft-cognitive handwriting-recognition


【解决方案1】:

以下是你在 cURL 中的做法:

curl -H "Ocp-Apim-Subscription-Key: 0123456789abcdef0123456789ABCDEF" -H "Content-Type: application/json" "ComputerVisionUrl" --data-binary @C:/Pictures/ImageToAnalyze.jpg

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多