azure - 使用本地镜像进行 Read 3.0、Azure 认知服务、计算机视觉

标签 azure computer-vision azure-cognitive-services

我尝试在文本识别脚本中使用本地镜像,文档中有以下示例 ( https://learn.microsoft.com/en-us/azure/cognitive-services/computer-vision/quickstarts/python-hand-text ):

enter image description here

但是当我将 image_url 更改为本地文件路径时,它会发送 HTTPError: 400 Client Error: Bad Request for url。我尝试过遵循其他教程,但似乎没有任何效果。

任何帮助将不胜感激:)

最佳答案

认知服务 API 将无法通过本地计算机上文件的 URL 定位图像。相反,您可以使用请求正文中图像的二进制数据来调用相同的端点。

替换示例 Python 代码中的以下行

image_url = "https://raw.githubusercontent.com/MicrosoftDocs/azure-docs/master/articles/cognitive-services/Computer-vision/Images/readsample.jpg"

headers = {'Ocp-Apim-Subscription-Key': subscription_key}
data = {'url': image_url}
response = requests.post(
    text_recognition_url, headers=headers, json=data)

headers = {'Ocp-Apim-Subscription-Key': subscription_key,'Content-Type': 'application/octet-stream'}
with open('YOUR_LOCAL_IMAGE_FILE', 'rb') as f:
    data = f.read()
response = requests.post(
    text_recognition_url, headers=headers, data=data)

并替换以下行:

image = Image.open(BytesIO(requests.get(image_url).content))

image = Image.open('./YOUR_LOCAL_IMAGE_FILE.png')

关于azure - 使用本地镜像进行 Read 3.0、Azure 认知服务、计算机视觉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63907566/

相关文章:

c# - 如何用OpenCV进行图像光照校正?

azure - 错误: The received token is of incorrect token type -- What should the token look like?

javascript - Microsoft 语音服务 Javascript SDK 超时

azure - 有没有办法让应用服务设置使用 Key Vault secret ?

opencv - 在不使用关键点的情况下定位移动的对象

python - 摆脱 maxpooling 层会导致运行 cuda 内存错误 pytorch

Azure 翻译 API 调用正在返回并且 40100

azure - 是否可以在 Vercel 以外的平台上使用增量静态再生?

c# - P&P RetryPolicy,什么是 transient 异常

azure - 我可以为 Azure 应用服务实例设置不同的应用程序设置(ENV 变量)吗?