Skip to content

Commit 00a4c62

Browse files
Vision semi-GAPIC (#3373)
1 parent b59b854 commit 00a4c62

37 files changed

+5180
-808
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
include README.rst LICENSE
22
recursive-include google *.json *.proto
3-
recursive-include unit_tests *
3+
recursive-include tests *
44
global-exclude *.pyc __pycache__
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__import__('pkg_resources').declare_namespace(__name__)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__import__('pkg_resources').declare_namespace(__name__)

packages/google-cloud-vision/google/cloud/gapic/vision/v1/__init__.py

Whitespace-only changes.
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# Copyright 2016 Google Inc. All rights reserved.
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+
"""Wrappers for protocol buffer enum types."""
15+
16+
17+
class TextAnnotation(object):
18+
class DetectedBreak(object):
19+
class BreakType(object):
20+
"""
21+
Enum to denote the type of break found. New line, space etc.
22+
23+
Attributes:
24+
UNKNOWN (int): Unknown break label type.
25+
SPACE (int): Regular space.
26+
SURE_SPACE (int): Sure space (very wide).
27+
EOL_SURE_SPACE (int): Line-wrapping break.
28+
HYPHEN (int): End-line hyphen that is not present in text; does
29+
LINE_BREAK (int): not co-occur with SPACE, LEADER_SPACE, or
30+
LINE_BREAK.
31+
Line break that ends a paragraph.
32+
"""
33+
UNKNOWN = 0
34+
SPACE = 1
35+
SURE_SPACE = 2
36+
EOL_SURE_SPACE = 3
37+
HYPHEN = 4
38+
LINE_BREAK = 5
39+
40+
41+
class Block(object):
42+
class BlockType(object):
43+
"""
44+
Type of a block (text, image etc) as identified by OCR.
45+
46+
Attributes:
47+
UNKNOWN (int): Unknown block type.
48+
TEXT (int): Regular text block.
49+
TABLE (int): Table block.
50+
PICTURE (int): Image block.
51+
RULER (int): Horizontal/vertical line box.
52+
BARCODE (int): Barcode block.
53+
"""
54+
UNKNOWN = 0
55+
TEXT = 1
56+
TABLE = 2
57+
PICTURE = 3
58+
RULER = 4
59+
BARCODE = 5
60+
61+
62+
class Likelihood(object):
63+
"""
64+
A bucketized representation of likelihood, which is intended to give clients
65+
highly stable results across model upgrades.
66+
67+
Attributes:
68+
UNKNOWN (int): Unknown likelihood.
69+
VERY_UNLIKELY (int): It is very unlikely that the image belongs to the specified vertical.
70+
UNLIKELY (int): It is unlikely that the image belongs to the specified vertical.
71+
POSSIBLE (int): It is possible that the image belongs to the specified vertical.
72+
LIKELY (int): It is likely that the image belongs to the specified vertical.
73+
VERY_LIKELY (int): It is very likely that the image belongs to the specified vertical.
74+
"""
75+
UNKNOWN = 0
76+
VERY_UNLIKELY = 1
77+
UNLIKELY = 2
78+
POSSIBLE = 3
79+
LIKELY = 4
80+
VERY_LIKELY = 5
81+
82+
83+
class Feature(object):
84+
class Type(object):
85+
"""
86+
Type of image feature.
87+
88+
Attributes:
89+
TYPE_UNSPECIFIED (int): Unspecified feature type.
90+
FACE_DETECTION (int): Run face detection.
91+
LANDMARK_DETECTION (int): Run landmark detection.
92+
LOGO_DETECTION (int): Run logo detection.
93+
LABEL_DETECTION (int): Run label detection.
94+
TEXT_DETECTION (int): Run OCR.
95+
DOCUMENT_TEXT_DETECTION (int): Run dense text document OCR. Takes precedence when both
96+
DOCUMENT_TEXT_DETECTION and TEXT_DETECTION are present.
97+
SAFE_SEARCH_DETECTION (int): Run computer vision models to compute image safe-search properties.
98+
IMAGE_PROPERTIES (int): Compute a set of image properties, such as the image's dominant colors.
99+
CROP_HINTS (int): Run crop hints.
100+
WEB_DETECTION (int): Run web detection.
101+
"""
102+
TYPE_UNSPECIFIED = 0
103+
FACE_DETECTION = 1
104+
LANDMARK_DETECTION = 2
105+
LOGO_DETECTION = 3
106+
LABEL_DETECTION = 4
107+
TEXT_DETECTION = 5
108+
DOCUMENT_TEXT_DETECTION = 11
109+
SAFE_SEARCH_DETECTION = 6
110+
IMAGE_PROPERTIES = 7
111+
CROP_HINTS = 9
112+
WEB_DETECTION = 10
113+
114+
115+
class FaceAnnotation(object):
116+
class Landmark(object):
117+
class Type(object):
118+
"""
119+
Face landmark (feature) type.
120+
Left and right are defined from the vantage of the viewer of the image
121+
without considering mirror projections typical of photos. So, ``LEFT_EYE``,
122+
typically, is the person's right eye.
123+
124+
Attributes:
125+
UNKNOWN_LANDMARK (int): Unknown face landmark detected. Should not be filled.
126+
LEFT_EYE (int): Left eye.
127+
RIGHT_EYE (int): Right eye.
128+
LEFT_OF_LEFT_EYEBROW (int): Left of left eyebrow.
129+
RIGHT_OF_LEFT_EYEBROW (int): Right of left eyebrow.
130+
LEFT_OF_RIGHT_EYEBROW (int): Left of right eyebrow.
131+
RIGHT_OF_RIGHT_EYEBROW (int): Right of right eyebrow.
132+
MIDPOINT_BETWEEN_EYES (int): Midpoint between eyes.
133+
NOSE_TIP (int): Nose tip.
134+
UPPER_LIP (int): Upper lip.
135+
LOWER_LIP (int): Lower lip.
136+
MOUTH_LEFT (int): Mouth left.
137+
MOUTH_RIGHT (int): Mouth right.
138+
MOUTH_CENTER (int): Mouth center.
139+
NOSE_BOTTOM_RIGHT (int): Nose, bottom right.
140+
NOSE_BOTTOM_LEFT (int): Nose, bottom left.
141+
NOSE_BOTTOM_CENTER (int): Nose, bottom center.
142+
LEFT_EYE_TOP_BOUNDARY (int): Left eye, top boundary.
143+
LEFT_EYE_RIGHT_CORNER (int): Left eye, right corner.
144+
LEFT_EYE_BOTTOM_BOUNDARY (int): Left eye, bottom boundary.
145+
LEFT_EYE_LEFT_CORNER (int): Left eye, left corner.
146+
RIGHT_EYE_TOP_BOUNDARY (int): Right eye, top boundary.
147+
RIGHT_EYE_RIGHT_CORNER (int): Right eye, right corner.
148+
RIGHT_EYE_BOTTOM_BOUNDARY (int): Right eye, bottom boundary.
149+
RIGHT_EYE_LEFT_CORNER (int): Right eye, left corner.
150+
LEFT_EYEBROW_UPPER_MIDPOINT (int): Left eyebrow, upper midpoint.
151+
RIGHT_EYEBROW_UPPER_MIDPOINT (int): Right eyebrow, upper midpoint.
152+
LEFT_EAR_TRAGION (int): Left ear tragion.
153+
RIGHT_EAR_TRAGION (int): Right ear tragion.
154+
LEFT_EYE_PUPIL (int): Left eye pupil.
155+
RIGHT_EYE_PUPIL (int): Right eye pupil.
156+
FOREHEAD_GLABELLA (int): Forehead glabella.
157+
CHIN_GNATHION (int): Chin gnathion.
158+
CHIN_LEFT_GONION (int): Chin left gonion.
159+
CHIN_RIGHT_GONION (int): Chin right gonion.
160+
"""
161+
UNKNOWN_LANDMARK = 0
162+
LEFT_EYE = 1
163+
RIGHT_EYE = 2
164+
LEFT_OF_LEFT_EYEBROW = 3
165+
RIGHT_OF_LEFT_EYEBROW = 4
166+
LEFT_OF_RIGHT_EYEBROW = 5
167+
RIGHT_OF_RIGHT_EYEBROW = 6
168+
MIDPOINT_BETWEEN_EYES = 7
169+
NOSE_TIP = 8
170+
UPPER_LIP = 9
171+
LOWER_LIP = 10
172+
MOUTH_LEFT = 11
173+
MOUTH_RIGHT = 12
174+
MOUTH_CENTER = 13
175+
NOSE_BOTTOM_RIGHT = 14
176+
NOSE_BOTTOM_LEFT = 15
177+
NOSE_BOTTOM_CENTER = 16
178+
LEFT_EYE_TOP_BOUNDARY = 17
179+
LEFT_EYE_RIGHT_CORNER = 18
180+
LEFT_EYE_BOTTOM_BOUNDARY = 19
181+
LEFT_EYE_LEFT_CORNER = 20
182+
RIGHT_EYE_TOP_BOUNDARY = 21
183+
RIGHT_EYE_RIGHT_CORNER = 22
184+
RIGHT_EYE_BOTTOM_BOUNDARY = 23
185+
RIGHT_EYE_LEFT_CORNER = 24
186+
LEFT_EYEBROW_UPPER_MIDPOINT = 25
187+
RIGHT_EYEBROW_UPPER_MIDPOINT = 26
188+
LEFT_EAR_TRAGION = 27
189+
RIGHT_EAR_TRAGION = 28
190+
LEFT_EYE_PUPIL = 29
191+
RIGHT_EYE_PUPIL = 30
192+
FOREHEAD_GLABELLA = 31
193+
CHIN_GNATHION = 32
194+
CHIN_LEFT_GONION = 33
195+
CHIN_RIGHT_GONION = 34
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# Copyright 2017, Google Inc. All rights reserved.
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+
# EDITING INSTRUCTIONS
16+
# This file was generated from the file
17+
# https://github.com/google/googleapis/blob/master/google/cloud/vision/v1/image_annotator.proto,
18+
# and updates to that file get reflected here through a refresh process.
19+
# For the short term, the refresh process will only be runnable by Google engineers.
20+
#
21+
# The only allowed edits are to method and file documentation. A 3-way
22+
# merge preserves those additions if the generated source changes.
23+
"""Accesses the google.cloud.vision.v1 ImageAnnotator API."""
24+
25+
import collections
26+
import json
27+
import os
28+
import pkg_resources
29+
import platform
30+
31+
from google.gax import api_callable
32+
from google.gax import config
33+
from google.gax import path_template
34+
import google.gax
35+
36+
from google.cloud.gapic.vision.v1 import enums
37+
from google.cloud.proto.vision.v1 import image_annotator_pb2
38+
39+
40+
class ImageAnnotatorClient(object):
41+
"""Service that performs Google Cloud Vision API detection tasks over
42+
client images, such as face, landmark, logo, label, and text detection. The
43+
ImageAnnotator service returns detected entities from the images.
44+
"""
45+
46+
SERVICE_ADDRESS = 'vision.googleapis.com'
47+
"""The default address of the service."""
48+
49+
DEFAULT_SERVICE_PORT = 443
50+
"""The default port of the service."""
51+
52+
# The scopes needed to make gRPC calls to all of the methods defined in
53+
# this service
54+
_ALL_SCOPES = ('https://www.googleapis.com/auth/cloud-platform', )
55+
56+
def __init__(self,
57+
service_path=SERVICE_ADDRESS,
58+
port=DEFAULT_SERVICE_PORT,
59+
channel=None,
60+
credentials=None,
61+
ssl_credentials=None,
62+
scopes=None,
63+
client_config=None,
64+
app_name=None,
65+
app_version='',
66+
lib_name=None,
67+
lib_version='',
68+
metrics_headers=()):
69+
"""Constructor.
70+
71+
Args:
72+
service_path (string): The domain name of the API remote host.
73+
port (int): The port on which to connect to the remote host.
74+
channel (:class:`grpc.Channel`): A ``Channel`` instance through
75+
which to make calls.
76+
credentials (object): The authorization credentials to attach to
77+
requests. These credentials identify this application to the
78+
service.
79+
ssl_credentials (:class:`grpc.ChannelCredentials`): A
80+
``ChannelCredentials`` instance for use with an SSL-enabled
81+
channel.
82+
scopes (list[string]): A list of OAuth2 scopes to attach to requests.
83+
client_config (dict):
84+
A dictionary for call options for each method. See
85+
:func:`google.gax.construct_settings` for the structure of
86+
this data. Falls back to the default config if not specified
87+
or the specified config is missing data points.
88+
app_name (string): The name of the application calling
89+
the service. Recommended for analytics purposes.
90+
app_version (string): The version of the application calling
91+
the service. Recommended for analytics purposes.
92+
lib_name (string): The API library software used for calling
93+
the service. (Unless you are writing an API client itself,
94+
leave this as default.)
95+
lib_version (string): The API library software version used
96+
for calling the service. (Unless you are writing an API client
97+
itself, leave this as default.)
98+
metrics_headers (dict): A dictionary of values for tracking
99+
client library metrics. Ultimately serializes to a string
100+
(e.g. 'foo/1.2.3 bar/3.14.1'). This argument should be
101+
considered private.
102+
103+
Returns:
104+
A ImageAnnotatorClient object.
105+
"""
106+
# Unless the calling application specifically requested
107+
# OAuth scopes, request everything.
108+
if scopes is None:
109+
scopes = self._ALL_SCOPES
110+
111+
# Initialize an empty client config, if none is set.
112+
if client_config is None:
113+
client_config = {}
114+
115+
# Initialize metrics_headers as an ordered dictionary
116+
# (cuts down on cardinality of the resulting string slightly).
117+
metrics_headers = collections.OrderedDict(metrics_headers)
118+
metrics_headers['gl-python'] = platform.python_version()
119+
120+
# The library may or may not be set, depending on what is
121+
# calling this client. Newer client libraries set the library name
122+
# and version.
123+
if lib_name:
124+
metrics_headers[lib_name] = lib_version
125+
126+
# Finally, track the GAPIC package version.
127+
metrics_headers['gapic'] = pkg_resources.get_distribution(
128+
'google-cloud-vision', ).version
129+
130+
# Load the configuration defaults.
131+
default_client_config = json.loads(
132+
pkg_resources.resource_string(
133+
__name__, 'image_annotator_client_config.json').decode())
134+
defaults = api_callable.construct_settings(
135+
'google.cloud.vision.v1.ImageAnnotator',
136+
default_client_config,
137+
client_config,
138+
config.STATUS_CODE_NAMES,
139+
metrics_headers=metrics_headers, )
140+
self.image_annotator_stub = config.create_stub(
141+
image_annotator_pb2.ImageAnnotatorStub,
142+
channel=channel,
143+
service_path=service_path,
144+
service_port=port,
145+
credentials=credentials,
146+
scopes=scopes,
147+
ssl_credentials=ssl_credentials)
148+
149+
self._batch_annotate_images = api_callable.create_api_call(
150+
self.image_annotator_stub.BatchAnnotateImages,
151+
settings=defaults['batch_annotate_images'])
152+
153+
# Service calls
154+
def batch_annotate_images(self, requests, options=None):
155+
"""
156+
Run image detection and annotation for a batch of images.
157+
158+
Example:
159+
>>> from google.cloud.gapic.vision.v1 import image_annotator_client
160+
>>> client = image_annotator_client.ImageAnnotatorClient()
161+
>>> requests = []
162+
>>> response = client.batch_annotate_images(requests)
163+
164+
Args:
165+
requests (list[:class:`google.cloud.proto.vision.v1.image_annotator_pb2.AnnotateImageRequest`]): Individual image annotation requests for this batch.
166+
options (:class:`google.gax.CallOptions`): Overrides the default
167+
settings for this call, e.g, timeout, retries etc.
168+
169+
Returns:
170+
A :class:`google.cloud.proto.vision.v1.image_annotator_pb2.BatchAnnotateImagesResponse` instance.
171+
172+
Raises:
173+
:exc:`google.gax.errors.GaxError` if the RPC is aborted.
174+
:exc:`ValueError` if the parameters are invalid.
175+
"""
176+
# Create the request object.
177+
request = image_annotator_pb2.BatchAnnotateImagesRequest(
178+
requests=requests)
179+
return self._batch_annotate_images(request, options)

0 commit comments

Comments
 (0)