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

我们目前正在使用 google vision API 做一个 ocr 项目,其中图像返回一个文本值......但到目前为止我们只能做 1 张图像,是否可以做 10 张图像?我使用 python 并且此代码仅运行一个图像..谢谢


import os, io

from google.cloud import vision

from google.cloud.vision import types

import pandas as pd


os.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_annotations


df = 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])


猛跑小猪
浏览 108回答 1
1回答

跃然一笑

由于异步模式支持“TEXT_DETECTION”功能,因此可以离线使用批量图像注释。您可以在此处找到 Python 的示例代码,如您所见,需要为每个图像创建一个请求元素并将其添加到请求数组中:client = vision_v1.ImageAnnotatorClient()//image onesource1 = {"image_uri": image_uri_1}image1 = {"source": source1}features1 = [    {"type": enums.Feature.Type.LABEL_DETECTION},    {"type": enums.Feature.Type.IMAGE_PROPERTIES}]//image twosource2 = {"image_uri": image_uri_2}image2 = {"source": source2}features2 = [    {"type": enums.Feature.Type.LABEL_DETECTION}]# Each requests element corresponds to a single imagerequests = [{"image": image1, "features": features1}, {"image": image2, "features": features2}]gcs_destination = {"uri": output_uri}# The max number of responses to output in each JSON filebatch_size = 2output_config = {"gcs_destination": gcs_destination,                 "batch_size": batch_size}operation = client.async_batch_annotate_images(requests, output_config)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python