Class: Google::Cloud::Vision::Image
- Inherits:
-
Object
- Object
- Google::Cloud::Vision::Image
- Defined in:
- lib/google/cloud/vision/image.rb,
lib/google/cloud/vision/image.rb
Overview
Image
Represents an image for the Vision service.
An Image instance can be created from a string file path, publicly-
accessible image HTTP/HTTPS URL, or Cloud Storage URI of the form
"gs://bucketname/path/to/image_filename"
; or a File, IO, StringIO, or
Tempfile instance; or an instance of Google::Cloud::Storage::File.
See Project#image.
The Cloud Vision API supports a variety of image file formats, including JPEG, PNG8, PNG24, Animated GIF (first frame only), and RAW. See Best Practices - Image Types for the list of formats. Be aware that Cloud Vision sets upper limits on file size as well as 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.
Defined Under Namespace
Classes: Context
Instance Attribute Summary collapse
-
#context ⇒ Context
readonly
Returns the image context for the image, which accepts metadata values such as location and language hints.
Instance Method Summary collapse
-
#annotate(faces: false, landmarks: false, logos: false, labels: false, text: false, document: false, safe_search: false, properties: false, crop_hints: false, web: false) ⇒ Annotation
(also: #mark, #detect)
Performs detection of Cloud Vision features on the image.
-
#crop_hints(max_results = Vision.default_max_crop_hints) ⇒ Array<Annotation::CropHint>
Performs the
CROP_HINTS
feature on the image. -
#document ⇒ Annotation::Text
Performs the
DOCUMENT_TEXT_DETECTION
feature (OCR for longer documents with dense text) on the image. -
#face ⇒ Annotation::Face
Performs the
FACE_DETECTION
feature on the image and returns only the first result. -
#faces(max_results = Vision.default_max_faces) ⇒ Array<Annotation::Face>
Performs the
FACE_DETECTION
feature on the image. -
#label ⇒ Annotation::Entity
Performs the
LABEL_DETECTION
feature on the image and returns only the first result. -
#labels(max_results = Vision.default_max_labels) ⇒ Array<Annotation::Entity>
Performs the
LABEL_DETECTION
feature on the image. -
#landmark ⇒ Annotation::Entity
Performs the
LANDMARK_DETECTION
feature on the image and returns only the first result. -
#landmarks(max_results = Vision.default_max_landmarks) ⇒ Array<Annotation::Entity>
Performs the
LANDMARK_DETECTION
feature on the image. -
#logo ⇒ Annotation::Entity
Performs the
LOGO_DETECTION
feature on the image and returns only the first result. -
#logos(max_results = Vision.default_max_logos) ⇒ Array<Annotation::Entity>
Performs the
LOGO_DETECTION
feature on the image. -
#properties ⇒ Annotation::Properties
Performs the
IMAGE_PROPERTIES
feature on the image. -
#safe_search ⇒ Annotation::SafeSearch
Performs the
SAFE_SEARCH_DETECTION
feature on the image. -
#text ⇒ Annotation::Text
Performs the
TEXT_DETECTION
feature (OCR for shorter documents with sparse text) on the image. -
#web(max_results = Vision.default_max_web) ⇒ Annotation::Web
Performs the
WEB_ANNOTATION
feature on the image.
Instance Attribute Details
#context ⇒ Context (readonly)
Returns the image context for the image, which accepts metadata values such as location and language hints.
66 67 68 |
# File 'lib/google/cloud/vision/image.rb', line 66 def context @context end |
Instance Method Details
#annotate(faces: false, landmarks: false, logos: false, labels: false, text: false, document: false, safe_search: false, properties: false, crop_hints: false, web: false) ⇒ Annotation Also known as: mark, detect
Performs detection of Cloud Vision
features
on the image. If no options for features are provided, all image
detection features will be performed, with a default of 100
results
for faces, landmarks, logos, labels, crop_hints, and web. 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.
514 515 516 517 518 519 520 521 522 523 |
# File 'lib/google/cloud/vision/image.rb', line 514 def annotate faces: false, landmarks: false, logos: false, labels: false, text: false, document: false, safe_search: false, properties: false, crop_hints: false, web: false @vision.annotate(self, faces: faces, landmarks: landmarks, logos: logos, labels: labels, text: text, document: document, safe_search: safe_search, properties: properties, crop_hints: crop_hints, web: web) end |
#crop_hints(max_results = Vision.default_max_crop_hints) ⇒ Array<Annotation::CropHint>
Performs the CROP_HINTS
feature on the image.
397 398 399 400 401 |
# File 'lib/google/cloud/vision/image.rb', line 397 def crop_hints max_results = Vision.default_max_crop_hints ensure_vision! annotation = @vision.mark self, crop_hints: max_results annotation.crop_hints end |
#document ⇒ Annotation::Text
Performs the DOCUMENT_TEXT_DETECTION
feature (OCR for longer
documents with dense text) on the image.
317 318 319 320 321 |
# File 'lib/google/cloud/vision/image.rb', line 317 def document ensure_vision! annotation = @vision.mark self, document: true annotation.text end |
#face ⇒ Annotation::Face
Performs the FACE_DETECTION
feature on the image and returns only
the first result.
127 128 129 |
# File 'lib/google/cloud/vision/image.rb', line 127 def face faces(1).first end |
#faces(max_results = Vision.default_max_faces) ⇒ Array<Annotation::Face>
Performs the FACE_DETECTION
feature on the image.
115 116 117 118 119 |
# File 'lib/google/cloud/vision/image.rb', line 115 def faces max_results = Vision.default_max_faces ensure_vision! annotation = @vision.mark self, faces: max_results annotation.faces end |
#label ⇒ Annotation::Entity
Performs the LABEL_DETECTION
feature on the image and returns only
the first result.
245 246 247 |
# File 'lib/google/cloud/vision/image.rb', line 245 def label labels(1).first end |
#labels(max_results = Vision.default_max_labels) ⇒ Array<Annotation::Entity>
Performs the LABEL_DETECTION
feature on the image.
233 234 235 236 237 |
# File 'lib/google/cloud/vision/image.rb', line 233 def labels max_results = Vision.default_max_labels ensure_vision! annotation = @vision.mark self, labels: max_results annotation.labels end |
#landmark ⇒ Annotation::Entity
Performs the LANDMARK_DETECTION
feature on the image and returns
only the first result.
166 167 168 |
# File 'lib/google/cloud/vision/image.rb', line 166 def landmark landmarks(1).first end |
#landmarks(max_results = Vision.default_max_landmarks) ⇒ Array<Annotation::Entity>
Performs the LANDMARK_DETECTION
feature on the image.
154 155 156 157 158 |
# File 'lib/google/cloud/vision/image.rb', line 154 def landmarks max_results = Vision.default_max_landmarks ensure_vision! annotation = @vision.mark self, landmarks: max_results annotation.landmarks end |
#logo ⇒ Annotation::Entity
Performs the LOGO_DETECTION
feature on the image and returns only
the first result.
205 206 207 |
# File 'lib/google/cloud/vision/image.rb', line 205 def logo logos(1).first end |
#logos(max_results = Vision.default_max_logos) ⇒ Array<Annotation::Entity>
Performs the LOGO_DETECTION
feature on the image.
193 194 195 196 197 |
# File 'lib/google/cloud/vision/image.rb', line 193 def logos max_results = Vision.default_max_logos ensure_vision! annotation = @vision.mark self, logos: max_results annotation.logos end |
#properties ⇒ Annotation::Properties
Performs the IMAGE_PROPERTIES
feature on the image.
369 370 371 372 373 |
# File 'lib/google/cloud/vision/image.rb', line 369 def properties ensure_vision! annotation = @vision.mark self, properties: true annotation.properties end |
#safe_search ⇒ Annotation::SafeSearch
Performs the SAFE_SEARCH_DETECTION
feature on the image.
341 342 343 344 345 |
# File 'lib/google/cloud/vision/image.rb', line 341 def safe_search ensure_vision! annotation = @vision.mark self, safe_search: true annotation.safe_search end |
#text ⇒ Annotation::Text
Performs the TEXT_DETECTION
feature (OCR for shorter documents with
sparse text) on the image.
281 282 283 284 285 |
# File 'lib/google/cloud/vision/image.rb', line 281 def text ensure_vision! annotation = @vision.mark self, text: true annotation.text end |
#web(max_results = Vision.default_max_web) ⇒ Annotation::Web
Performs the WEB_ANNOTATION
feature on the image.
431 432 433 434 435 |
# File 'lib/google/cloud/vision/image.rb', line 431 def web max_results = Vision.default_max_web ensure_vision! annotation = @vision.mark self, web: max_results annotation.web end |