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

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

Overview

Text

The result of text, or optical character recognition (OCR), detection.

Examples:

require "google/cloud"

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

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

text = image.text
text.locale #=> "en"
text.words.count #=> 28
text.text
#=> "Google Cloud Client for Ruby an idiomatic, intuitive... "

Defined Under Namespace

Classes: Word

Instance Method Summary collapse

Instance Method Details

#boundsArray<Vertex>

The bounds for the detected text in the image.

Returns:



78
79
80
81
82
83
# File 'lib/google/cloud/vision/annotation/text.rb', line 78

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

#localeString

The language code detected for text.

Returns:



69
70
71
# File 'lib/google/cloud/vision/annotation/text.rb', line 69

def locale
  @gapi.locale
end

#textString

The text detected in an image.

Returns:

  • (String)

    The entire text including newline characters.



58
59
60
# File 'lib/google/cloud/vision/annotation/text.rb', line 58

def text
  @gapi.description
end

#to_hHash

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

Returns:

  • (Hash)


99
100
101
102
# File 'lib/google/cloud/vision/annotation/text.rb', line 99

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

#wordsArray<Word>

Each word in the detected text, with the bounds for each word.

Returns:



90
91
92
# File 'lib/google/cloud/vision/annotation/text.rb', line 90

def words
  @words
end