-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_google_part_2.py
43 lines (35 loc) · 1.17 KB
/
test_google_part_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import io
import os
import google
from google.cloud import vision
from google.cloud.vision import types
def detect_text():
"""Detects text in the file."""
from google.cloud import vision
import io
client = vision.ImageAnnotatorClient()
file_name = os.path.abspath('screenshot.png')
with io.open(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
print('Response:')
print(texts)
print('Texts:')
print(texts[0].description)
sample=[]
for text in texts:
sample+=[text.description]
print(sample)
for text in texts:
print('\n"{}"'.format(text.description))
vertices = (['({},{})'.format(vertex.x, vertex.y)
for vertex in text.bounding_poly.vertices])
print('bounds: {}'.format(','.join(vertices)))
if response.error.message:
raise Exception(
'{}\nFor more info on error messages, check: '
'https://cloud.google.com/apis/design/errors'.format(
response.error.message))
detect_text()