Class: RTesseract::Uzn

Inherits:
RTesseract show all
Defined in:
lib/rtesseract/uzn.rb

Overview

Alternative approach to Mixed when you want to read from specific areas. Requires ‘-psm 4` which means the text must be “a single column of text of variable sizes”.

Constant Summary collapse

DEFAULT_ALPHABET =
'Text/Latin'

Constants inherited from RTesseract

LANGUAGES

Instance Attribute Summary collapse

Attributes inherited from RTesseract

#configuration, #processor, #source

Instance Method Summary collapse

Methods inherited from RTesseract

#clean, #clear_console_output, clear_pdf_option, #config, #config_file, #config_hook, configure, #convert, #convert_pdf, #convert_result, #convert_text, #crop!, default_command, #file_dest, #file_ext, #file_with_ext, #from_blob, #image, #initialize_hook, #lang, local_config, #oem, #option_to_string, #options_cmd, #pdf?, #psm, #read, read, #tessdata_dir, #tesseract_version, #to_pdf, #to_s, #to_s_without_spaces, #user_patterns, #user_words

Constructor Details

#initialize(src = '', options = {}) {|_self| ... } ⇒ Uzn

Returns a new instance of Uzn.

Yields:

  • (_self)

Yield Parameters:



10
11
12
13
14
15
# File 'lib/rtesseract/uzn.rb', line 10

def initialize(src = '', options = {})
  @areas = options.delete(:areas) || []
  @alphabet = options.delete(:alphabet) || DEFAULT_ALPHABET
  super(src, options.merge(psm: 4))
  yield self if block_given?
end

Instance Attribute Details

#areasObject (readonly)

Returns the value of attribute areas.



7
8
9
# File 'lib/rtesseract/uzn.rb', line 7

def areas
  @areas
end

Instance Method Details

#after_convert_hookObject



28
29
30
# File 'lib/rtesseract/uzn.rb', line 28

def after_convert_hook
  RTesseract::Utils.remove_files([@uzn_file])
end

#area(points) ⇒ Object

Add areas



18
19
20
# File 'lib/rtesseract/uzn.rb', line 18

def area(points)
  areas << points
end

#convert_commandObject



22
23
24
25
26
# File 'lib/rtesseract/uzn.rb', line 22

def convert_command
  @image = image
  write_uzn_file
  `#{configuration.command} "#{@image}" "#{file_dest}" #{lang} #{psm} #{tessdata_dir} #{user_words} #{user_patterns} #{config_file} #{clear_console_output} #{options_cmd.join(' ')}`
end