Documentation ¶
Overview ¶
Integrates Google Vision features, including image labeling, face, logo, and landmark detection, optical character recognition (OCR), and detection of explicit content, into applications.
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 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) 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)
- type Mouth
- type Nose
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultAuthScopes ¶ added in v0.8.0
func DefaultAuthScopes() []string
DefaultAuthScopes reports the default set of authentication scopes to use with this package.
func NewImageFromReader ¶ added in v0.8.0
NewImageFromReader reads the bytes of an image from r.
func NewImageFromURI ¶ added in v0.8.0
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 ¶ added in v0.24.0
type AsyncBatchAnnotateFilesOperation struct {
// contains filtered or unexported fields
}
AsyncBatchAnnotateFilesOperation manages a long-running operation from AsyncBatchAnnotateFiles.
func (*AsyncBatchAnnotateFilesOperation) Done ¶ added in v0.24.0
func (op *AsyncBatchAnnotateFilesOperation) Done() bool
Done reports whether the long-running operation has completed.
func (*AsyncBatchAnnotateFilesOperation) Metadata ¶ added in v0.24.0
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 ¶ added in v0.24.0
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 ¶ added in v0.24.0
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 ¶ added in v0.24.0
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 Eyebrows ¶ added in v0.8.0
type Eyebrows struct {
Left, Right Eyebrow
}
Eyebrows represents a face's eyebrows.
type FaceLandmarks ¶ added in v0.8.0
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 ¶ added in v0.8.0
func FaceFromLandmarks(landmarks []*pb.FaceAnnotation_Landmark) *FaceLandmarks
FaceFromLandmarks converts the list of face landmarks returned by the service to a FaceLandmarks struct.
type ImageAnnotatorCallOptions ¶ added in v0.3.0
type ImageAnnotatorCallOptions struct { BatchAnnotateImages []gax.CallOption AsyncBatchAnnotateFiles []gax.CallOption }
ImageAnnotatorCallOptions contains the retry settings for each method of ImageAnnotatorClient.
type ImageAnnotatorClient ¶ added in v0.3.0
type ImageAnnotatorClient struct { // LROClient is used internally to handle longrunning operations. // It is exposed so that its CallOptions can be modified if required. // Users should not Close this client. LROClient *lroauto.OperationsClient // The call options for this service. CallOptions *ImageAnnotatorCallOptions // 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.
func NewImageAnnotatorClient ¶ added in v0.3.0
func NewImageAnnotatorClient(ctx context.Context, opts ...option.ClientOption) (*ImageAnnotatorClient, error)
NewImageAnnotatorClient creates a new image annotator client.
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 ¶
ctx := context.Background() c, err := vision.NewImageAnnotatorClient(ctx) if err != nil { // TODO: Handle error. } // TODO: Use client. _ = c
Output:
func (*ImageAnnotatorClient) AnnotateImage ¶ added in v0.8.0
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 ( vision "cloud.google.com/go/vision/apiv1" "golang.org/x/net/context" 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 ¶ added in v0.24.0
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 ¶
ctx := context.Background() c, err := vision.NewImageAnnotatorClient(ctx) if err != nil { // TODO: Handle error. } req := &visionpb.AsyncBatchAnnotateFilesRequest{ // TODO: Fill request struct fields. } 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 ¶ added in v0.24.0
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) BatchAnnotateImages ¶ added in v0.3.0
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 ¶
ctx := context.Background() c, err := vision.NewImageAnnotatorClient(ctx) if err != nil { // TODO: Handle error. } req := &visionpb.BatchAnnotateImagesRequest{ // TODO: Fill request struct fields. } resp, err := c.BatchAnnotateImages(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp
Output:
func (*ImageAnnotatorClient) Close ¶ added in v0.3.0
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 ¶ added in v0.3.0
func (c *ImageAnnotatorClient) Connection() *grpc.ClientConn
Connection returns the client's connection to the API service.
func (*ImageAnnotatorClient) CropHints ¶ added in v0.8.0
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 ¶ added in v0.8.0
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 ¶ added in v0.8.0
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 ¶ added in v0.8.0
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 ¶ added in v0.8.0
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 ¶ added in v0.8.0
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 ¶ added in v0.8.0
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 ¶ added in v0.8.0
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 ¶ added in v0.8.0
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 ¶ added in v0.8.0
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 ¶ added in v0.29.0
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.