Python3-Landmark类的方法? Landmark.getType已在文档中列出,但不起作用

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

我正在尝试了解Google Vision API,并且正在使用一些python代码。当我尝试提取地标的类型时,找不到正确的方法。

我能找到的最好的documentation是Java,其中getType()被列为方法。

这里是带有输出的试用代码:

from google.cloud import vision
import pickle
import inspect

client = vision.ImageAnnotatorClient()

response = client.annotate_image({ 
    'image': {'source': {'image_uri': 'gs://bsa-test-bucket/2020-04-28 19.54.21.jpg'}},
    'features': [{'type': vision.enums.Feature.Type.FACE_DETECTION}, 
                {'type' : vision.enums.Feature.Type.LABEL_DETECTION}],})


for face in response.face_annotations:

    for i, lm in enumerate(face.landmarks):
        print(i, 'landmark_annotations type', type(lm), '\n')
        print(inspect.getmembers(lm))
        print(lm.getType())

输出:

> 0 landmark_annotations type <class
> 'google.cloud.vision_v1.proto.image_annotator_pb2.Landmark'> 
> 
> [('_SetListener', <bound method Message._SetListener of type: LEFT_EYE
> position {   x: 1198.06494140625   y: 1629.644287109375   z:
> -0.0032958984375 }
> >), ('__getstate__', <bound method Message.__getstate__ of type: LEFT_EYE position {   x: 1198.06494140625   y: 1629.644287109375   z:
> -0.0032958984375 }
> >)] 

Traceback (most recent call last):   File "src/gv-test.py", line 18, in <module>
    >     print(lm.getType()) AttributeError: getType

什么是正确的方法,在哪里可以找到用Python实现的类的文档?

谢谢!

google-api python-3.7 google-vision
1个回答
0
投票

我找到了。它是一个属性。

response.face_annotations[0].type

返回正确的类型常量。

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