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

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

Overview

Page

A page within a detected text (OCR). See #pages.

Examples:

require "google/cloud/vision"

vision = Google::Cloud::Vision.new

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

text = image.text

page = text.pages.first

page.languages.first.code #=> "en"
page.wont_be :prefix_break?
page.width #=> 400
page.height #=> 80
page.blocks.count #=> 1

Defined Under Namespace

Classes: Block, Language, Paragraph, Symbol, Word

Instance Method Summary collapse

Instance Method Details

#blocksArray<Block>

List of blocks of text, images etc on this page.

Returns:



341
342
343
344
345
# File 'lib/google/cloud/vision/annotation/text.rb', line 341

def blocks
  @blocks ||= Array(@grpc.blocks).map do |b|
    Block.from_grpc b
  end
end

#break_type::Symbol

The type of a detected break at the start or end of the page.

Returns:

  • (::Symbol)


303
304
305
306
# File 'lib/google/cloud/vision/annotation/text.rb', line 303

def break_type
  @grpc.property.detected_break &&
    @grpc.property.detected_break.type.to_sym
end

#heightInteger

Page height in pixels.

Returns:

  • (Integer)


332
333
334
# File 'lib/google/cloud/vision/annotation/text.rb', line 332

def height
  @grpc.height
end

#languagesArray<Language>

A list of detected languages together with confidence.

Returns:



292
293
294
295
296
# File 'lib/google/cloud/vision/annotation/text.rb', line 292

def languages
  @languages ||= Array(@grpc.property.detected_languages).map do |l|
    Language.from_grpc l
  end
end

#prefix_break?Boolean

True if a detected break prepends the page.

Returns:

  • (Boolean)


313
314
315
316
# File 'lib/google/cloud/vision/annotation/text.rb', line 313

def prefix_break?
  @grpc.property.detected_break &&
    @grpc.property.detected_break.is_prefix
end

#to_hHash

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

Returns:

  • (Hash)


352
353
354
355
356
# File 'lib/google/cloud/vision/annotation/text.rb', line 352

def to_h
  { languages: languages.map(&:to_h), break_type: break_type,
    prefix_break: prefix_break?, width: width, height: height,
    blocks: blocks.map(&:to_h) }
end

#widthInteger

Page width in pixels.

Returns:

  • (Integer)


323
324
325
# File 'lib/google/cloud/vision/annotation/text.rb', line 323

def width
  @grpc.width
end