Documentation ¶
Overview ¶
Package vision is an auto-generated package for the Cloud Vision API.
Integrates Google Vision features, including image labeling, face, logo, and landmark detection, optical character recognition (OCR), and detection of explicit content, into applications.
Example usage ¶
To get started with this package, create a client.
ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close()
The client will use your default application credentials. Clients should be reused instead of created as needed. The methods of Client are safe for concurrent use by multiple goroutines. The returned client must be Closed when it is done being used.
Using the Client ¶
The following is an example of making an API call with the newly created client.
ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.CreateProductSetRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#CreateProductSetRequest. } resp, err := c.CreateProductSet(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp
Use of Context ¶
The ctx passed to NewClient is used for authentication requests and for creating the underlying connection, but is not used for subsequent calls. Individual methods on the client use the ctx given to them.
To close the open connection, use the Close() method.
For information about setting deadlines, reusing contexts, and more please visit https://pkg.go.dev/cloud.google.com/go.
Index ¶
- func DefaultAuthScopes() []string
- func NewImageFromReader(r io.Reader) (*pb.Image, error)
- func NewImageFromURI(uri string) *pb.Image
- type AsyncBatchAnnotateFilesOperation
- func (op *AsyncBatchAnnotateFilesOperation) Done() bool
- func (op *AsyncBatchAnnotateFilesOperation) Metadata() (*visionpb.OperationMetadata, error)
- func (op *AsyncBatchAnnotateFilesOperation) Name() string
- func (op *AsyncBatchAnnotateFilesOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*visionpb.AsyncBatchAnnotateFilesResponse, error)
- func (op *AsyncBatchAnnotateFilesOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*visionpb.AsyncBatchAnnotateFilesResponse, error)
- type AsyncBatchAnnotateImagesOperation
- func (op *AsyncBatchAnnotateImagesOperation) Done() bool
- func (op *AsyncBatchAnnotateImagesOperation) Metadata() (*visionpb.OperationMetadata, error)
- func (op *AsyncBatchAnnotateImagesOperation) Name() string
- func (op *AsyncBatchAnnotateImagesOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*visionpb.AsyncBatchAnnotateImagesResponse, error)
- func (op *AsyncBatchAnnotateImagesOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*visionpb.AsyncBatchAnnotateImagesResponse, error)
- type Chin
- type Ears
- type Eye
- type Eyebrow
- type Eyebrows
- type Eyes
- type FaceLandmarks
- type ImageAnnotatorCallOptions
- type ImageAnnotatorClient
- func (c *ImageAnnotatorClient) AnnotateImage(ctx context.Context, req *pb.AnnotateImageRequest, opts ...gax.CallOption) (*pb.AnnotateImageResponse, error)
- func (c *ImageAnnotatorClient) AsyncBatchAnnotateFiles(ctx context.Context, req *visionpb.AsyncBatchAnnotateFilesRequest, ...) (*AsyncBatchAnnotateFilesOperation, error)
- func (c *ImageAnnotatorClient) AsyncBatchAnnotateFilesOperation(name string) *AsyncBatchAnnotateFilesOperation
- func (c *ImageAnnotatorClient) AsyncBatchAnnotateImages(ctx context.Context, req *visionpb.AsyncBatchAnnotateImagesRequest, ...) (*AsyncBatchAnnotateImagesOperation, error)
- func (c *ImageAnnotatorClient) AsyncBatchAnnotateImagesOperation(name string) *AsyncBatchAnnotateImagesOperation
- func (c *ImageAnnotatorClient) BatchAnnotateFiles(ctx context.Context, req *visionpb.BatchAnnotateFilesRequest, ...) (*visionpb.BatchAnnotateFilesResponse, error)
- func (c *ImageAnnotatorClient) BatchAnnotateImages(ctx context.Context, req *visionpb.BatchAnnotateImagesRequest, ...) (*visionpb.BatchAnnotateImagesResponse, error)
- func (c *ImageAnnotatorClient) Close() error
- func (c *ImageAnnotatorClient) Connection() *grpc.ClientConn
- func (c *ImageAnnotatorClient) CropHints(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, ...) (*pb.CropHintsAnnotation, error)
- func (c *ImageAnnotatorClient) DetectDocumentText(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, ...) (*pb.TextAnnotation, error)
- func (c *ImageAnnotatorClient) DetectFaces(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, maxResults int, ...) ([]*pb.FaceAnnotation, error)
- func (c *ImageAnnotatorClient) DetectImageProperties(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, ...) (*pb.ImageProperties, error)
- func (c *ImageAnnotatorClient) DetectLabels(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, maxResults int, ...) ([]*pb.EntityAnnotation, error)
- func (c *ImageAnnotatorClient) DetectLandmarks(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, maxResults int, ...) ([]*pb.EntityAnnotation, error)
- func (c *ImageAnnotatorClient) DetectLogos(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, maxResults int, ...) ([]*pb.EntityAnnotation, error)
- func (c *ImageAnnotatorClient) DetectSafeSearch(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, ...) (*pb.SafeSearchAnnotation, error)
- func (c *ImageAnnotatorClient) DetectTexts(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, maxResults int, ...) ([]*pb.EntityAnnotation, error)
- func (c *ImageAnnotatorClient) DetectWeb(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, ...) (*pb.WebDetection, error)
- func (c *ImageAnnotatorClient) LocalizeObjects(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, ...) ([]*pb.LocalizedObjectAnnotation, error)
- func (c *ImageAnnotatorClient) ProductSearch(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, ...) (*pb.ProductSearchResults, error)
- type ImportProductSetsOperation
- func (op *ImportProductSetsOperation) Done() bool
- func (op *ImportProductSetsOperation) Metadata() (*visionpb.BatchOperationMetadata, error)
- func (op *ImportProductSetsOperation) Name() string
- func (op *ImportProductSetsOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*visionpb.ImportProductSetsResponse, error)
- func (op *ImportProductSetsOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*visionpb.ImportProductSetsResponse, error)
- type Mouth
- type Nose
- type ProductIterator
- type ProductSearchCallOptions
- type ProductSearchClient
- func (c *ProductSearchClient) AddProductToProductSet(ctx context.Context, req *visionpb.AddProductToProductSetRequest, ...) error
- func (c *ProductSearchClient) Close() error
- func (c *ProductSearchClient) Connection() *grpc.ClientConn
- func (c *ProductSearchClient) CreateProduct(ctx context.Context, req *visionpb.CreateProductRequest, ...) (*visionpb.Product, error)
- func (c *ProductSearchClient) CreateProductSet(ctx context.Context, req *visionpb.CreateProductSetRequest, ...) (*visionpb.ProductSet, error)
- func (c *ProductSearchClient) CreateReferenceImage(ctx context.Context, req *visionpb.CreateReferenceImageRequest, ...) (*visionpb.ReferenceImage, error)
- func (c *ProductSearchClient) DeleteProduct(ctx context.Context, req *visionpb.DeleteProductRequest, ...) error
- func (c *ProductSearchClient) DeleteProductSet(ctx context.Context, req *visionpb.DeleteProductSetRequest, ...) error
- func (c *ProductSearchClient) DeleteReferenceImage(ctx context.Context, req *visionpb.DeleteReferenceImageRequest, ...) error
- func (c *ProductSearchClient) GetProduct(ctx context.Context, req *visionpb.GetProductRequest, opts ...gax.CallOption) (*visionpb.Product, error)
- func (c *ProductSearchClient) GetProductSet(ctx context.Context, req *visionpb.GetProductSetRequest, ...) (*visionpb.ProductSet, error)
- func (c *ProductSearchClient) GetReferenceImage(ctx context.Context, req *visionpb.GetReferenceImageRequest, ...) (*visionpb.ReferenceImage, error)
- func (c *ProductSearchClient) ImportProductSets(ctx context.Context, req *visionpb.ImportProductSetsRequest, ...) (*ImportProductSetsOperation, error)
- func (c *ProductSearchClient) ImportProductSetsOperation(name string) *ImportProductSetsOperation
- func (c *ProductSearchClient) ListProductSets(ctx context.Context, req *visionpb.ListProductSetsRequest, ...) *ProductSetIterator
- func (c *ProductSearchClient) ListProducts(ctx context.Context, req *visionpb.ListProductsRequest, opts ...gax.CallOption) *ProductIterator
- func (c *ProductSearchClient) ListProductsInProductSet(ctx context.Context, req *visionpb.ListProductsInProductSetRequest, ...) *ProductIterator
- func (c *ProductSearchClient) ListReferenceImages(ctx context.Context, req *visionpb.ListReferenceImagesRequest, ...) *ReferenceImageIterator
- func (c *ProductSearchClient) PurgeProducts(ctx context.Context, req *visionpb.PurgeProductsRequest, ...) (*PurgeProductsOperation, error)
- func (c *ProductSearchClient) PurgeProductsOperation(name string) *PurgeProductsOperation
- func (c *ProductSearchClient) RemoveProductFromProductSet(ctx context.Context, req *visionpb.RemoveProductFromProductSetRequest, ...) error
- func (c *ProductSearchClient) UpdateProduct(ctx context.Context, req *visionpb.UpdateProductRequest, ...) (*visionpb.Product, error)
- func (c *ProductSearchClient) UpdateProductSet(ctx context.Context, req *visionpb.UpdateProductSetRequest, ...) (*visionpb.ProductSet, error)
- type ProductSetIterator
- type PurgeProductsOperation
- func (op *PurgeProductsOperation) Done() bool
- func (op *PurgeProductsOperation) Metadata() (*visionpb.BatchOperationMetadata, error)
- func (op *PurgeProductsOperation) Name() string
- func (op *PurgeProductsOperation) Poll(ctx context.Context, opts ...gax.CallOption) error
- func (op *PurgeProductsOperation) Wait(ctx context.Context, opts ...gax.CallOption) error
- type ReferenceImageIterator
Examples ¶
- ImageAnnotatorClient.AnnotateImage
- ImageAnnotatorClient.AsyncBatchAnnotateFiles
- ImageAnnotatorClient.AsyncBatchAnnotateImages
- ImageAnnotatorClient.BatchAnnotateFiles
- ImageAnnotatorClient.BatchAnnotateImages
- NewImageAnnotatorClient
- NewProductSearchClient
- ProductSearchClient.AddProductToProductSet
- ProductSearchClient.CreateProduct
- ProductSearchClient.CreateProductSet
- ProductSearchClient.CreateReferenceImage
- ProductSearchClient.DeleteProduct
- ProductSearchClient.DeleteProductSet
- ProductSearchClient.DeleteReferenceImage
- ProductSearchClient.GetProduct
- ProductSearchClient.GetProductSet
- ProductSearchClient.GetReferenceImage
- ProductSearchClient.ImportProductSets
- ProductSearchClient.ListProductSets
- ProductSearchClient.ListProducts
- ProductSearchClient.ListProductsInProductSet
- ProductSearchClient.ListReferenceImages
- ProductSearchClient.PurgeProducts
- ProductSearchClient.RemoveProductFromProductSet
- ProductSearchClient.UpdateProduct
- ProductSearchClient.UpdateProductSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultAuthScopes ¶
func DefaultAuthScopes() []string
DefaultAuthScopes reports the default set of authentication scopes to use with this package.
func NewImageFromReader ¶
NewImageFromReader reads the bytes of an image from r.
func NewImageFromURI ¶
NewImageFromURI returns an image that refers to an object in Google Cloud Storage (when the uri is of the form "gs://BUCKET/OBJECT") or at a public URL.
Types ¶
type AsyncBatchAnnotateFilesOperation ¶
type AsyncBatchAnnotateFilesOperation struct {
// contains filtered or unexported fields
}
AsyncBatchAnnotateFilesOperation manages a long-running operation from AsyncBatchAnnotateFiles.
func (*AsyncBatchAnnotateFilesOperation) Done ¶
func (op *AsyncBatchAnnotateFilesOperation) Done() bool
Done reports whether the long-running operation has completed.
func (*AsyncBatchAnnotateFilesOperation) Metadata ¶
func (op *AsyncBatchAnnotateFilesOperation) Metadata() (*visionpb.OperationMetadata, error)
Metadata returns metadata associated with the long-running operation. Metadata itself does not contact the server, but Poll does. To get the latest metadata, call this method after a successful call to Poll. If the metadata is not available, the returned metadata and error are both nil.
func (*AsyncBatchAnnotateFilesOperation) Name ¶
func (op *AsyncBatchAnnotateFilesOperation) Name() string
Name returns the name of the long-running operation. The name is assigned by the server and is unique within the service from which the operation is created.
func (*AsyncBatchAnnotateFilesOperation) Poll ¶
func (op *AsyncBatchAnnotateFilesOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*visionpb.AsyncBatchAnnotateFilesResponse, error)
Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds and the operation has completed with failure, the error is returned and op.Done will return true. If Poll succeeds and the operation has completed successfully, op.Done will return true, and the response of the operation is returned. If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*AsyncBatchAnnotateFilesOperation) Wait ¶
func (op *AsyncBatchAnnotateFilesOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*visionpb.AsyncBatchAnnotateFilesResponse, error)
Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
type AsyncBatchAnnotateImagesOperation ¶
type AsyncBatchAnnotateImagesOperation struct {
// contains filtered or unexported fields
}
AsyncBatchAnnotateImagesOperation manages a long-running operation from AsyncBatchAnnotateImages.
func (*AsyncBatchAnnotateImagesOperation) Done ¶
func (op *AsyncBatchAnnotateImagesOperation) Done() bool
Done reports whether the long-running operation has completed.
func (*AsyncBatchAnnotateImagesOperation) Metadata ¶
func (op *AsyncBatchAnnotateImagesOperation) Metadata() (*visionpb.OperationMetadata, error)
Metadata returns metadata associated with the long-running operation. Metadata itself does not contact the server, but Poll does. To get the latest metadata, call this method after a successful call to Poll. If the metadata is not available, the returned metadata and error are both nil.
func (*AsyncBatchAnnotateImagesOperation) Name ¶
func (op *AsyncBatchAnnotateImagesOperation) Name() string
Name returns the name of the long-running operation. The name is assigned by the server and is unique within the service from which the operation is created.
func (*AsyncBatchAnnotateImagesOperation) Poll ¶
func (op *AsyncBatchAnnotateImagesOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*visionpb.AsyncBatchAnnotateImagesResponse, error)
Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds and the operation has completed with failure, the error is returned and op.Done will return true. If Poll succeeds and the operation has completed successfully, op.Done will return true, and the response of the operation is returned. If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*AsyncBatchAnnotateImagesOperation) Wait ¶
func (op *AsyncBatchAnnotateImagesOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*visionpb.AsyncBatchAnnotateImagesResponse, error)
Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
type FaceLandmarks ¶
type FaceLandmarks struct { Eyebrows Eyebrows Eyes Eyes Ears Ears Nose Nose Mouth Mouth Chin Chin Forehead *pb.Position }
FaceLandmarks contains the positions of facial features detected by the service.
func FaceFromLandmarks ¶
func FaceFromLandmarks(landmarks []*pb.FaceAnnotation_Landmark) *FaceLandmarks
FaceFromLandmarks converts the list of face landmarks returned by the service to a FaceLandmarks struct.
type ImageAnnotatorCallOptions ¶
type ImageAnnotatorCallOptions struct { BatchAnnotateImages []gax.CallOption BatchAnnotateFiles []gax.CallOption AsyncBatchAnnotateImages []gax.CallOption AsyncBatchAnnotateFiles []gax.CallOption }
ImageAnnotatorCallOptions contains the retry settings for each method of ImageAnnotatorClient.
type ImageAnnotatorClient ¶
type ImageAnnotatorClient struct { // The call options for this service. CallOptions *ImageAnnotatorCallOptions // LROClient is used internally to handle long-running operations. // It is exposed so that its CallOptions can be modified if required. // Users should not Close this client. LROClient *lroauto.OperationsClient // contains filtered or unexported fields }
ImageAnnotatorClient is a client for interacting with Cloud Vision API. Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
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.
func NewImageAnnotatorClient ¶
func NewImageAnnotatorClient(ctx context.Context, opts ...option.ClientOption) (*ImageAnnotatorClient, error)
NewImageAnnotatorClient creates a new image annotator client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.
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.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" ) func main() { ctx := context.Background() c, err := vision.NewImageAnnotatorClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() // TODO: Use client. _ = c }
Output:
func (*ImageAnnotatorClient) AnnotateImage ¶
func (c *ImageAnnotatorClient) AnnotateImage(ctx context.Context, req *pb.AnnotateImageRequest, opts ...gax.CallOption) (*pb.AnnotateImageResponse, error)
AnnotateImage runs image detection and annotation for a single image.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" pb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewImageAnnotatorClient(ctx) if err != nil { // TODO: Handle error. } res, err := c.AnnotateImage(ctx, &pb.AnnotateImageRequest{ Image: vision.NewImageFromURI("gs://my-bucket/my-image.png"), Features: []*pb.Feature{ {Type: pb.Feature_LANDMARK_DETECTION, MaxResults: 5}, {Type: pb.Feature_LABEL_DETECTION, MaxResults: 3}, }, }) if err != nil { // TODO: Handle error. } // TODO: Use res. _ = res }
Output:
func (*ImageAnnotatorClient) AsyncBatchAnnotateFiles ¶
func (c *ImageAnnotatorClient) AsyncBatchAnnotateFiles(ctx context.Context, req *visionpb.AsyncBatchAnnotateFilesRequest, opts ...gax.CallOption) (*AsyncBatchAnnotateFilesOperation, error)
AsyncBatchAnnotateFiles 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).
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewImageAnnotatorClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.AsyncBatchAnnotateFilesRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#AsyncBatchAnnotateFilesRequest. } op, err := c.AsyncBatchAnnotateFiles(ctx, req) if err != nil { // TODO: Handle error. } resp, err := op.Wait(ctx) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*ImageAnnotatorClient) AsyncBatchAnnotateFilesOperation ¶
func (c *ImageAnnotatorClient) AsyncBatchAnnotateFilesOperation(name string) *AsyncBatchAnnotateFilesOperation
AsyncBatchAnnotateFilesOperation returns a new AsyncBatchAnnotateFilesOperation from a given name. The name must be that of a previously created AsyncBatchAnnotateFilesOperation, possibly from a different process.
func (*ImageAnnotatorClient) AsyncBatchAnnotateImages ¶
func (c *ImageAnnotatorClient) AsyncBatchAnnotateImages(ctx context.Context, req *visionpb.AsyncBatchAnnotateImagesRequest, opts ...gax.CallOption) (*AsyncBatchAnnotateImagesOperation, error)
AsyncBatchAnnotateImages run asynchronous image detection and annotation for a list of images.
Progress and results can be retrieved through the google.longrunning.Operations interface. Operation.metadata contains OperationMetadata (metadata). Operation.response contains AsyncBatchAnnotateImagesResponse (results).
This service will write image annotation outputs to json files in customer GCS bucket, each json file containing BatchAnnotateImagesResponse proto.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewImageAnnotatorClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.AsyncBatchAnnotateImagesRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#AsyncBatchAnnotateImagesRequest. } op, err := c.AsyncBatchAnnotateImages(ctx, req) if err != nil { // TODO: Handle error. } resp, err := op.Wait(ctx) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*ImageAnnotatorClient) AsyncBatchAnnotateImagesOperation ¶
func (c *ImageAnnotatorClient) AsyncBatchAnnotateImagesOperation(name string) *AsyncBatchAnnotateImagesOperation
AsyncBatchAnnotateImagesOperation returns a new AsyncBatchAnnotateImagesOperation from a given name. The name must be that of a previously created AsyncBatchAnnotateImagesOperation, possibly from a different process.
func (*ImageAnnotatorClient) BatchAnnotateFiles ¶
func (c *ImageAnnotatorClient) BatchAnnotateFiles(ctx context.Context, req *visionpb.BatchAnnotateFilesRequest, opts ...gax.CallOption) (*visionpb.BatchAnnotateFilesResponse, error)
BatchAnnotateFiles service that performs image detection and annotation for a batch of files. Now only “application/pdf”, “image/tiff” and “image/gif” are supported.
This service will extract at most 5 (customers can specify which 5 in AnnotateFileRequest.pages) frames (gif) or pages (pdf or tiff) from each file provided and perform detection and annotation for each image extracted.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewImageAnnotatorClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.BatchAnnotateFilesRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#BatchAnnotateFilesRequest. } resp, err := c.BatchAnnotateFiles(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*ImageAnnotatorClient) BatchAnnotateImages ¶
func (c *ImageAnnotatorClient) BatchAnnotateImages(ctx context.Context, req *visionpb.BatchAnnotateImagesRequest, opts ...gax.CallOption) (*visionpb.BatchAnnotateImagesResponse, error)
BatchAnnotateImages run image detection and annotation for a batch of images.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewImageAnnotatorClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.BatchAnnotateImagesRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#BatchAnnotateImagesRequest. } resp, err := c.BatchAnnotateImages(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*ImageAnnotatorClient) Close ¶
func (c *ImageAnnotatorClient) Close() error
Close closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*ImageAnnotatorClient) Connection ¶
func (c *ImageAnnotatorClient) Connection() *grpc.ClientConn
Connection returns a connection to the API service.
Deprecated.
func (*ImageAnnotatorClient) CropHints ¶
func (c *ImageAnnotatorClient) CropHints(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, opts ...gax.CallOption) (*pb.CropHintsAnnotation, error)
CropHints computes crop hints for the image.
func (*ImageAnnotatorClient) DetectDocumentText ¶
func (c *ImageAnnotatorClient) DetectDocumentText(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, opts ...gax.CallOption) (*pb.TextAnnotation, error)
DetectDocumentText performs full text (OCR) detection on the image.
func (*ImageAnnotatorClient) DetectFaces ¶
func (c *ImageAnnotatorClient) DetectFaces(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, maxResults int, opts ...gax.CallOption) ([]*pb.FaceAnnotation, error)
DetectFaces performs face detection on the image. At most maxResults results are returned.
func (*ImageAnnotatorClient) DetectImageProperties ¶
func (c *ImageAnnotatorClient) DetectImageProperties(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, opts ...gax.CallOption) (*pb.ImageProperties, error)
DetectImageProperties computes properties of the image.
func (*ImageAnnotatorClient) DetectLabels ¶
func (c *ImageAnnotatorClient) DetectLabels(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, maxResults int, opts ...gax.CallOption) ([]*pb.EntityAnnotation, error)
DetectLabels performs label detection on the image. At most maxResults results are returned.
func (*ImageAnnotatorClient) DetectLandmarks ¶
func (c *ImageAnnotatorClient) DetectLandmarks(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, maxResults int, opts ...gax.CallOption) ([]*pb.EntityAnnotation, error)
DetectLandmarks performs landmark detection on the image. At most maxResults results are returned.
func (*ImageAnnotatorClient) DetectLogos ¶
func (c *ImageAnnotatorClient) DetectLogos(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, maxResults int, opts ...gax.CallOption) ([]*pb.EntityAnnotation, error)
DetectLogos performs logo detection on the image. At most maxResults results are returned.
func (*ImageAnnotatorClient) DetectSafeSearch ¶
func (c *ImageAnnotatorClient) DetectSafeSearch(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, opts ...gax.CallOption) (*pb.SafeSearchAnnotation, error)
DetectSafeSearch performs safe-search detection on the image.
func (*ImageAnnotatorClient) DetectTexts ¶
func (c *ImageAnnotatorClient) DetectTexts(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, maxResults int, opts ...gax.CallOption) ([]*pb.EntityAnnotation, error)
DetectTexts performs text detection on the image. At most maxResults results are returned.
func (*ImageAnnotatorClient) DetectWeb ¶
func (c *ImageAnnotatorClient) DetectWeb(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, opts ...gax.CallOption) (*pb.WebDetection, error)
DetectWeb computes a web annotation on the image.
func (*ImageAnnotatorClient) LocalizeObjects ¶
func (c *ImageAnnotatorClient) LocalizeObjects(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, opts ...gax.CallOption) ([]*pb.LocalizedObjectAnnotation, error)
LocalizeObject runs the localizer for object detection.
func (*ImageAnnotatorClient) ProductSearch ¶
func (c *ImageAnnotatorClient) ProductSearch(ctx context.Context, img *pb.Image, ictx *pb.ImageContext, opts ...gax.CallOption) (*pb.ProductSearchResults, error)
ProductSearch searches the image for products.
type ImportProductSetsOperation ¶
type ImportProductSetsOperation struct {
// contains filtered or unexported fields
}
ImportProductSetsOperation manages a long-running operation from ImportProductSets.
func (*ImportProductSetsOperation) Done ¶
func (op *ImportProductSetsOperation) Done() bool
Done reports whether the long-running operation has completed.
func (*ImportProductSetsOperation) Metadata ¶
func (op *ImportProductSetsOperation) Metadata() (*visionpb.BatchOperationMetadata, error)
Metadata returns metadata associated with the long-running operation. Metadata itself does not contact the server, but Poll does. To get the latest metadata, call this method after a successful call to Poll. If the metadata is not available, the returned metadata and error are both nil.
func (*ImportProductSetsOperation) Name ¶
func (op *ImportProductSetsOperation) Name() string
Name returns the name of the long-running operation. The name is assigned by the server and is unique within the service from which the operation is created.
func (*ImportProductSetsOperation) Poll ¶
func (op *ImportProductSetsOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*visionpb.ImportProductSetsResponse, error)
Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds and the operation has completed with failure, the error is returned and op.Done will return true. If Poll succeeds and the operation has completed successfully, op.Done will return true, and the response of the operation is returned. If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*ImportProductSetsOperation) Wait ¶
func (op *ImportProductSetsOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*visionpb.ImportProductSetsResponse, error)
Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
type ProductIterator ¶
type ProductIterator struct { // Response is the raw response for the current page. // It must be cast to the RPC response type. // Calling Next() or InternalFetch() updates this value. Response interface{} // InternalFetch is for use by the Google Cloud Libraries only. // It is not part of the stable interface of this package. // // InternalFetch returns results from a single call to the underlying RPC. // The number of results is no greater than pageSize. // If there are no more results, nextPageToken is empty and err is nil. InternalFetch func(pageSize int, pageToken string) (results []*visionpb.Product, nextPageToken string, err error) // contains filtered or unexported fields }
ProductIterator manages a stream of *visionpb.Product.
func (*ProductIterator) Next ¶
func (it *ProductIterator) Next() (*visionpb.Product, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*ProductIterator) PageInfo ¶
func (it *ProductIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
type ProductSearchCallOptions ¶
type ProductSearchCallOptions struct { CreateProductSet []gax.CallOption ListProductSets []gax.CallOption GetProductSet []gax.CallOption UpdateProductSet []gax.CallOption DeleteProductSet []gax.CallOption CreateProduct []gax.CallOption ListProducts []gax.CallOption GetProduct []gax.CallOption UpdateProduct []gax.CallOption DeleteProduct []gax.CallOption CreateReferenceImage []gax.CallOption DeleteReferenceImage []gax.CallOption ListReferenceImages []gax.CallOption GetReferenceImage []gax.CallOption AddProductToProductSet []gax.CallOption RemoveProductFromProductSet []gax.CallOption ListProductsInProductSet []gax.CallOption ImportProductSets []gax.CallOption PurgeProducts []gax.CallOption }
ProductSearchCallOptions contains the retry settings for each method of ProductSearchClient.
type ProductSearchClient ¶
type ProductSearchClient struct { // The call options for this service. CallOptions *ProductSearchCallOptions // LROClient is used internally to handle long-running operations. // It is exposed so that its CallOptions can be modified if required. // Users should not Close this client. LROClient *lroauto.OperationsClient // contains filtered or unexported fields }
ProductSearchClient is a client for interacting with Cloud Vision API. Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
Manages Products and ProductSets of reference images for use in product search. It uses the following resource model:
The API has a collection of ProductSet resources, named projects/*/locations/*/productSets/*, which acts as a way to put different products into groups to limit identification.
In parallel,
The API has a collection of Product resources, named projects/*/locations/*/products/* Each Product has a collection of ReferenceImage resources, named projects/*/locations/*/products/*/referenceImages/*
func NewProductSearchClient ¶
func NewProductSearchClient(ctx context.Context, opts ...option.ClientOption) (*ProductSearchClient, error)
NewProductSearchClient creates a new product search client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.
Manages Products and ProductSets of reference images for use in product search. It uses the following resource model:
The API has a collection of ProductSet resources, named projects/*/locations/*/productSets/*, which acts as a way to put different products into groups to limit identification.
In parallel,
The API has a collection of Product resources, named projects/*/locations/*/products/* Each Product has a collection of ReferenceImage resources, named projects/*/locations/*/products/*/referenceImages/*
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() // TODO: Use client. _ = c }
Output:
func (*ProductSearchClient) AddProductToProductSet ¶
func (c *ProductSearchClient) AddProductToProductSet(ctx context.Context, req *visionpb.AddProductToProductSetRequest, opts ...gax.CallOption) error
AddProductToProductSet adds a Product to the specified ProductSet. If the Product is already present, no change is made.
One Product can be added to at most 100 ProductSets.
Possible errors:
Returns NOT_FOUND if the Product or the ProductSet doesn’t exist.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.AddProductToProductSetRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#AddProductToProductSetRequest. } err = c.AddProductToProductSet(ctx, req) if err != nil { // TODO: Handle error. } }
Output:
func (*ProductSearchClient) Close ¶
func (c *ProductSearchClient) Close() error
Close closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*ProductSearchClient) Connection ¶
func (c *ProductSearchClient) Connection() *grpc.ClientConn
Connection returns a connection to the API service.
Deprecated.
func (*ProductSearchClient) CreateProduct ¶
func (c *ProductSearchClient) CreateProduct(ctx context.Context, req *visionpb.CreateProductRequest, opts ...gax.CallOption) (*visionpb.Product, error)
CreateProduct creates and returns a new product resource.
Possible errors:
Returns INVALID_ARGUMENT if display_name is missing or longer than 4096 characters. Returns INVALID_ARGUMENT if description is longer than 4096 characters. Returns INVALID_ARGUMENT if product_category is missing or invalid.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.CreateProductRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#CreateProductRequest. } resp, err := c.CreateProduct(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*ProductSearchClient) CreateProductSet ¶
func (c *ProductSearchClient) CreateProductSet(ctx context.Context, req *visionpb.CreateProductSetRequest, opts ...gax.CallOption) (*visionpb.ProductSet, error)
CreateProductSet creates and returns a new ProductSet resource.
Possible errors:
Returns INVALID_ARGUMENT if display_name is missing, or is longer than 4096 characters.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.CreateProductSetRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#CreateProductSetRequest. } resp, err := c.CreateProductSet(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*ProductSearchClient) CreateReferenceImage ¶
func (c *ProductSearchClient) CreateReferenceImage(ctx context.Context, req *visionpb.CreateReferenceImageRequest, opts ...gax.CallOption) (*visionpb.ReferenceImage, error)
CreateReferenceImage creates and returns a new ReferenceImage resource.
The bounding_poly field is optional. If bounding_poly is not specified, the system will try to detect regions of interest in the image that are compatible with the product_category on the parent product. If it is specified, detection is ALWAYS skipped. The system converts polygons into non-rotated rectangles.
Note that the pipeline will resize the image if the image resolution is too large to process (above 50MP).
Possible errors:
Returns INVALID_ARGUMENT if the image_uri is missing or longer than 4096 characters. Returns INVALID_ARGUMENT if the product does not exist. Returns INVALID_ARGUMENT if bounding_poly is not provided, and nothing compatible with the parent product’s product_category is detected. Returns INVALID_ARGUMENT if bounding_poly contains more than 10 polygons.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.CreateReferenceImageRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#CreateReferenceImageRequest. } resp, err := c.CreateReferenceImage(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*ProductSearchClient) DeleteProduct ¶
func (c *ProductSearchClient) DeleteProduct(ctx context.Context, req *visionpb.DeleteProductRequest, opts ...gax.CallOption) error
DeleteProduct permanently deletes a product and its reference images.
Metadata of the product and all its images will be deleted right away, but search queries against ProductSets containing the product may still work until all related caches are refreshed.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.DeleteProductRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#DeleteProductRequest. } err = c.DeleteProduct(ctx, req) if err != nil { // TODO: Handle error. } }
Output:
func (*ProductSearchClient) DeleteProductSet ¶
func (c *ProductSearchClient) DeleteProductSet(ctx context.Context, req *visionpb.DeleteProductSetRequest, opts ...gax.CallOption) error
DeleteProductSet permanently deletes a ProductSet. Products and ReferenceImages in the ProductSet are not deleted.
The actual image files are not deleted from Google Cloud Storage.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.DeleteProductSetRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#DeleteProductSetRequest. } err = c.DeleteProductSet(ctx, req) if err != nil { // TODO: Handle error. } }
Output:
func (*ProductSearchClient) DeleteReferenceImage ¶
func (c *ProductSearchClient) DeleteReferenceImage(ctx context.Context, req *visionpb.DeleteReferenceImageRequest, opts ...gax.CallOption) error
DeleteReferenceImage permanently deletes a reference image.
The image metadata will be deleted right away, but search queries against ProductSets containing the image may still work until all related caches are refreshed.
The actual image files are not deleted from Google Cloud Storage.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.DeleteReferenceImageRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#DeleteReferenceImageRequest. } err = c.DeleteReferenceImage(ctx, req) if err != nil { // TODO: Handle error. } }
Output:
func (*ProductSearchClient) GetProduct ¶
func (c *ProductSearchClient) GetProduct(ctx context.Context, req *visionpb.GetProductRequest, opts ...gax.CallOption) (*visionpb.Product, error)
GetProduct gets information associated with a Product.
Possible errors:
Returns NOT_FOUND if the Product does not exist.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.GetProductRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#GetProductRequest. } resp, err := c.GetProduct(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*ProductSearchClient) GetProductSet ¶
func (c *ProductSearchClient) GetProductSet(ctx context.Context, req *visionpb.GetProductSetRequest, opts ...gax.CallOption) (*visionpb.ProductSet, error)
GetProductSet gets information associated with a ProductSet.
Possible errors:
Returns NOT_FOUND if the ProductSet does not exist.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.GetProductSetRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#GetProductSetRequest. } resp, err := c.GetProductSet(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*ProductSearchClient) GetReferenceImage ¶
func (c *ProductSearchClient) GetReferenceImage(ctx context.Context, req *visionpb.GetReferenceImageRequest, opts ...gax.CallOption) (*visionpb.ReferenceImage, error)
GetReferenceImage gets information associated with a ReferenceImage.
Possible errors:
Returns NOT_FOUND if the specified image does not exist.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.GetReferenceImageRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#GetReferenceImageRequest. } resp, err := c.GetReferenceImage(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*ProductSearchClient) ImportProductSets ¶
func (c *ProductSearchClient) ImportProductSets(ctx context.Context, req *visionpb.ImportProductSetsRequest, opts ...gax.CallOption) (*ImportProductSetsOperation, error)
ImportProductSets asynchronous API that imports a list of reference images to specified product sets based on a list of image information.
The google.longrunning.Operation API can be used to keep track of the progress and results of the request. Operation.metadata contains BatchOperationMetadata. (progress) Operation.response contains ImportProductSetsResponse. (results)
The input source of this method is a csv file on Google Cloud Storage. For the format of the csv file please see ImportProductSetsGcsSource.csv_file_uri.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.ImportProductSetsRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#ImportProductSetsRequest. } op, err := c.ImportProductSets(ctx, req) if err != nil { // TODO: Handle error. } resp, err := op.Wait(ctx) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*ProductSearchClient) ImportProductSetsOperation ¶
func (c *ProductSearchClient) ImportProductSetsOperation(name string) *ImportProductSetsOperation
ImportProductSetsOperation returns a new ImportProductSetsOperation from a given name. The name must be that of a previously created ImportProductSetsOperation, possibly from a different process.
func (*ProductSearchClient) ListProductSets ¶
func (c *ProductSearchClient) ListProductSets(ctx context.Context, req *visionpb.ListProductSetsRequest, opts ...gax.CallOption) *ProductSetIterator
ListProductSets lists ProductSets in an unspecified order.
Possible errors:
Returns INVALID_ARGUMENT if page_size is greater than 100, or less than 1.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" "google.golang.org/api/iterator" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.ListProductSetsRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#ListProductSetsRequest. } it := c.ListProductSets(ctx, req) for { resp, err := it.Next() if err == iterator.Done { break } if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp } }
Output:
func (*ProductSearchClient) ListProducts ¶
func (c *ProductSearchClient) ListProducts(ctx context.Context, req *visionpb.ListProductsRequest, opts ...gax.CallOption) *ProductIterator
ListProducts lists products in an unspecified order.
Possible errors:
Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" "google.golang.org/api/iterator" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.ListProductsRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#ListProductsRequest. } it := c.ListProducts(ctx, req) for { resp, err := it.Next() if err == iterator.Done { break } if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp } }
Output:
func (*ProductSearchClient) ListProductsInProductSet ¶
func (c *ProductSearchClient) ListProductsInProductSet(ctx context.Context, req *visionpb.ListProductsInProductSetRequest, opts ...gax.CallOption) *ProductIterator
ListProductsInProductSet lists the Products in a ProductSet, in an unspecified order. If the ProductSet does not exist, the products field of the response will be empty.
Possible errors:
Returns INVALID_ARGUMENT if page_size is greater than 100 or less than 1.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" "google.golang.org/api/iterator" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.ListProductsInProductSetRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#ListProductsInProductSetRequest. } it := c.ListProductsInProductSet(ctx, req) for { resp, err := it.Next() if err == iterator.Done { break } if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp } }
Output:
func (*ProductSearchClient) ListReferenceImages ¶
func (c *ProductSearchClient) ListReferenceImages(ctx context.Context, req *visionpb.ListReferenceImagesRequest, opts ...gax.CallOption) *ReferenceImageIterator
ListReferenceImages lists reference images.
Possible errors:
Returns NOT_FOUND if the parent product does not exist. Returns INVALID_ARGUMENT if the page_size is greater than 100, or less than 1.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" "google.golang.org/api/iterator" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.ListReferenceImagesRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#ListReferenceImagesRequest. } it := c.ListReferenceImages(ctx, req) for { resp, err := it.Next() if err == iterator.Done { break } if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp } }
Output:
func (*ProductSearchClient) PurgeProducts ¶
func (c *ProductSearchClient) PurgeProducts(ctx context.Context, req *visionpb.PurgeProductsRequest, opts ...gax.CallOption) (*PurgeProductsOperation, error)
PurgeProducts asynchronous API to delete all Products in a ProductSet or all Products that are in no ProductSet.
If a Product is a member of the specified ProductSet in addition to other ProductSets, the Product will still be deleted.
It is recommended to not delete the specified ProductSet until after this operation has completed. It is also recommended to not add any of the Products involved in the batch delete to a new ProductSet while this operation is running because those Products may still end up deleted.
It’s not possible to undo the PurgeProducts operation. Therefore, it is recommended to keep the csv files used in ImportProductSets (if that was how you originally built the Product Set) before starting PurgeProducts, in case you need to re-import the data after deletion.
If the plan is to purge all of the Products from a ProductSet and then re-use the empty ProductSet to re-import new Products into the empty ProductSet, you must wait until the PurgeProducts operation has finished for that ProductSet.
The google.longrunning.Operation API can be used to keep track of the progress and results of the request. Operation.metadata contains BatchOperationMetadata. (progress)
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.PurgeProductsRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#PurgeProductsRequest. } op, err := c.PurgeProducts(ctx, req) if err != nil { // TODO: Handle error. } err = op.Wait(ctx) if err != nil { // TODO: Handle error. } }
Output:
func (*ProductSearchClient) PurgeProductsOperation ¶
func (c *ProductSearchClient) PurgeProductsOperation(name string) *PurgeProductsOperation
PurgeProductsOperation returns a new PurgeProductsOperation from a given name. The name must be that of a previously created PurgeProductsOperation, possibly from a different process.
func (*ProductSearchClient) RemoveProductFromProductSet ¶
func (c *ProductSearchClient) RemoveProductFromProductSet(ctx context.Context, req *visionpb.RemoveProductFromProductSetRequest, opts ...gax.CallOption) error
RemoveProductFromProductSet removes a Product from the specified ProductSet.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.RemoveProductFromProductSetRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#RemoveProductFromProductSetRequest. } err = c.RemoveProductFromProductSet(ctx, req) if err != nil { // TODO: Handle error. } }
Output:
func (*ProductSearchClient) UpdateProduct ¶
func (c *ProductSearchClient) UpdateProduct(ctx context.Context, req *visionpb.UpdateProductRequest, opts ...gax.CallOption) (*visionpb.Product, error)
UpdateProduct makes changes to a Product resource. Only the display_name, description, and labels fields can be updated right now.
If labels are updated, the change will not be reflected in queries until the next index time.
Possible errors:
Returns NOT_FOUND if the Product does not exist. Returns INVALID_ARGUMENT if display_name is present in update_mask but is missing from the request or longer than 4096 characters. Returns INVALID_ARGUMENT if description is present in update_mask but is longer than 4096 characters. Returns INVALID_ARGUMENT if product_category is present in update_mask.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.UpdateProductRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#UpdateProductRequest. } resp, err := c.UpdateProduct(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
func (*ProductSearchClient) UpdateProductSet ¶
func (c *ProductSearchClient) UpdateProductSet(ctx context.Context, req *visionpb.UpdateProductSetRequest, opts ...gax.CallOption) (*visionpb.ProductSet, error)
UpdateProductSet makes changes to a ProductSet resource. Only display_name can be updated currently.
Possible errors:
Returns NOT_FOUND if the ProductSet does not exist. Returns INVALID_ARGUMENT if display_name is present in update_mask but missing from the request or longer than 4096 characters.
Example ¶
package main import ( "context" vision "cloud.google.com/go/vision/apiv1" visionpb "google.golang.org/genproto/googleapis/cloud/vision/v1" ) func main() { ctx := context.Background() c, err := vision.NewProductSearchClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &visionpb.UpdateProductSetRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/google.golang.org/genproto/googleapis/cloud/vision/v1#UpdateProductSetRequest. } resp, err := c.UpdateProductSet(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output:
type ProductSetIterator ¶
type ProductSetIterator struct { // Response is the raw response for the current page. // It must be cast to the RPC response type. // Calling Next() or InternalFetch() updates this value. Response interface{} // InternalFetch is for use by the Google Cloud Libraries only. // It is not part of the stable interface of this package. // // InternalFetch returns results from a single call to the underlying RPC. // The number of results is no greater than pageSize. // If there are no more results, nextPageToken is empty and err is nil. InternalFetch func(pageSize int, pageToken string) (results []*visionpb.ProductSet, nextPageToken string, err error) // contains filtered or unexported fields }
ProductSetIterator manages a stream of *visionpb.ProductSet.
func (*ProductSetIterator) Next ¶
func (it *ProductSetIterator) Next() (*visionpb.ProductSet, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*ProductSetIterator) PageInfo ¶
func (it *ProductSetIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
type PurgeProductsOperation ¶
type PurgeProductsOperation struct {
// contains filtered or unexported fields
}
PurgeProductsOperation manages a long-running operation from PurgeProducts.
func (*PurgeProductsOperation) Done ¶
func (op *PurgeProductsOperation) Done() bool
Done reports whether the long-running operation has completed.
func (*PurgeProductsOperation) Metadata ¶
func (op *PurgeProductsOperation) Metadata() (*visionpb.BatchOperationMetadata, error)
Metadata returns metadata associated with the long-running operation. Metadata itself does not contact the server, but Poll does. To get the latest metadata, call this method after a successful call to Poll. If the metadata is not available, the returned metadata and error are both nil.
func (*PurgeProductsOperation) Name ¶
func (op *PurgeProductsOperation) Name() string
Name returns the name of the long-running operation. The name is assigned by the server and is unique within the service from which the operation is created.
func (*PurgeProductsOperation) Poll ¶
func (op *PurgeProductsOperation) Poll(ctx context.Context, opts ...gax.CallOption) error
Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds and the operation has completed with failure, the error is returned and op.Done will return true. If Poll succeeds and the operation has completed successfully, op.Done will return true, and the response of the operation is returned. If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*PurgeProductsOperation) Wait ¶
func (op *PurgeProductsOperation) Wait(ctx context.Context, opts ...gax.CallOption) error
Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
type ReferenceImageIterator ¶
type ReferenceImageIterator struct { // Response is the raw response for the current page. // It must be cast to the RPC response type. // Calling Next() or InternalFetch() updates this value. Response interface{} // InternalFetch is for use by the Google Cloud Libraries only. // It is not part of the stable interface of this package. // // InternalFetch returns results from a single call to the underlying RPC. // The number of results is no greater than pageSize. // If there are no more results, nextPageToken is empty and err is nil. InternalFetch func(pageSize int, pageToken string) (results []*visionpb.ReferenceImage, nextPageToken string, err error) // contains filtered or unexported fields }
ReferenceImageIterator manages a stream of *visionpb.ReferenceImage.
func (*ReferenceImageIterator) Next ¶
func (it *ReferenceImageIterator) Next() (*visionpb.ReferenceImage, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*ReferenceImageIterator) PageInfo ¶
func (it *ReferenceImageIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.