김태희

Add code for Text Detection

1 +"""Detects text in the file."""
2 +from google.cloud import vision
3 +
4 +import io
5 +import os
6 +
7 +os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="C:/Users/User/Downloads/SmokeDetection-ab1773dcbc6a.json"
8 +client = vision.ImageAnnotatorClient()
9 +path = 'D:/Curricular/5-2/CapstoneDesign2/git/Prj/test01.jpg'
10 +
11 +with io.open(path, 'rb') as image_file:
12 + content = image_file.read()
13 +
14 +image = vision.Image(content=content)
15 +
16 +price_candidate = []
17 +card_number_candidate = []
18 +date_candidate = []
19 +
20 +response = client.text_detection(image=image)
21 +texts = response.text_annotations
22 +print('Texts:')
23 +
24 +for text in texts:
25 + content = text.description
26 + content = content.replace(',','')
27 + print('\n"{}"'.format(content))
28 +
29 +
30 +if response.error.message:
31 + raise Exception(
32 + '{}\nFor more info on error messages, check: '
33 + 'https://cloud.google.com/apis/design/errors'.format(
34 + response.error.message))