-
Notifications
You must be signed in to change notification settings - Fork 7
/
visionapiocr.py
38 lines (28 loc) · 982 Bytes
/
visionapiocr.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 json
import requests
import io
import os
# Imports the Google Cloud client library
from google.cloud import vision
from google.cloud.vision import types
def detect_text(path):
"""Detects text in the file."""
client = vision.ImageAnnotatorClient()
with io.open(path, 'rb') as image_file:
content = image_file.read()
image = types.Image(content=content)
response = client.text_detection(image=image)
texts = response.text_annotations
#print(texts)
print('Texts:')
for text in texts:
a=("{}".format(text.description))
print(a)
#vertices = (['({},{})'.format(vertex.x, vertex.y)
# for vertex in text.bounding_poly.vertices])
#print('bounds: {}'.format(','.join(vertices)))'''
print((a))
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = '' #give path to your Service account keys .json file
bq_client = Client()
path='' #give path to your image
detect_text(path)