<reponame>sichoi85/rchoi-test-flask-app
import json

def detect_text(path):
    """Detects text in the file."""
    from google.cloud import vision
    import io
    client = vision.ImageAnnotatorClient()

    with io.open(path, 'rb') as image_file:
        content = image_file.read()

    image = vision.types.Image(content=content)
    response = client.text_detection(image=image)
    texts = response.text_annotations

    json_obj = dict()
    index = 0

    for text in texts:
        print("index:", index)
        print(text.description)
        json_obj[index] = text.description
        #print('\n"{}"'.format(text.description))
        index += 1
        vertices = (['({},{})'.format(vertex.x, vertex.y)
                    for vertex in text.bounding_poly.vertices])

        #print('bounds: {}'.format(','.join(vertices)))
    return json.dumps(json_obj)

    if response.error.message:
        raise Exception(
            '{}\nFor more info on error messages, check: '
            'https://cloud.google.com/apis/design/errors'.format(
                response.error.message))

import json

def detect_text(path):
    """Detects text in the file."""
    from google.cloud import vision
    import io
    client = vision.ImageAnnotatorClient()

    with io.open(path, 'rb') as image_file:
        content = image_file.read()

    image = vision.types.Image(content=content)
    response = client.text_detection(image=image)
    texts = response.text_annotations

    json_obj = dict()
    index = 0

    for text in texts:
        print("index:", index)
        print(text.description)
        json_obj[index] = text.description
        #print('\n"{}"'.format(text.description))
        index += 1
        vertices = (['({},{})'.format(vertex.x, vertex.y)
                    for vertex in text.bounding_poly.vertices])

        #print('bounds: {}'.format(','.join(vertices)))
    return json.dumps(json_obj)

    if response.error.message:
        raise Exception(
            '{}\nFor more info on error messages, check: '
            'https://cloud.google.com/apis/design/errors'.format(
                response.error.message))
Detects text in the file. #print('\n"{}"'.format(text.description)) #print('bounds: {}'.format(','.join(vertices)))