gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 23:25:29 25 4
gpt4 key购买 nike

我尝试在文本识别脚本中使用本地镜像,文档中有以下示例 ( 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com