3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/asposeocrjava/OCR/recognizewhitelistedcharacters.rb', line 3
def initialize()
data_dir = File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) + '/data/'
ocr_engine = Rjb::import('com.aspose.ocr.OcrEngine').new
ocr_config = ocr_engine.getConfig()
ocr_engine.setImage(Rjb::import('com.aspose.ocr.ImageStream').fromFile(data_dir + 'ocr.png'))
ocr_engine.getConfig().setRemoveNonText(true)
if ocr_engine.process()
text = ocr_engine.getText()
puts "Text: " + text.to_string
expression = "(\\d+)"
pattern = Rjb::import('java.util.regex.Pattern').compile(expression)
matcher = pattern.matcher(text.toString())
if matcher.find()
puts "Found value: " + matcher.group(0).to_string
end
end
end
|