从网络摄像头发布图像到Azure Face Api [英] Posting An Image from Webcam to Azure Face Api

查看:117
本文介绍了从网络摄像头发布图像到Azure Face Api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将从网络摄像头获取的图像上传到Microsoft Azure Face Api.我从canvas.toDataUrl('image/png')中获得了包含数据Uri的图像.我将内容类型更改为application/octet-stream,将数据Uri附加到发布请求时,收到错误请求(400)无效的人脸图像.如果将附加数据更改为Blob,我将停止接收错误,但是我只会返回一个空数组,而不是JSON对象.我真的很感谢为我指明正确方向的任何帮助.

I am trying to upload an image that I get from my webcam to the Microsoft Azure Face Api. I get the image from canvas.toDataUrl(‘image/png’) which contains the Data Uri. I change the Content Type to application/octet-stream and when I attach the Data Uri to the post request, I get a Bad Request (400) Invalid Face Image. If I change the attached data to a Blob, I stop receiving errors however I only get back an empty array instead of a JSON object. I would really appreciate any help for pointing me in the right direction.

谢谢!

推荐答案

所以我最终通过将图像作为blob对象发送而得到了答案.您首先使用以下方法从画布上抓取图像:

So I got the answer finally by sending the image as a blob object. You first grab the image from canvas with:

let data = canvas.toDataURL('image/jpeg');

然后,您可以通过运行以下命令将其重新格式化为Blob数据对象:

Afterwards, you can reformat it to a blob data object by running:

fetch(data)
  .then(res => res.blob())
  .then(blobData => {
    // attach blobData as the data for the post request
  }

您还需要将发布请求的Content-Type切换为"application/octet-stream"

You will also need to switch the Content-Type of the post request to "application/octet-stream"

这篇关于从网络摄像头发布图像到Azure Face Api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆