-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvision.py
More file actions
37 lines (26 loc) · 1.18 KB
/
vision.py
File metadata and controls
37 lines (26 loc) · 1.18 KB
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
import os, io
from google.cloud import vision
# from google.cloud.vision import types
# import pandas as pd
# os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = r'ServiceAccountToken.json'
client = vision.ImageAnnotatorClient()
FOLDER_PATH = r'/home/rohit/Work/DocAid/DocAid-API/'
IMAGE_FILE = 'rohit.jpeg'
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)
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))