Class ImageAnnotatorClient (0.40.0)

ImageAnnotatorClient(
    transport=None,
    channel=None,
    credentials=None,
    client_config=None,
    client_info=None,
    client_options=None,
)

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.

Inheritance

builtins.object > google.cloud.vision_helpers.VisionHelpers > builtins.object > google.cloud.vision_v1p3beta1.gapic.image_annotator_client.ImageAnnotatorClient > ImageAnnotatorClient

Methods

ImageAnnotatorClient

ImageAnnotatorClient(
    transport=None,
    channel=None,
    credentials=None,
    client_config=None,
    client_info=None,
    client_options=None,
)

Constructor.

Parameters
Name Description
channel grpc.Channel

DEPRECATED. A Channel instance through which to make calls. This argument is mutually exclusive with credentials; providing both will raise an exception.

credentials google.auth.credentials.Credentials

The authorization credentials to attach to requests. These credentials identify this application to the service. If none are specified, the client will attempt to ascertain the credentials from the environment. This argument is mutually exclusive with providing a transport instance to transport; doing so will raise an exception.

client_config dict

DEPRECATED. A dictionary of call options for each method. If not specified, the default configuration is used.

client_info google.api_core.gapic_v1.client_info.ClientInfo

The client info used to send a user-agent string along with API requests. If None, then default info will be used. Generally, you only need to set this if you're developing your own client library.

client_options Union[dict, google.api_core.client_options.ClientOptions]

Client options used to set user options on the client. API Endpoint should be set through client_options.

annotate_image

annotate_image(request, retry=None, timeout=None)

Run image detection and annotation for an image.

.. rubric:: Example

from google.cloud.vision_v1 import ImageAnnotatorClient client = ImageAnnotatorClient() request = { ... 'image': { ... 'source': {'image_uri': 'https://foo.com/image.jpg'}, ... }, ... } response = client.annotate_image(request)

Parameters
Name Description
retry Optional[google.api_core.retry.Retry]

A retry object used to retry requests. If None is specified, requests will not be retried.

timeout Optional[float]

The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

async_batch_annotate_files

async_batch_annotate_files(requests, retry=<object object>, timeout=<object object>, metadata=None)

Run asynchronous image detection and annotation for a list of generic files, such as PDF files, which may contain multiple pages and multiple images per page. Progress and results can be retrieved through the google.longrunning.Operations interface. Operation.metadata contains OperationMetadata (metadata). Operation.response contains AsyncBatchAnnotateFilesResponse (results).

.. rubric:: Example

from google.cloud import vision_v1p3beta1

client = vision_v1p3beta1.ImageAnnotatorClient()

TODO: Initialize requests:

requests = []

response = client.async_batch_annotate_files(requests)

def callback(operation_future): ... # Handle result. ... result = operation_future.result()

response.add_done_callback(callback)

Handle metadata.

metadata = response.metadata()

Parameters
Name Description
requests list[Union[dict, AsyncAnnotateFileRequest]]

Individual async file annotation requests for this batch. If a dict is provided, it must be of the same form as the protobuf message AsyncAnnotateFileRequest

retry Optional[google.api_core.retry.Retry]

A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

timeout Optional[float]

The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

metadata Optional[Sequence[Tuple[str, str]]]

Additional metadata that is provided to the method.

Exceptions
Type Description
google.api_core.exceptions.GoogleAPICallError If the request failed for any reason.
google.api_core.exceptions.RetryError If the request failed due to a retryable error and retry attempts failed.
ValueError If the parameters are invalid.

batch_annotate_images

batch_annotate_images(requests, retry=<object object>, timeout=<object object>, metadata=None)

Run image detection and annotation for a batch of images.

.. rubric:: Example

from google.cloud import vision_v1p3beta1

client = vision_v1p3beta1.ImageAnnotatorClient()

TODO: Initialize requests:

requests = []

response = client.batch_annotate_images(requests)

Parameters
Name Description
requests list[Union[dict, AnnotateImageRequest]]

Individual image annotation requests for this batch. If a dict is provided, it must be of the same form as the protobuf message AnnotateImageRequest

retry Optional[google.api_core.retry.Retry]

A retry object used to retry requests. If None is specified, requests will be retried using a default configuration.

timeout Optional[float]

The amount of time, in seconds, to wait for the request to complete. Note that if retry is specified, the timeout applies to each individual attempt.

metadata Optional[Sequence[Tuple[str, str]]]

Additional metadata that is provided to the method.

Exceptions
Type Description
google.api_core.exceptions.GoogleAPICallError If the request failed for any reason.
google.api_core.exceptions.RetryError If the request failed due to a retryable error and retry attempts failed.
ValueError If the parameters are invalid.

crop_hints

crop_hints(image, max_results=None, retry=None, timeout=None, **kwargs)

Return crop hints information.

Parameters
Name Description
kwargs dict

Additional properties to be set on the AnnotateImageRequest.

image Image

The image to analyze.

max_results int

Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

retry int

Number of retries to do before giving up.

timeout int

Number of seconds before timing out.

Returns
Type Description
AnnotateImageResponse The API response.

document_text_detection

document_text_detection(
    image, max_results=None, retry=None, timeout=None, **kwargs
)

Perform document text detection.

Parameters
Name Description
kwargs dict

Additional properties to be set on the AnnotateImageRequest.

image Image

The image to analyze.

max_results int

Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

retry int

Number of retries to do before giving up.

timeout int

Number of seconds before timing out.

Returns
Type Description
AnnotateImageResponse The API response.

face_detection

face_detection(image, max_results=None, retry=None, timeout=None, **kwargs)

Perform face detection.

Parameters
Name Description
kwargs dict

Additional properties to be set on the AnnotateImageRequest.

image Image

The image to analyze.

max_results int

Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

retry int

Number of retries to do before giving up.

timeout int

Number of seconds before timing out.

Returns
Type Description
AnnotateImageResponse The API response.

from_service_account_file

from_service_account_file(filename, *args, **kwargs)

Creates an instance of this client using the provided credentials file.

Parameter
Name Description
filename str

The path to the service account private key json file.

Returns
Type Description
ImageAnnotatorClient The constructed client.

from_service_account_json

from_service_account_json(filename, *args, **kwargs)

Creates an instance of this client using the provided credentials file.

Parameter
Name Description
filename str

The path to the service account private key json file.

Returns
Type Description
ImageAnnotatorClient The constructed client.

image_properties

image_properties(image, max_results=None, retry=None, timeout=None, **kwargs)

Return image properties information.

Parameters
Name Description
kwargs dict

Additional properties to be set on the AnnotateImageRequest.

image Image

The image to analyze.

max_results int

Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

retry int

Number of retries to do before giving up.

timeout int

Number of seconds before timing out.

Returns
Type Description
AnnotateImageResponse The API response.

label_detection

label_detection(image, max_results=None, retry=None, timeout=None, **kwargs)

Perform label detection.

Parameters
Name Description
kwargs dict

Additional properties to be set on the AnnotateImageRequest.

image Image

The image to analyze.

max_results int

Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

retry int

Number of retries to do before giving up.

timeout int

Number of seconds before timing out.

Returns
Type Description
AnnotateImageResponse The API response.

landmark_detection

landmark_detection(image, max_results=None, retry=None, timeout=None, **kwargs)

Perform landmark detection.

Parameters
Name Description
kwargs dict

Additional properties to be set on the AnnotateImageRequest.

image Image

The image to analyze.

max_results int

Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

retry int

Number of retries to do before giving up.

timeout int

Number of seconds before timing out.

Returns
Type Description
AnnotateImageResponse The API response.

logo_detection

logo_detection(image, max_results=None, retry=None, timeout=None, **kwargs)

Perform logo detection.

Parameters
Name Description
kwargs dict

Additional properties to be set on the AnnotateImageRequest.

image Image

The image to analyze.

max_results int

Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

retry int

Number of retries to do before giving up.

timeout int

Number of seconds before timing out.

Returns
Type Description
AnnotateImageResponse The API response.

object_localization

object_localization(image, max_results=None, retry=None, timeout=None, **kwargs)

Return object localization information.

Parameters
Name Description
kwargs dict

Additional properties to be set on the AnnotateImageRequest.

image Image

The image to analyze.

max_results int

Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

retry int

Number of retries to do before giving up.

timeout int

Number of seconds before timing out.

Returns
Type Description
AnnotateImageResponse The API response.
product_search(image, max_results=None, retry=None, timeout=None, **kwargs)

Return product search information.

Parameters
Name Description
kwargs dict

Additional properties to be set on the AnnotateImageRequest.

image Image

The image to analyze.

max_results int

Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

retry int

Number of retries to do before giving up.

timeout int

Number of seconds before timing out.

Returns
Type Description
AnnotateImageResponse The API response.

safe_search_detection

safe_search_detection(image, max_results=None, retry=None, timeout=None, **kwargs)

Perform safe search detection.

Parameters
Name Description
kwargs dict

Additional properties to be set on the AnnotateImageRequest.

image Image

The image to analyze.

max_results int

Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

retry int

Number of retries to do before giving up.

timeout int

Number of seconds before timing out.

Returns
Type Description
AnnotateImageResponse The API response.

text_detection

text_detection(image, max_results=None, retry=None, timeout=None, **kwargs)

Perform text detection.

Parameters
Name Description
kwargs dict

Additional properties to be set on the AnnotateImageRequest.

image Image

The image to analyze.

max_results int

Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

retry int

Number of retries to do before giving up.

timeout int

Number of seconds before timing out.

Returns
Type Description
AnnotateImageResponse The API response.

web_detection

web_detection(image, max_results=None, retry=None, timeout=None, **kwargs)

Perform web detection.

Parameters
Name Description
kwargs dict

Additional properties to be set on the AnnotateImageRequest.

image Image

The image to analyze.

max_results int

Number of results to return, does not apply for TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, or CROP_HINTS.

retry int

Number of retries to do before giving up.

timeout int

Number of seconds before timing out.

Returns
Type Description
AnnotateImageResponse The API response.