Class: Tesseract::Engine
- Inherits:
-
Object
show all
- Defined in:
- lib/tesseract/engine.rb,
lib/tesseract/engine/baseline.rb,
lib/tesseract/engine/iterator.rb,
lib/tesseract/engine/orientation.rb,
lib/tesseract/engine/bounding_box.rb,
lib/tesseract/engine/font_attributes.rb
Defined Under Namespace
Classes: Baseline, BoundingBox, FontAttributes, Iterator, Orientation
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#blacklist ⇒ Object
-
#blacklist=(value) ⇒ Object
-
#get(name) ⇒ Object
-
#hocr ⇒ Object
-
#hocr_at(x = nil, y = nil, width = nil, height = nil, page = nil) ⇒ Object
-
#hocr_for(image = nil, x = nil, y = nil, width = nil, height = nil, page = nil) ⇒ Object
-
#image=(image) ⇒ Object
-
#initialize(path = nil, language = :eng, mode = :DEFAULT, variables = {}, config = []) {|_self| ... } ⇒ Engine
constructor
-
#input=(name) ⇒ Object
-
#load_config(*config) ⇒ Object
-
#output=(name) ⇒ Object
-
#page_segmentation_mode ⇒ Object
-
#page_segmentation_mode=(value) ⇒ Object
-
#process(image, page = nil) ⇒ Object
-
#select(x = nil, y = nil, width = nil, height = nil) ⇒ Object
-
#set(name, value) ⇒ Object
-
#text ⇒ Object
-
#text_at(x = nil, y = nil, width = nil, height = nil) ⇒ Object
-
#text_for(image = nil, x = nil, y = nil, width = nil, height = nil) ⇒ Object
-
#version ⇒ Object
-
#whitelist ⇒ Object
-
#whitelist=(value) ⇒ Object
-
#with(&block) ⇒ Object
Constructor Details
#initialize(path = nil, language = :eng, mode = :DEFAULT, variables = {}, config = []) {|_self| ... } ⇒ Engine
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/tesseract/engine.rb', line 37
def initialize (path = nil, language = :eng, mode = :DEFAULT, variables = {}, config = [], &block) @api = API.new
@initializing = true
@init = block
@path = path
@language = language
@mode = mode
@variables = variables
@config = config
@rectangle = []
yield self if block_given?
@initializing = false
_init
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
32
33
34
|
# File 'lib/tesseract/engine.rb', line 32
def config
@config
end
|
Instance Method Details
#blacklist ⇒ Object
108
109
110
|
# File 'lib/tesseract/engine.rb', line 108
def blacklist
get('tessedit_char_blacklist').chars.to_a
end
|
#blacklist=(value) ⇒ Object
112
113
114
|
# File 'lib/tesseract/engine.rb', line 112
def blacklist= (value)
set('tessedit_char_blacklist', value.respond_to?(:to_a) ? value.to_a.join : value.to_s)
end
|
#get(name) ⇒ Object
92
93
94
|
# File 'lib/tesseract/engine.rb', line 92
def get (name)
@api.get_variable(name.to_s) || @variables[name]
end
|
#hocr ⇒ Object
190
191
192
|
# File 'lib/tesseract/engine.rb', line 190
def hocr
hocr_at
end
|
#hocr_at(x = nil, y = nil, width = nil, height = nil, page = nil) ⇒ Object
186
187
188
|
# File 'lib/tesseract/engine.rb', line 186
def hocr_at (x = nil, y = nil, width = nil, height = nil, page = nil)
hocr_for(nil, x, y, width, height, page)
end
|
#hocr_for(image = nil, x = nil, y = nil, width = nil, height = nil, page = nil) ⇒ Object
177
178
179
180
181
|
# File 'lib/tesseract/engine.rb', line 177
def hocr_for (image = nil, x = nil, y = nil, width = nil, height = nil, page = nil)
_setup(image, x, y, width, height)
@api.get_hocr(page || 0)
end
|
#image=(image) ⇒ Object
134
135
136
|
# File 'lib/tesseract/engine.rb', line 134
def image= (image)
@image = image
end
|
78
79
80
|
# File 'lib/tesseract/engine.rb', line 78
def input= (name)
@api.set_input_name(name)
end
|
#load_config(*config) ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/tesseract/engine.rb', line 61
def load_config (*config)
@config.concat config.flatten.compact.uniq
unless @initializing
@config.each {|conf|
@api.read_config_file(conf)
}
end
end
|
#output=(name) ⇒ Object
82
83
84
|
# File 'lib/tesseract/engine.rb', line 82
def output= (name)
@api.set_output_name(name)
end
|
#page_segmentation_mode ⇒ Object
124
125
126
|
# File 'lib/tesseract/engine.rb', line 124
def page_segmentation_mode
@api.get_page_seg_mode
end
|
#page_segmentation_mode=(value) ⇒ Object
128
129
130
131
132
|
# File 'lib/tesseract/engine.rb', line 128
def page_segmentation_mode= (value)
@psm = C.for_enum(value)
@api.set_page_seg_mode @psm
end
|
#process(image, page = nil) ⇒ Object
240
241
242
243
244
245
246
247
248
|
# File 'lib/tesseract/engine.rb', line 240
def process (image, page = nil)
if page
@api.process_page(API.image_for(image), page)
else
raise ArgumentError, 'the path does not exist' unless File.exists?(image)
@api.process_pages(image)
end
end
|
#select(x = nil, y = nil, width = nil, height = nil) ⇒ Object
141
142
143
|
# File 'lib/tesseract/engine.rb', line 141
def select (x = nil, y = nil, width = nil, height = nil)
@rectangle = [x, y, width, height]
end
|
#set(name, value) ⇒ Object
86
87
88
89
90
|
# File 'lib/tesseract/engine.rb', line 86
def set (name, value)
@variables[name] = value
@api.set_variable(name.to_s, value.to_s)
end
|
#text ⇒ Object
170
171
172
|
# File 'lib/tesseract/engine.rb', line 170
def text
text_at
end
|
#text_at(x = nil, y = nil, width = nil, height = nil) ⇒ Object
166
167
168
|
# File 'lib/tesseract/engine.rb', line 166
def text_at (x = nil, y = nil, width = nil, height = nil)
text_for(nil, x, y, width, height)
end
|
#text_for(image = nil, x = nil, y = nil, width = nil, height = nil) ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/tesseract/engine.rb', line 148
def text_for (image = nil, x = nil, y = nil, width = nil, height = nil)
_setup(image, x, y, width, height)
@api.get_text.tap {|text|
text.instance_exec(@api) {|api|
@unlv = api.get_unlv
@confidence = api.mean_text_confidence
class << self
attr_reader :unlv, :confidence
end
}
}
end
|
#version ⇒ Object
57
58
59
|
# File 'lib/tesseract/engine.rb', line 57
def version
@api.version
end
|
#whitelist ⇒ Object
116
117
118
|
# File 'lib/tesseract/engine.rb', line 116
def whitelist
get('tessedit_char_whitelist').chars.to_a
end
|
#whitelist=(value) ⇒ Object
120
121
122
|
# File 'lib/tesseract/engine.rb', line 120
def whitelist= (value)
set('tessedit_char_whitelist', value.respond_to?(:to_a) ? value.to_a.join : value.to_s)
end
|
#with(&block) ⇒ Object
71
72
73
74
75
76
|
# File 'lib/tesseract/engine.rb', line 71
def with (&block) self.class.new(@path, @language, @mode, @variables.clone, @config.clone) {|e|
@init.call(e) if @init
block.call(e) if block
}
end
|