-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandToText.py
38 lines (28 loc) · 1.21 KB
/
handToText.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
import os, io
from google.cloud import vision
from google.cloud.vision import types
import base64
import pandas as pd
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = r'ServiceAccountToken.json'
client = vision.ImageAnnotatorClient()
FOLDER_PATH = r'/home/raghav/Desktop/Charting-API'
IMAGE_FILE = 'raghav2.jpg'
FILE_PATH = os.path.join(FOLDER_PATH, IMAGE_FILE)
with io.open(FILE_PATH, 'rb') as image_file:
content = image_file.read()
image = vision.types.Image(content=content)
response = client.document_text_detection(image=image)
docText = response.full_text_annotation.text
print(docText)
print(type(docText))
pages = response.full_text_annotation.pages
for page in pages:
for block in page.blocks:
print('block confidence:', block.confidence)
for paragraph in block.paragraphs:
print('paragraph confidence:', paragraph.confidence)
for word in paragraph.words:
word_text = ''.join([symbol.text for symbol in word.symbols])
print('Word text: {0} (confidence: {1}'.format(word_text, word.confidence))
for symbol in word.symbols:
print('\tSymbol: {0} (confidence: {1}'.format(symbol.text, symbol.confidence))