8000 Add vision ocr set endpoint samples · mikeguzman/python-docs-samples@e3d53ae · GitHub
[go: up one dir, main page]

Skip to content

Commit e3d53ae

Browse files
committed
Add vision ocr set endpoint samples
1 parent 0499658 commit e3d53ae

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
import set_endpoint
16+
17+
18+
def test_set_endpoint(capsys):
19+
set_endpoint.set_endpoint()
20+
21+
out, _ = capsys.readouterr()
22+
assert 'System' in out
23+
assert 'bounds:' in out

0 commit comments

Comments
 (0)
0