使用Azure人脸识别API时,如何用colab目录替换URL?

2024-04-19 21:12:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我们在python3中的googlecolab上使用azurefaceapi。 它可以很好地用于url(web上的图像),但是我们不能让它在Colab中作为文件下载的本地文件上工作。 例如,我们无法读取本地Colab文件中的文件,例如以下路径: ImagePath='/content/Slide331.PNG'

   response = requests.post(face_api_url, params=params, headers=headers, json={"url": image_url}) 

如何更改json={“url”:image\u url} 到本地路径,例如ImagePath='/content/Slide331.PNG'??????你知道吗

我们试着去看蔚蓝请求.post文件和参数,但它没有提供任何具体信息。你知道吗

我们相信这些也需要改变:

   faces = response.json()

   image_file = BytesIO(requests.get(image_url).content)

这是ouf完整代码,上面是其中的元素:

''Python

def annotate_image(image_url):
   response = requests.post(face_api_url, params=params, headers=headers, json={"url": image_url}) 

   faces = response.json()

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


   plt.figure(figsize=(8,8))
   ax = plt.imshow(image, alpha=0.6)
   for face in faces:
      [HERE IS THE CODE TO PLOT FACES ON THE PICTURES WHICH WORKS WELL]

''

我们尝试将URL更改为本地路径,但没有成功: {'错误':{'代码':'无效URL','消息':'无效图像URL.}}


Tags: 文件image路径jsonurlresponseparamscontent