【发布时间】:2020-12-01 21:18:07
【问题描述】:
我们目前正在使用谷歌视觉 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])
【问题讨论】:
标签: python google-cloud-platform ocr google-vision