为了账号安全,请及时绑定邮箱和手机立即绑定

是否可以使用 google vision api 一次扫描 10 张图像?到目前为止只做 1

是否可以使用 google vision api 一次扫描 10 张图像?到目前为止只做 1

猛跑小猪 2023-05-16 15:55:25
我们目前正在使用 google vision API 做一个 ocr 项目,其中图像返回一个文本值......但到目前为止我们只能做 1 张图像,是否可以做 10 张图像?我使用 python 并且此代码仅运行一个图像..谢谢import os, iofrom google.cloud import visionfrom google.cloud.vision import typesimport pandas as pdos.environ['GOOGLE_APPLICATION_CREDENTIALS'] = r'anjir.json'client = vision.ImageAnnotatorClient()FILE_NAME = 'receipttest2.jpg'FOLDER_PATH = r'C:\Users\Fadhlan\Desktop\Python venv\image\text'with io.open(os.path.join(FOLDER_PATH, FILE_NAME), 'rb') as image_file:    content = image_file.read()image = vision.types.Image(content=content)response = client.text_detection(image=image)texts = response.text_annotationsdf = pd.DataFrame(columns=['locale', 'description'])for text in texts:    df = df.append(        dict(            locale=text.locale,            description=text.description        ),        ignore_index=True    )print(df['description'][0])
查看完整描述

1 回答

?
跃然一笑

TA贡献1826条经验 获得超6个赞

由于异步模式支持“TEXT_DETECTION”功能,因此可以离线使用批量图像注释。您可以在此处找到 Python 的示例代码,如您所见,需要为每个图像创建一个请求元素并将其添加到请求数组中:

client = vision_v1.ImageAnnotatorClient()


//image one

source1 = {"image_uri": image_uri_1}

image1 = {"source": source1}

features1 = [

    {"type": enums.Feature.Type.LABEL_DETECTION},

    {"type": enums.Feature.Type.IMAGE_PROPERTIES}

]


//image two

source2 = {"image_uri": image_uri_2}

image2 = {"source": source2}

features2 = [

    {"type": enums.Feature.Type.LABEL_DETECTION}

]


# Each requests element corresponds to a single image

requests = [{"image": image1, "features": features1}, {"image": image2, "features": features2}]

gcs_destination = {"uri": output_uri}


# The max number of responses to output in each JSON file

batch_size = 2


output_config = {"gcs_destination": gcs_destination,

                 "batch_size": batch_size}

operation = client.async_batch_annotate_images(requests, output_config)


查看完整回答
反对 回复 2023-05-16
  • 1 回答
  • 0 关注
  • 101 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信