김태희

Add code for Text Detection

"""Detects text in the file."""
from google.cloud import vision
import io
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="C:/Users/User/Downloads/SmokeDetection-ab1773dcbc6a.json"
client = vision.ImageAnnotatorClient()
path = 'D:/Curricular/5-2/CapstoneDesign2/git/Prj/test01.jpg'
with io.open(path, 'rb') as image_file:
content = image_file.read()
image = vision.Image(content=content)
price_candidate = []
card_number_candidate = []
date_candidate = []
response = client.text_detection(image=image)
texts = response.text_annotations
print('Texts:')
for text in texts:
content = text.description
content = content.replace(',','')
print('\n"{}"'.format(content))
if response.error.message:
raise Exception(
'{}\nFor more info on error messages, check: '
'https://cloud.google.com/apis/design/errors'.format(
response.error.message))