Class: Google::Cloud::Vision::Image::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/vision/image.rb

Overview

# Image::Context

Represents an image context.

Examples:

require "google/cloud/vision"

vision = Google::Cloud::Vision.new

image = vision.image "path/to/landmark.jpg"
image.context.area.min = { longitude: -122.0862462,
                           latitude: 37.4220041 }
image.context.area.max = { longitude: -122.0762462,
                           latitude: 37.4320041 }

Defined Under Namespace

Classes: Area

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



447
448
449
450
# File 'lib/google/cloud/vision/image.rb', line 447

def initialize
  @area = Area.new
  @languages = []
end

Instance Attribute Details

#areaArea (readonly)

Returns a lat/long rectangle that specifies the location of the image.

Returns:

  • (Area)

    The lat/long pairs for ‘latLongRect`.



441
442
443
# File 'lib/google/cloud/vision/image.rb', line 441

def area
  @area
end

#languagesArray<String>

A list of [ISO 639-1 language codes](en.wikipedia.org/wiki/List_of_ISO_639-1_codes) to use for text (OCR) detection. In most cases, an empty value will yield the best results as it will allow text detection to automatically detect the text language. For languages based on the latin alphabet a hint is not needed. In rare cases, when the language of the text in the image is known in advance, setting this hint will help get better results (although it will hurt a great deal if the hint is wrong).

Returns:

  • (Array<String>)

    the current value of languages



436
437
438
# File 'lib/google/cloud/vision/image.rb', line 436

def languages
  @languages
end

Instance Method Details

#empty?Boolean

Returns ‘true` if either `min` or `max` are not populated.

Returns:

  • (Boolean)


457
458
459
# File 'lib/google/cloud/vision/image.rb', line 457

def empty?
  area.empty? && languages.empty?
end

#to_grpcObject



463
464
465
466
467
468
469
470
# File 'lib/google/cloud/vision/image.rb', line 463

def to_grpc
  return nil if empty?

  args = {}
  args[:lat_long_rect] = area.to_grpc unless area.empty?
  args[:language_hints] = languages unless languages.empty?
  Google::Cloud::Vision::V1::ImageContext.new args
end