-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogle_vision.py
34 lines (24 loc) · 1.02 KB
/
google_vision.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
import os
import io
from google.cloud import vision
def main():
client = vision.ImageAnnotatorClient()
file_name = os.path.abspath('app/uploads/18.png')
# Loads the image into memory
with io.open(file_name, 'rb') as image_file:
content = image_file.read()
image_context = vision.ImageContext(language_hints=["ja"])
image = vision.Image(content=content)
# Performs label detection on the image file
response = client.text_detection(image=image, image_context=image_context)
for i, block in enumerate(response.full_text_annotation.pages[0].blocks):
block_text = ""
for paragraph in block.paragraphs:
for word in paragraph.words:
block_text += "".join([symbol.text for symbol in word.symbols])
latest_vertices = word.bounding_box.vertices[0] #latest_vertices.x , latest_vertices.y
print(i, block_text, latest_vertices)
full_text = response.full_text_annotation.text
#print(full_text)
if __name__=="__main__":
main()