Google 的 Vision API 可以接受来自任何外部服务器的 URL 和 return 对该图像的响应吗?
Can Google's Vision API accept a URL from any external server and return a response on that image?
我已经能够 运行 Google 的视觉 API 在本地存储的图像上成功。但是,每当我 运行 我的脚本将图像存储在外部服务器上时。我收到一个错误。
import io
import os
from google.cloud import vision
vision_client = vision.Client()
file_name = "https://static.pexels.com/photos/36753/flower-purple-lical-blosso.jpg"
with io.open(file_name, 'rb') as image_file:
content = image_file.read()
image = vision_client.image(content=content, )
labels = image.detect_labels()
for label in labels:
print(label.description)
错误说
Traceback (most recent call last):
File "visionex.py", line 8, in <module>
with io.open(file_name, 'rb') as image_file:
IOError: [Errno 2] No such file or directory:
'https://static.pexels.com/photos/36753/flower-purple-lical-blosso.jpg'
你不应该在这里使用 io.open 尝试使用 requests 模块
import requests # the lib that handles the url stuff
data = requests.get(file_name)
content = data.content
您无法使用 io.open 函数打开远程文件。阅读有关用于处理对远程文件的请求的请求模块的更多信息。
我已经能够 运行 Google 的视觉 API 在本地存储的图像上成功。但是,每当我 运行 我的脚本将图像存储在外部服务器上时。我收到一个错误。
import io
import os
from google.cloud import vision
vision_client = vision.Client()
file_name = "https://static.pexels.com/photos/36753/flower-purple-lical-blosso.jpg"
with io.open(file_name, 'rb') as image_file:
content = image_file.read()
image = vision_client.image(content=content, )
labels = image.detect_labels()
for label in labels:
print(label.description)
错误说
Traceback (most recent call last):
File "visionex.py", line 8, in <module>
with io.open(file_name, 'rb') as image_file:
IOError: [Errno 2] No such file or directory:
'https://static.pexels.com/photos/36753/flower-purple-lical-blosso.jpg'
你不应该在这里使用 io.open 尝试使用 requests 模块
import requests # the lib that handles the url stuff
data = requests.get(file_name)
content = data.content
您无法使用 io.open 函数打开远程文件。阅读有关用于处理对远程文件的请求的请求模块的更多信息。