Skip to content

Commit

Permalink
Vision semi-GAPIC (#3373)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukesneeringer authored Jun 2, 2017
1 parent b59b854 commit 00a4c62
Show file tree
Hide file tree
Showing 37 changed files with 5,180 additions and 808 deletions.
2 changes: 1 addition & 1 deletion packages/google-cloud-vision/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include README.rst LICENSE
recursive-include google *.json *.proto
recursive-include unit_tests *
recursive-include tests *
global-exclude *.pyc __pycache__
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
Empty file.
195 changes: 195 additions & 0 deletions packages/google-cloud-vision/google/cloud/gapic/vision/v1/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# Copyright 2016 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Wrappers for protocol buffer enum types."""


class TextAnnotation(object):
class DetectedBreak(object):
class BreakType(object):
"""
Enum to denote the type of break found. New line, space etc.
Attributes:
UNKNOWN (int): Unknown break label type.
SPACE (int): Regular space.
SURE_SPACE (int): Sure space (very wide).
EOL_SURE_SPACE (int): Line-wrapping break.
HYPHEN (int): End-line hyphen that is not present in text; does
LINE_BREAK (int): not co-occur with SPACE, LEADER_SPACE, or
LINE_BREAK.
Line break that ends a paragraph.
"""
UNKNOWN = 0
SPACE = 1
SURE_SPACE = 2
EOL_SURE_SPACE = 3
HYPHEN = 4
LINE_BREAK = 5


class Block(object):
class BlockType(object):
"""
Type of a block (text, image etc) as identified by OCR.
Attributes:
UNKNOWN (int): Unknown block type.
TEXT (int): Regular text block.
TABLE (int): Table block.
PICTURE (int): Image block.
RULER (int): Horizontal/vertical line box.
BARCODE (int): Barcode block.
"""
UNKNOWN = 0
TEXT = 1
TABLE = 2
PICTURE = 3
RULER = 4
BARCODE = 5


class Likelihood(object):
"""
A bucketized representation of likelihood, which is intended to give clients
highly stable results across model upgrades.
Attributes:
UNKNOWN (int): Unknown likelihood.
VERY_UNLIKELY (int): It is very unlikely that the image belongs to the specified vertical.
UNLIKELY (int): It is unlikely that the image belongs to the specified vertical.
POSSIBLE (int): It is possible that the image belongs to the specified vertical.
LIKELY (int): It is likely that the image belongs to the specified vertical.
VERY_LIKELY (int): It is very likely that the image belongs to the specified vertical.
"""
UNKNOWN = 0
VERY_UNLIKELY = 1
UNLIKELY = 2
POSSIBLE = 3
LIKELY = 4
VERY_LIKELY = 5


class Feature(object):
class Type(object):
"""
Type of image feature.
Attributes:
TYPE_UNSPECIFIED (int): Unspecified feature type.
FACE_DETECTION (int): Run face detection.
LANDMARK_DETECTION (int): Run landmark detection.
LOGO_DETECTION (int): Run logo detection.
LABEL_DETECTION (int): Run label detection.
TEXT_DETECTION (int): Run OCR.
DOCUMENT_TEXT_DETECTION (int): Run dense text document OCR. Takes precedence when both
DOCUMENT_TEXT_DETECTION and TEXT_DETECTION are present.
SAFE_SEARCH_DETECTION (int): Run computer vision models to compute image safe-search properties.
IMAGE_PROPERTIES (int): Compute a set of image properties, such as the image's dominant colors.
CROP_HINTS (int): Run crop hints.
WEB_DETECTION (int): Run web detection.
"""
TYPE_UNSPECIFIED = 0
FACE_DETECTION = 1
LANDMARK_DETECTION = 2
LOGO_DETECTION = 3
LABEL_DETECTION = 4
TEXT_DETECTION = 5
DOCUMENT_TEXT_DETECTION = 11
SAFE_SEARCH_DETECTION = 6
IMAGE_PROPERTIES = 7
CROP_HINTS = 9
WEB_DETECTION = 10


class FaceAnnotation(object):
class Landmark(object):
class Type(object):
"""
Face landmark (feature) type.
Left and right are defined from the vantage of the viewer of the image
without considering mirror projections typical of photos. So, ``LEFT_EYE``,
typically, is the person's right eye.
Attributes:
UNKNOWN_LANDMARK (int): Unknown face landmark detected. Should not be filled.
LEFT_EYE (int): Left eye.
RIGHT_EYE (int): Right eye.
LEFT_OF_LEFT_EYEBROW (int): Left of left eyebrow.
RIGHT_OF_LEFT_EYEBROW (int): Right of left eyebrow.
LEFT_OF_RIGHT_EYEBROW (int): Left of right eyebrow.
RIGHT_OF_RIGHT_EYEBROW (int): Right of right eyebrow.
MIDPOINT_BETWEEN_EYES (int): Midpoint between eyes.
NOSE_TIP (int): Nose tip.
UPPER_LIP (int): Upper lip.
LOWER_LIP (int): Lower lip.
MOUTH_LEFT (int): Mouth left.
MOUTH_RIGHT (int): Mouth right.
MOUTH_CENTER (int): Mouth center.
NOSE_BOTTOM_RIGHT (int): Nose, bottom right.
NOSE_BOTTOM_LEFT (int): Nose, bottom left.
NOSE_BOTTOM_CENTER (int): Nose, bottom center.
LEFT_EYE_TOP_BOUNDARY (int): Left eye, top boundary.
LEFT_EYE_RIGHT_CORNER (int): Left eye, right corner.
LEFT_EYE_BOTTOM_BOUNDARY (int): Left eye, bottom boundary.
LEFT_EYE_LEFT_CORNER (int): Left eye, left corner.
RIGHT_EYE_TOP_BOUNDARY (int): Right eye, top boundary.
RIGHT_EYE_RIGHT_CORNER (int): Right eye, right corner.
RIGHT_EYE_BOTTOM_BOUNDARY (int): Right eye, bottom boundary.
RIGHT_EYE_LEFT_CORNER (int): Right eye, left corner.
LEFT_EYEBROW_UPPER_MIDPOINT (int): Left eyebrow, upper midpoint.
RIGHT_EYEBROW_UPPER_MIDPOINT (int): Right eyebrow, upper midpoint.
LEFT_EAR_TRAGION (int): Left ear tragion.
RIGHT_EAR_TRAGION (int): Right ear tragion.
LEFT_EYE_PUPIL (int): Left eye pupil.
RIGHT_EYE_PUPIL (int): Right eye pupil.
FOREHEAD_GLABELLA (int): Forehead glabella.
CHIN_GNATHION (int): Chin gnathion.
CHIN_LEFT_GONION (int): Chin left gonion.
CHIN_RIGHT_GONION (int): Chin right gonion.
"""
UNKNOWN_LANDMARK = 0
LEFT_EYE = 1
RIGHT_EYE = 2
LEFT_OF_LEFT_EYEBROW = 3
RIGHT_OF_LEFT_EYEBROW = 4
LEFT_OF_RIGHT_EYEBROW = 5
RIGHT_OF_RIGHT_EYEBROW = 6
MIDPOINT_BETWEEN_EYES = 7
NOSE_TIP = 8
UPPER_LIP = 9
LOWER_LIP = 10
MOUTH_LEFT = 11
MOUTH_RIGHT = 12
MOUTH_CENTER = 13
NOSE_BOTTOM_RIGHT = 14
NOSE_BOTTOM_LEFT = 15
NOSE_BOTTOM_CENTER = 16
LEFT_EYE_TOP_BOUNDARY = 17
LEFT_EYE_RIGHT_CORNER = 18
LEFT_EYE_BOTTOM_BOUNDARY = 19
LEFT_EYE_LEFT_CORNER = 20
RIGHT_EYE_TOP_BOUNDARY = 21
RIGHT_EYE_RIGHT_CORNER = 22
RIGHT_EYE_BOTTOM_BOUNDARY = 23
RIGHT_EYE_LEFT_CORNER = 24
LEFT_EYEBROW_UPPER_MIDPOINT = 25
RIGHT_EYEBROW_UPPER_MIDPOINT = 26
LEFT_EAR_TRAGION = 27
RIGHT_EAR_TRAGION = 28
LEFT_EYE_PUPIL = 29
RIGHT_EYE_PUPIL = 30
FOREHEAD_GLABELLA = 31
CHIN_GNATHION = 32
CHIN_LEFT_GONION = 33
CHIN_RIGHT_GONION = 34
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# Copyright 2017, Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# EDITING INSTRUCTIONS
# This file was generated from the file
# https://github.com/google/googleapis/blob/master/google/cloud/vision/v1/image_annotator.proto,
# and updates to that file get reflected here through a refresh process.
# For the short term, the refresh process will only be runnable by Google engineers.
#
# The only allowed edits are to method and file documentation. A 3-way
# merge preserves those additions if the generated source changes.
"""Accesses the google.cloud.vision.v1 ImageAnnotator API."""

import collections
import json
import os
import pkg_resources
import platform

from google.gax import api_callable
from google.gax import config
from google.gax import path_template
import google.gax

from google.cloud.gapic.vision.v1 import enums
from google.cloud.proto.vision.v1 import image_annotator_pb2


class ImageAnnotatorClient(object):
"""Service that performs Google Cloud Vision API detection tasks over
client images, such as face, landmark, logo, label, and text detection. The
ImageAnnotator service returns detected entities from the images.
"""

SERVICE_ADDRESS = 'vision.googleapis.com'
"""The default address of the service."""

DEFAULT_SERVICE_PORT = 443
"""The default port of the service."""

# The scopes needed to make gRPC calls to all of the methods defined in
# this service
_ALL_SCOPES = ('https://www.googleapis.com/auth/cloud-platform', )

def __init__(self,
service_path=SERVICE_ADDRESS,
port=DEFAULT_SERVICE_PORT,
channel=None,
credentials=None,
ssl_credentials=None,
scopes=None,
client_config=None,
app_name=None,
app_version='',
lib_name=None,
lib_version='',
metrics_headers=()):
"""Constructor.
Args:
service_path (string): The domain name of the API remote host.
port (int): The port on which to connect to the remote host.
channel (:class:`grpc.Channel`): A ``Channel`` instance through
which to make calls.
credentials (object): The authorization credentials to attach to
requests. These credentials identify this application to the
service.
ssl_credentials (:class:`grpc.ChannelCredentials`): A
``ChannelCredentials`` instance for use with an SSL-enabled
channel.
scopes (list[string]): A list of OAuth2 scopes to attach to requests.
client_config (dict):
A dictionary for call options for each method. See
:func:`google.gax.construct_settings` for the structure of
this data. Falls back to the default config if not specified
or the specified config is missing data points.
app_name (string): The name of the application calling
the service. Recommended for analytics purposes.
app_version (string): The version of the application calling
the service. Recommended for analytics purposes.
lib_name (string): The API library software used for calling
the service. (Unless you are writing an API client itself,
leave this as default.)
lib_version (string): The API library software version used
for calling the service. (Unless you are writing an API client
itself, leave this as default.)
metrics_headers (dict): A dictionary of values for tracking
client library metrics. Ultimately serializes to a string
(e.g. 'foo/1.2.3 bar/3.14.1'). This argument should be
considered private.
Returns:
A ImageAnnotatorClient object.
"""
# Unless the calling application specifically requested
# OAuth scopes, request everything.
if scopes is None:
scopes = self._ALL_SCOPES

# Initialize an empty client config, if none is set.
if client_config is None:
client_config = {}

# Initialize metrics_headers as an ordered dictionary
# (cuts down on cardinality of the resulting string slightly).
metrics_headers = collections.OrderedDict(metrics_headers)
metrics_headers['gl-python'] = platform.python_version()

# The library may or may not be set, depending on what is
# calling this client. Newer client libraries set the library name
# and version.
if lib_name:
metrics_headers[lib_name] = lib_version

# Finally, track the GAPIC package version.
metrics_headers['gapic'] = pkg_resources.get_distribution(
'google-cloud-vision', ).version

# Load the configuration defaults.
default_client_config = json.loads(
pkg_resources.resource_string(
__name__, 'image_annotator_client_config.json').decode())
defaults = api_callable.construct_settings(
'google.cloud.vision.v1.ImageAnnotator',
default_client_config,
client_config,
config.STATUS_CODE_NAMES,
metrics_headers=metrics_headers, )
self.image_annotator_stub = config.create_stub(
image_annotator_pb2.ImageAnnotatorStub,
channel=channel,
service_path=service_path,
service_port=port,
credentials=credentials,
scopes=scopes,
ssl_credentials=ssl_credentials)

self._batch_annotate_images = api_callable.create_api_call(
self.image_annotator_stub.BatchAnnotateImages,
settings=defaults['batch_annotate_images'])

# Service calls
def batch_annotate_images(self, requests, options=None):
"""
Run image detection and annotation for a batch of images.
Example:
>>> from google.cloud.gapic.vision.v1 import image_annotator_client
>>> client = image_annotator_client.ImageAnnotatorClient()
>>> requests = []
>>> response = client.batch_annotate_images(requests)
Args:
requests (list[:class:`google.cloud.proto.vision.v1.image_annotator_pb2.AnnotateImageRequest`]): Individual image annotation requests for this batch.
options (:class:`google.gax.CallOptions`): Overrides the default
settings for this call, e.g, timeout, retries etc.
Returns:
A :class:`google.cloud.proto.vision.v1.image_annotator_pb2.BatchAnnotateImagesResponse` instance.
Raises:
:exc:`google.gax.errors.GaxError` if the RPC is aborted.
:exc:`ValueError` if the parameters are invalid.
"""
# Create the request object.
request = image_annotator_pb2.BatchAnnotateImagesRequest(
requests=requests)
return self._batch_annotate_images(request, options)
Loading

0 comments on commit 00a4c62

Please sign in to comment.