Class ImageAnnotatorClient (0.39.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_v1p2beta1.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
NameDescription
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
NameDescription
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 async image detection and annotation for a list of generic files (e.g. PDF) 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_v1p2beta1

client = vision_v1p2beta1.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
NameDescription
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
TypeDescription
google.api_core.exceptions.GoogleAPICallErrorIf the request failed for any reason.
google.api_core.exceptions.RetryErrorIf the request failed due to a retryable error and retry attempts failed.
ValueErrorIf 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_v1p2beta1

client = vision_v1p2beta1.ImageAnnotatorClient()

TODO: Initialize requests:

requests = []

response = client.batch_annotate_images(requests)

Parameters
NameDescription
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
TypeDescription
google.api_core.exceptions.GoogleAPICallErrorIf the request failed for any reason.
google.api_core.exceptions.RetryErrorIf the request failed due to a retryable error and retry attempts failed.
ValueErrorIf the parameters are invalid.

crop_hints

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

Return crop hints information.

Parameters
NameDescription
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
TypeDescription
AnnotateImageResponseThe API response.

document_text_detection

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

Perform document text detection.

Parameters
NameDescription
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
TypeDescription
AnnotateImageResponseThe API response.

face_detection

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

Perform face detection.

Parameters
NameDescription
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
TypeDescription
AnnotateImageResponseThe 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
NameDescription
filename str

The path to the service account private key json file.

Returns
TypeDescription
ImageAnnotatorClientThe 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
NameDescription
filename str

The path to the service account private key json file.

Returns
TypeDescription
ImageAnnotatorClientThe constructed client.

image_properties

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

Return image properties information.

Parameters
NameDescription
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
TypeDescription
AnnotateImageResponseThe API response.

label_detection

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

Perform label detection.

Parameters
NameDescription
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
TypeDescription
AnnotateImageResponseThe API response.

landmark_detection

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

Perform landmark detection.

Parameters
NameDescription
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
TypeDescription
AnnotateImageResponseThe API response.

logo_detection

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

Perform logo detection.

Parameters
NameDescription
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
TypeDescription
AnnotateImageResponseThe API response.

safe_search_detection

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

Perform safe search detection.

Parameters
NameDescription
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
TypeDescription
AnnotateImageResponseThe API response.

text_detection

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

Perform text detection.

Parameters
NameDescription
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
TypeDescription
AnnotateImageResponseThe API response.

web_detection

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

Perform web detection.

Parameters
NameDescription
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
TypeDescription
AnnotateImageResponseThe API response.