首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >image = vision_client.image( AttributeError:'ImageAnnotatorClient‘对象没有属性'image’

image = vision_client.image( AttributeError:'ImageAnnotatorClient‘对象没有属性'image’
EN

Stack Overflow用户
提问于 2019-02-27 00:16:36
回答 2查看 2.2K关注 0票数 0
代码语言:javascript
运行
复制
import io,os

# Imports the Google Cloud client library
from google.cloud import vision
# Instantiates a client (Change the line below******)
vision_client = vision.ImageAnnotatorClient('my-key.json')   

# The name of the image file to annotate (Change the line below 'image_path.jpg' ******)
file_name = os.path.join(
    os.path.dirname(__file__),
    'image_path.jpg') 

# Loads the image into memory
with io.open(file_name, 'rb') as image_file:
    content = image_file.read()
    image = vision_client.image(
        content=content)

# Performs label detection on the image file
labels = image.detect_labels()

print('Labels:')
for label in labels:
    print(label.description)

windows上的python 3.6.5

这个代码示例给出了标题中提到的错误,有人知道如何修复它吗?

EN

回答 2

Stack Overflow用户

发布于 2019-05-31 09:43:03

这对我很有效:

代码语言:javascript
运行
复制
import io
import os
# Imports the Google Cloud client library
from google.cloud import vision
from google.cloud.vision import types
# Instantiates a client
client = vision.ImageAnnotatorClient()
# The name of the image file to annotate
file_name = os.path.join(
    os.path.dirname(__file__),
    'resources/wakeupcat.jpg')

# Loads the image into memory
with io.open(file_name, 'rb') as image_file:
    content = image_file.read()
image = types.Image(content=content)
# Performs label detection on the image file
response = client.label_detection(image=image)
labels = response.label_annotations
print('Labels:')
for label in labels:
    print(label.description)
票数 3
EN

Stack Overflow用户

发布于 2019-02-28 00:50:45

你的代码有一些错误,但我想我找到了所有的错误。

代码语言:javascript
运行
复制
import os, io
from google.cloud import vision

vision_client = vision.ImageAnnotatorClient('my-key.json')   

file_name = os.path.join(os.path.dirname(__file__),'image_path.jpg') 

with io.open(file_name, 'rb') as image_file:
    content = image_file.read()

labels = vision_client.label_detection({'content': content})
labels = labes.label_annotations()

print('Labels:')
for label in labels:
    print(label.description)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54889827

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档