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"

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

annotations[0].faces.count #=> 1
annotations[0].labels.count #=> 4
annotations[1].landmarks.count #=> 1

Instance Method Summary collapse

Instance Method Details

#annotate(*images, faces: false, landmarks: false, logos: false, labels: false, text: false, document: false, safe_search: false, properties: false, crop_hints: false, web: 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.pages.count #=> 1

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 detection feature (OCR for shorter documents with sparse text). Optional.

  • document (Boolean)

    Whether to perform the document text detection feature (OCR for longer documents with dense text). 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.

  • crop_hints (Boolean, Integer)

    Whether to perform the crop hints feature. Optional.

  • web (Boolean, Integer)

    Whether to perform the web annotation feature. Optional.

Returns:

See Also:



145
146
147
148
149
150
151
# File 'lib/google/cloud/vision/annotate.rb', line 145

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