是否可以使用Google Vision API一次扫描10张图像?到目前为止,只做1次 [英] is it possible to scan 10 images at once ocr using google vision api? so far manage to do only 1

查看:51
本文介绍了是否可以使用Google Vision API一次扫描10张图像?到目前为止,只做1次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们当前正在使用google vision API进行ocr项目,其中图像返回文本值...但是到目前为止,我们仅能处理1张图像,是否可以处理10张图像?即时通讯使用python,此代码仅运行一张图片..谢谢

We are currently doing an ocr project using google vision API where the images return a text value... but so far we manage to do only 1 image, is it possible to do 10 images? im using python and this code only runs one image.. thank you

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

推荐答案

可以使用批处理图像离线注释,因为" TEXT_DETECTION&qu​​ot;功能在异步模式下受支持.您可以在此处中找到的Python示例代码.,则需要为每个图像创建一个request元素并将其添加到请求数组中:

It's possible using batch image annotation offline since the "TEXT_DETECTION" feature is supported in the asynchronous mode. You can find a sample code for Python in here and as you can see there, it's required to create a request element for each image and add it to the array of requests:

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)

这篇关于是否可以使用Google Vision API一次扫描10张图像?到目前为止,只做1次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆