Class: Gcloud::Vision::Annotation::Text
- Inherits:
-
Object
- Object
- Gcloud::Vision::Annotation::Text
- Defined in:
- lib/gcloud/vision/annotation/text.rb
Overview
# Text
The result of text, or optical character recognition (OCR), detection.
Defined Under Namespace
Classes: Word
Instance Attribute Summary collapse
Class Method Summary collapse
-
.from_gapi(gapi_list) ⇒ Object
objects.
Instance Method Summary collapse
-
#bounds ⇒ Array<Vertex>
The bounds for the detected text in the image.
-
#initialize ⇒ Text
constructor
A new instance of Text.
- #inspect ⇒ Object
-
#locale ⇒ String
The language code detected for ‘text`.
-
#text ⇒ String
The text detected in an image.
-
#to_h ⇒ Hash
Deeply converts object to a hash.
-
#to_hash ⇒ Hash
Deeply converts object to a hash.
- #to_s ⇒ Object
- #to_str ⇒ Object
-
#words ⇒ Array<Word>
Each word in the detected text, with the bounds for each word.
Constructor Details
#initialize ⇒ Text
Returns a new instance of Text.
47 48 49 50 |
# File 'lib/gcloud/vision/annotation/text.rb', line 47 def initialize @gapi = {} @words = [] end |
Instance Attribute Details
#gapi ⇒ Object
43 44 45 |
# File 'lib/gcloud/vision/annotation/text.rb', line 43 def gapi @gapi end |
Class Method Details
.from_gapi(gapi_list) ⇒ Object
objects.
131 132 133 134 135 136 137 138 |
# File 'lib/gcloud/vision/annotation/text.rb', line 131 def self.from_gapi gapi_list text, *words = Array gapi_list return nil if text.nil? new.tap do |t| t.instance_variable_set :@gapi, text t.instance_variable_set :@words, words.map { |w| Word.from_gapi w } end end |
Instance Method Details
#bounds ⇒ Array<Vertex>
The bounds for the detected text in the image.
77 78 79 80 81 82 |
# File 'lib/gcloud/vision/annotation/text.rb', line 77 def bounds return [] unless @gapi.bounding_poly @bounds ||= Array(@gapi.bounding_poly.vertices).map do |v| Vertex.from_gapi v end end |
#inspect ⇒ Object
123 124 125 126 |
# File 'lib/gcloud/vision/annotation/text.rb', line 123 def inspect format "#<Text text: %s, locale: %s, bounds: %i, words: %i>", text.inspect, locale.inspect, bounds.count, words.count end |
#locale ⇒ String
The language code detected for ‘text`.
68 69 70 |
# File 'lib/gcloud/vision/annotation/text.rb', line 68 def locale @gapi.locale end |
#text ⇒ String
The text detected in an image.
57 58 59 |
# File 'lib/gcloud/vision/annotation/text.rb', line 57 def text @gapi.description end |
#to_h ⇒ Hash
Deeply converts object to a hash. All keys will be symbolized.
98 99 100 |
# File 'lib/gcloud/vision/annotation/text.rb', line 98 def to_h to_hash end |
#to_hash ⇒ Hash
Deeply converts object to a hash. All keys will be symbolized.
107 108 109 110 |
# File 'lib/gcloud/vision/annotation/text.rb', line 107 def to_hash { text: text, locale: locale, bounds: bounds.map(&:to_h), words: words.map(&:to_h) } end |
#to_s ⇒ Object
113 114 115 |
# File 'lib/gcloud/vision/annotation/text.rb', line 113 def to_s to_str end |
#to_str ⇒ Object
118 119 120 |
# File 'lib/gcloud/vision/annotation/text.rb', line 118 def to_str text end |
#words ⇒ Array<Word>
Each word in the detected text, with the bounds for each word.
89 90 91 |
# File 'lib/gcloud/vision/annotation/text.rb', line 89 def words @words end |