VISION 没有属性枚举

问题描述 投票:0回答:1

我正在尝试使用谷歌云视觉API来生成图像的标题。

我尝试使用以下代码来注释图像:

from google.cloud import vision
from google.cloud.vision_v1 import types


client = vision.ImageAnnotatorClient.from_service_account_json('service_account_key.json')

file_name = 'Images/man.jpg'
with open(file_name, 'rb') as image_file:
    content = image_file.read()

image = types.Image(content=content)
response = client.annotate_image({
    'image': image,
    'features': [{'type': vision.enums.Feature.Type.LABEL_DETECTION}]
})

captions = []
for annotation in response.label_annotations:
    captions.append(annotation.description)

print("Generated captions for the image:")
for caption in captions:
    print(caption)

我收到的错误是 '功能':[{'类型':vision.enums.Feature.Type.LABEL_DETECTION}] AttributeError:模块“google.cloud.vision”没有属性“enums”

python image google-cloud-vision
1个回答
0
投票

vision 是一个枚举,要访问 LABEL_DETECTION 值,可以直接使用`vision.Feature.Type.LABEL_DETECTION。

© www.soinside.com 2019 - 2024. All rights reserved.