Class: Google::Cloud::Vision::Annotation::Text::Word

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

Overview

Word

A word within a detected text (OCR). See Google::Cloud::Vision::Annotation::Text.

Examples:

require "google/cloud"

gcloud = Google::Cloud.new
vision = gcloud.vision

image = vision.image "path/to/text.png"
text = image.text

words = text.words
words.count #=> 28

word = words.first
word.text #=> "Google"
word.bounds.count #=> 4
word.bounds.first #=> #<Vertex (x: 13, y: 8)>

Instance Method Summary collapse

Instance Method Details

#boundsArray<Vertex>

The bounds of the word within the detected text.

Returns:



180
181
182
183
184
185
# File 'lib/google/cloud/vision/annotation/text.rb', line 180

def bounds
  return [] unless @gapi.bounding_poly
  @bounds ||= Array(@gapi.bounding_poly.vertices).map do |v|
    Vertex.from_gapi v
  end
end

#textString

The text of the word.

Returns:

  • (String)


171
172
173
# File 'lib/google/cloud/vision/annotation/text.rb', line 171

def text
  @gapi.description
end

#to_hHash

Deeply converts object to a hash. All keys will be symbolized.

Returns:

  • (Hash)


192
193
194
# File 'lib/google/cloud/vision/annotation/text.rb', line 192

def to_h
  { text: text, bounds: bounds.map(&:to_h) }
end