|
| 1 | +# Copyright 2019 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | + |
| 16 | +def set_endpoint(): |
| 17 | + """Change your endpoint""" |
| 18 | + # [START vision_set_endpoint] |
| 19 | + from google.cloud import vision |
| 20 | + |
| 21 | + client_options = {'api_endpoint': 'eu-vision.googleapis.com:443'} |
| 22 | + |
| 23 | + client = vision.ImageAnnotatorClient(client_options=client_options) |
| 24 | + # [END vision_set_endpoint] |
| 25 | + image_source = vision.types.ImageSource( |
| 26 | + image_uri='gs://cloud-samples-data/vision/text/screen.jpg') |
| 27 | + image = vision.types.Image(source=image_source) |
| 28 | + |
| 29 | + response = client.text_detection(image=image) |
| 30 | + |
| 31 | + print('Texts:') |
| 32 | + for text in response.text_annotations: |
| 33 | + print('{}'.format(text.description)) |
| 34 | + |
| 35 | + vertices = (['({},{})'.format(vertex.x, vertex.y) |
| 36 | + for vertex in text.bounding_poly.vertices]) |
| 37 | + |
| 38 | + print('bounds: {}\n'.format(','.join(vertices))) |
| 39 | + |
| 40 | + |
| 41 | +if __name__ == '__main__': |
| 42 | + set_endpoint() |
0 commit comments