Class: Google::Cloud::Vision::Annotate

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/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 "google/cloud/vision"

vision = Google::Cloud::Vision.new

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 Method Summary collapse

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 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 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 for current file size limits.

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

Examples:

require "google/cloud/vision"

vision = Google::Cloud::Vision.new

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)

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

  • landmarks (Boolean, Integer)

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

  • logos (Boolean, Integer)

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

  • labels (Boolean, Integer)

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

  • text (Boolean)

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

  • safe_search (Boolean)

    Whether to perform the safe search feature. Optional.

  • properties (Boolean)

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

Returns:

See Also:



138
139
140
141
142
143
# File 'lib/google/cloud/vision/annotate.rb', line 138

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