Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 是否可以使用google vision api一次扫描10幅ocr图像?到目前为止,我只做了1件事_Python_Google Cloud Platform_Ocr_Google Vision - Fatal编程技术网

Python 是否可以使用google vision api一次扫描10幅ocr图像?到目前为止,我只做了1件事

Python 是否可以使用google vision api一次扫描10幅ocr图像?到目前为止,我只做了1件事,python,google-cloud-platform,ocr,google-vision,Python,Google Cloud Platform,Ocr,Google Vision,我们目前正在使用google vision API进行ocr项目,其中图像返回文本值。。。但到目前为止,我们只制作了一张图片,是否可以制作10张图片?我正在使用python,这段代码只运行一个映像。。多谢各位 import os, io from google.cloud import vision from google.cloud.vision import types import pandas as pd os.environ['GOOGLE_APPLICATION_CREDENTIA

我们目前正在使用google vision API进行ocr项目,其中图像返回文本值。。。但到目前为止,我们只制作了一张图片,是否可以制作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])
可以使用,因为在异步模式下支持。您可以找到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)

非常感谢你的帮助。。。但是你能举一个小例子说明如何为每个图像创建一个请求元素并将其添加到请求数组中吗?我已经编辑了我的答案,其中显示了两个图像的示例。好的,谢谢你,先生。。。。但我能知道什么是图像uri、gcs目的地和批处理大小吗?