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:



344
345
346
347
348
# File 'lib/google/cloud/vision/annotation/text.rb', line 344

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)


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

def break_type
  return nil if @grpc.property.nil?
  @grpc.property.detected_break &&
    @grpc.property.detected_break.type.to_sym
end

#heightInteger

Page height in pixels.

Returns:

  • (Integer)


335
336
337
# File 'lib/google/cloud/vision/annotation/text.rb', line 335

def height
  @grpc.height
end

#languagesArray<Language>

A list of detected languages together with confidence.

Returns:



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

def languages
  return [] if @grpc.property.nil?
  @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)


315
316
317
318
319
# File 'lib/google/cloud/vision/annotation/text.rb', line 315

def prefix_break?
  return nil if @grpc.property.nil?
  @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)


355
356
357
358
359
# File 'lib/google/cloud/vision/annotation/text.rb', line 355

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)


326
327
328
# File 'lib/google/cloud/vision/annotation/text.rb', line 326

def width
  @grpc.width
end