Vision Image#

Image#

Image represented by either a URI or byte stream.

class google.cloud.vision.image.Image(client, content=None, filename=None, source_uri=None)[source]#

Bases: object

Image representation containing information to be annotate.

Parameters:
  • content (bytes) – Byte stream of an image.
  • filename (str) – Filename to image.
  • source_uri (str) – URL or Google Cloud Storage URI of image.
  • client (Client) – Instance of Vision client.
as_dict()[source]#

Generate dictionary structure for request.

Return type:dict
Returns:Dictionary with source information for image.
content#

Base64 encoded image content.

Return type:str
Returns:Base64 encoded image bytes.
detect(features)[source]#

Detect multiple feature types.

Parameters:features (list of Feature) – List of the Feature indication the type of annotation to perform.
Return type:list
Returns:List of EntityAnnotation.
detect_crop_hints(aspect_ratios=None, limit=10)[source]#

Detect crop hints in image.

Parameters:
  • aspect_ratios (list) – (Optional) List of floats i.e. 4/3 == 1.33333. A maximum of 16 aspect ratios can be given.
  • limit (int) – (Optional) The number of crop hints to detect.
Return type:

list

Returns:

List of CropHints.

detect_faces(limit=10)[source]#

Detect faces in image.

Parameters:limit (int) – The number of faces to try and detect.
Return type:list
Returns:List of Face.
detect_full_text(language_hints=None, limit=10)[source]#

Detect a full document’s text.

Parameters:
Return type:

list

Returns:

List of TextAnnotation.

detect_labels(limit=10)[source]#

Detect labels that describe objects in an image.

Parameters:limit (int) – The maximum number of labels to try and detect.
Return type:list
Returns:List of EntityAnnotation
detect_landmarks(limit=10)[source]#

Detect landmarks in an image.

Parameters:limit (int) – The maximum number of landmarks to find.
Return type:list
Returns:List of EntityAnnotation.
detect_logos(limit=10)[source]#

Detect logos in an image.

Parameters:limit (int) – The maximum number of logos to find.
Return type:list
Returns:List of EntityAnnotation.
detect_properties(limit=10)[source]#

Detect the color properties of an image.

Parameters:limit (int) – The maximum number of image properties to find.
Return type:list
Returns:List of ImagePropertiesAnnotation.

Retreive safe search properties from an image.

Parameters:limit (int) – The number of faces to try and detect.
Return type:list
Returns:List of SafeSearchAnnotation.
detect_text(limit=10)[source]#

Detect text in an image.

Parameters:limit (int) – The maximum instances of text to find.
Return type:list
Returns:List of EntityAnnotation.
detect_web(limit=10)[source]#

Detect similar images elsewhere on the web.

Parameters:limit (int) – The maximum instances of text to find.
Return type:list
Returns:List of EntityAnnotation.
source#

Google Cloud Storage URI.

Return type:str
Returns:String of Google Cloud Storage URI.

Geometry#

Geometry and other generic classes used by the Vision API.

class google.cloud.vision.geometry.Bounds(vertices)[source]#

Bases: google.cloud.vision.geometry.BoundsBase

A polygon boundry of the detected feature.

class google.cloud.vision.geometry.BoundsBase(vertices)[source]#

Bases: object

Base class for handling bounds with vertices.

Parameters:vertices (list of Vertex) – List of vertcies describing points on an image.
classmethod from_api_repr(vertices)[source]#

Factory: construct BoundsBase instance from Vision API response.

Parameters:vertices (dict) – List of vertices.
Return type:BoundsBase or None
Returns:Instance of BoundsBase with populated verticies or None.
classmethod from_pb(vertices)[source]#

Factory: construct BoundsBase instance from a protobuf response.

Parameters:vertices (BoundingPoly) – List of vertices.
Return type:BoundsBase or None
Returns:Instance of BoundsBase with populated verticies.
vertices#

List of vertices.

Return type:list of Vertex
Returns:List of populated vertices.
class google.cloud.vision.geometry.FDBounds(vertices)[source]#

Bases: google.cloud.vision.geometry.BoundsBase

The bounding polygon of just the skin portion of the face.

class google.cloud.vision.geometry.LocationInformation(latitude, longitude)[source]#

Bases: object

Representation of location information returned by the Vision API.

Parameters:
  • latitude (float) – Latitude coordinate of geographical location.
  • longitude (float) – Longitude coordinate of geographical location.
classmethod from_api_repr(location_info)[source]#

Factory: construct location information from Vision API response.

Parameters:location_info (dict) – Dictionary response of locations.
Return type:LocationInformation
Returns:LocationInformation with populated latitude and longitude.
classmethod from_pb(location_info)[source]#

Factory: construct location information from a protobuf response.

Parameters:location_info (LocationInfo) – Protobuf response with LocationInfo.
Return type:LocationInformation
Returns:LocationInformation with populated latitude and longitude.
latitude#

Latitude coordinate.

Return type:float
Returns:Latitude coordinate of location.
longitude#

Longitude coordinate.

Return type:float
Returns:Longitude coordinate of location.
class google.cloud.vision.geometry.Position(x_coordinate=None, y_coordinate=None, z_coordinate=None)[source]#

Bases: object

A 3D position in the image.

See: https://cloud.google.com/vision/docs/reference/rest/v1/images/annotate#Position

Parameters:
  • x_coordinate (float) – X position coordinate.
  • y_coordinate (float) – Y position coordinate.
  • z_coordinate (float) – Z position coordinate.
classmethod from_api_repr(position)[source]#

Factory: construct 3D position from API response.

Parameters:position (dict) – Dictionary with 3 axis position data.
Return type:Position
Returns:Position constructed with 3D points from API response.
classmethod from_pb(response_position)[source]#

Factory: construct 3D position from API response.

Return type:Position
Returns:Position constructed with 3D points from API response.
x_coordinate#

X position coordinate.

Return type:float
Returns:X position coordinate.
y_coordinate#

Y position coordinate.

Return type:float
Returns:Y position coordinate.
z_coordinate#

Z position coordinate.

Return type:float
Returns:Z position coordinate.
class google.cloud.vision.geometry.Vertex(x_coordinate=None, y_coordinate=None)[source]#

Bases: object

A vertex represents a 2D point in the image.

See: https://cloud.google.com/vision/docs/reference/rest/v1/images/annotate#Vertex

Parameters:
  • x_coordinate (float) – X position coordinate.
  • y_coordinate (float) – Y position coordinate.
x_coordinate#

X position coordinate.

Return type:float
Returns:X position coordinate.
y_coordinate#

Y position coordinate.

Return type:float
Returns:Y position coordinate.

Likelihood#

Likelihood constants returned from Vision API.

class google.cloud.vision.likelihood.Likelihood[source]#

Bases: enum.Enum

A representation of likelihood to give stable results across upgrades.

See: https://cloud.google.com/vision/docs/reference/rest/v1/images/annotate#likelihood

LIKELY = 'LIKELY'#
POSSIBLE = 'POSSIBLE'#
UNKNOWN = 'UNKNOWN'#
UNLIKELY = 'UNLIKELY'#
VERY_LIKELY = 'VERY_LIKELY'#
VERY_UNLIKELY = 'VERY_UNLIKELY'#