PHP Class Google\Cloud\Vision\VisionClient

Example: use Google\Cloud\ServiceBuilder; $cloud = new ServiceBuilder(); $vision = $cloud->vision(); VisionClient can be instantiated directly. use Google\Cloud\Vision\VisionClient; $vision = new VisionClient();
Inheritance: use trait Google\Cloud\ClientTrait, use trait Google\Cloud\ValidateTrait
Datei anzeigen Open project: GoogleCloudPlatform/gcloud-php

Protected Properties

Property Type Description
$connection ConnectionInterface

Public Methods

Method Description
__construct ( array $config = [] ) Create a Vision client.
annotate ( Image $image, array $options = [] ) : Annotation Annotate a single image.
annotateBatch ( array $images, array $options = [] ) : Annotation[] Annotate a set of images.
image ( resource | string | StorageObject $image, array $features, array $options = [] ) : Image Create an instance of {@see Google\Cloud\Vision\Image} with required features and options.
images ( array $images, array $features, array $options = [] ) : Image[] Create an array of type {@see Google\Cloud\Vision\Image} with required features and options set for each member of the set.

Method Details

__construct() public method

Create a Vision client.
public __construct ( array $config = [] )
$config array [optional] { Configuration Options. @type string $projectId The project ID from the Google Developer's Console. @type CacheItemPoolInterface $authCache A cache for storing access tokens. **Defaults to** a simple in memory implementation. @type array $authCacheOptions Cache configuration options. @type callable $authHttpHandler A handler used to deliver Psr7 requests specifically for authentication. @type callable $httpHandler A handler used to deliver Psr7 requests. @type string $keyFile The contents of the service account credentials .json file retrieved from the Google Developers Console. @type string $keyFilePath The full path to your service account credentials .json file retrieved from the Google Developers Console. @type int $retries Number of retries for a failed request. **Defaults to** `3`. @type array $scopes Scopes to be used for the request. }

annotate() public method

Example: $familyPhotoResource = fopen(__DIR__ .'/assets/family-photo.jpg', 'r'); $image = $vision->image($familyPhotoResource, [ 'FACE_DETECTION' ]); $result = $vision->annotate($image);
public annotate ( Image $image, array $options = [] ) : Annotation
$image Image The image to annotate
$options array Configuration options
return Annotation

annotateBatch() public method

Example: $images = []; $familyPhotoResource = fopen(__DIR__ .'/assets/family-photo.jpg', 'r'); $eiffelTowerResource = fopen(__DIR__ .'/assets/eiffel-tower.jpg', 'r'); $images[] = $vision->image($familyPhotoResource, [ 'FACE_DETECTION' ]); $images[] = $vision->image($eiffelTowerResource, [ 'LANDMARK_DETECTION' ]); $result = $vision->annotateBatch($images);
public annotateBatch ( array $images, array $options = [] ) : Annotation[]
$images array An array consisting of instances of {@see \Google\Cloud\Vision\Image}.
$options array Configuration Options
return Annotation[]

image() public method

This method should be used to configure a single image, or when a set of images requires different settings for each member of the set. If you have a set of images which all will use the same settings, {@see \Google\Cloud\Vision\VisionClient::images()} may be quicker and simpler to use. This method will not perform any service requests, and is meant to be used to configure a request prior to calling {@see \Google\Cloud\Vision\VisionClient::annotate()}. For more information, including best practices and examples detailing other usage such as $imageContext, see {@see \Google\Cloud\Vision\Image::__construct()}. Example: $imageResource = fopen(__DIR__ .'/assets/family-photo.jpg', 'r'); $image = $vision->image($imageResource, [ 'FACE_DETECTION' ]); Setting maxResults for a feature $imageResource = fopen(__DIR__ .'/assets/family-photo.jpg', 'r'); $image = $vision->image($imageResource, [ 'FACE_DETECTION' ], [ 'maxResults' => [ 'FACE_DETECTION' => 1 ] ]);
public image ( resource | string | StorageObject $image, array $features, array $options = [] ) : Image
$image resource | string | StorageObject An image to configure with the given settings. This parameter will accept a resource, a string of bytes, or an instance of {@see \Google\Cloud\Storage\StorageObject}.
$features array A list of cloud vision [features](https://cloud.google.com/vision/reference/rest/v1/images/annotate#type) to apply to the image.
$options array See {@see \Google\Cloud\Vision\Image::__construct()} for configuration details.
return Image

images() public method

This method is useful for quickly configuring every member of a set of images with the same features and options. Should you need to provide different features or options for one or more members of the set, {@see \Google\Cloud\Vision\VisionClient::image()} is a better choice. This method will not perform any service requests, and is meant to be used to configure a request prior to calling {@see \Google\Cloud\Vision\VisionClient::annotateBatch()}. For more information, including best practices and examples detailing other usage such as $imageContext, see {@see \Google\Cloud\Vision\Image::__construct()}. Example: In the example below, both images will have the same settings applied. They will both run face detection and return up to 10 results. $familyPhotoResource = fopen(__DIR__ .'/assets/family-photo.jpg', 'r'); $weddingPhotoResource = fopen(__DIR__ .'/assets/wedding-photo.jpg', 'r'); $images = $vision->images([$familyPhotoResource, $weddingPhotoResource], [ 'FACE_DETECTION' ], [ 'maxResults' => [ 'FACE_DETECTION' => 10 ] ]);
public images ( array $images, array $features, array $options = [] ) : Image[]
$images array An array of images to configure with the given settings. Each member of the set can be a resource, a string of bytes, or an instance of {@see \Google\Cloud\Storage\StorageObject}.
$features array A list of cloud vision features to apply to each image.
$options array See {@see \Google\Cloud\Vision\Image::__construct()} for configuration details.
return Image[]

Property Details

$connection protected_oe property

protected ConnectionInterface $connection
return ConnectionInterface