зеркало из
https://github.com/ssciwr/AMMICO.git
synced 2025-10-29 13:06:04 +02:00
28 строки
727 B
Python
28 строки
727 B
Python
from google.cloud import vision
|
|
import io
|
|
|
|
|
|
def detect_text(subdict):
|
|
"""Detects text in the file."""
|
|
|
|
path = subdict["filename"]
|
|
client = vision.ImageAnnotatorClient()
|
|
|
|
with io.open(path, "rb") as image_file:
|
|
content = image_file.read()
|
|
|
|
image = vision.Image(content=content)
|
|
|
|
response = client.text_detection(image=image)
|
|
texts = response.text_annotations
|
|
subdict = {"text": []}
|
|
for text in texts:
|
|
subdict["text"].append(text.description)
|
|
|
|
if response.error.message:
|
|
raise Exception(
|
|
"{}\nFor more info on error messages, check: "
|
|
"https://cloud.google.com/apis/design/errors".format(response.error.message)
|
|
)
|
|
return subdict
|