我如何为Google的visionapi设置超时

2024-05-23 20:15:11 发布

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

我正在使用Python对Google的visionapi进行查询以从图像中获取标签,但是我无法设置超时,以防在给定的时间内没有收到响应。

我使用以下基于调用选项的Google's Documentation的代码。

这是我的代码:

class GoogleQuery():

def __init__(self, VisionTools):
    self.client = vision.ImageAnnotatorClient()
    self.QueryOptions = google.gax.CallOptions(timeout=0.1)

... more init fields

def QueryImage(self, frame):
    image = types.Image(content=frame)

    # Make query to Google
    response = self.client.label_detection(image=image, options=self.QueryOptions)

我尝试过直接将这些论点传递给Google,但没有成功,比如:

^{pr2}$

Tags: 代码图像imageselfclientinitdefdocumentation