Class: Gcloud::Vision::Annotate

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud/vision/annotate.rb

Overview

# Annotate

Accumulates configuration for an image annotation request. Users describe the type of Google Cloud Vision API tasks to perform over images by configuring features such as ‘faces`, `landmarks`, `text`, etc. This configuration captures the Cloud Vision API vertical to operate on and the number of top-scoring results to return.

See Project#annotate.

Examples:

require "gcloud"

gcloud = Gcloud.new
vision = gcloud.vision

face_image = vision.image "path/to/face.jpg"
landmark_image = vision.image "path/to/landmark.jpg"

annotation = vision.annotate do |annotate|
   annotate.annotate face_image, faces: true, labels: true
   annotate.annotate landmark_image, landmarks: true
end

annotation.faces.count #=> 1
annotation.labels.count #=> 4
annotation.landmarks.count #=> 1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Annotate

Returns a new instance of Annotate.



55
56
57
58
# File 'lib/gcloud/vision/annotate.rb', line 55

def initialize project
  @project = project
  @requests = []
end

Instance Attribute Details

#requestsObject



51
52
53
# File 'lib/gcloud/vision/annotate.rb', line 51

def requests
  @requests
end

Instance Method Details

#annotate(*images, faces: false, landmarks: false, logos: false, labels: false, text: false, safe_search: false, properties: false) ⇒ Annotation+

Performs detection of Cloud Vision [features](cloud.google.com/vision/reference/rest/v1/images/annotate#Feature) on the given images. If no options for features are provided, all image detection features will be performed, with a default of ‘100` results for faces, landmarks, logos, and labels. If any feature option is provided, only the specified feature detections will be performed. Please review [Pricing](cloud.google.com/vision/docs/pricing) before use, as a separate charge is incurred for each feature performed on an image.

Cloud Vision sets upper limits on file size as well as on the total combined size of all images in a request. Reducing your file size can significantly improve throughput; however, be careful not to reduce image quality in the process. See [Best Practices - Image Sizing](cloud.google.com/vision/docs/image-best-practices#image_sizing) for current file size limits.

See Project#annotate for requests that do not involve multiple feature configurations.

Examples:

require "gcloud"

gcloud = Gcloud.new
vision = gcloud.vision

face_image = vision.image "path/to/face.jpg"
landmark_image = vision.image "path/to/landmark.jpg"
text_image = vision.image "path/to/text.png"

annotations = vision.annotate do |annotate|
   annotate.annotate face_image, faces: true, labels: true
   annotate.annotate landmark_image, landmarks: true
   annotate.annotate text_image, text: true
end

annotations[0].faces.count #=> 1
annotations[0].labels.count #=> 4
annotations[1].landmarks.count #=> 1
annotations[2].text.words.count #=> 28

Parameters:

  • images (Image, Object)

    The image or images to annotate. This can be an Image instance, or any other type that converts to an Image. See #image for details.

  • faces (Boolean, Integer) (defaults to: false)

    Whether to perform the facial detection feature. The maximum number of results is configured in Gcloud::Vision.default_max_faces, or may be provided here. Optional.

  • landmarks (Boolean, Integer) (defaults to: false)

    Whether to perform the landmark detection feature. The maximum number of results is configured in Gcloud::Vision.default_max_landmarks, or may be provided here. Optional.

  • logos (Boolean, Integer) (defaults to: false)

    Whether to perform the logo detection feature. The maximum number of results is configured in Gcloud::Vision.default_max_logos, or may be provided here. Optional.

  • labels (Boolean, Integer) (defaults to: false)

    Whether to perform the label detection feature. The maximum number of results is configured in Gcloud::Vision.default_max_labels, or may be provided here. Optional.

  • text (Boolean) (defaults to: false)

    Whether to perform the text (OCR) feature. Optional.

  • safe_search (Boolean) (defaults to: false)

    Whether to perform the safe search feature. Optional.

  • properties (Boolean) (defaults to: false)

    Whether to perform the image properties feature (currently, the image’s dominant colors.) Optional.

Returns:

See Also:



136
137
138
139
140
141
# File 'lib/gcloud/vision/annotate.rb', line 136

def annotate *images, faces: false, landmarks: false, logos: false,
             labels: false, text: false, safe_search: false,
             properties: false
  add_requests(images, faces, landmarks, logos, labels, text,
               safe_search, properties)
end