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/vision"

vision = Google::Cloud::Vision.new

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:



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

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

#localeString

The language code detected for text.

Returns:



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

def locale
  @grpc.locale
end

#textString

The text detected in an image.

Returns:

  • (String)

    The entire text including newline characters.



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

def text
  @grpc.description
end

#to_hHash

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

Returns:

  • (Hash)


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

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:



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

def words
  @words
end