rtesseract 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/processors/mini_magick.rb +12 -0
- data/lib/processors/rmagick.rb +11 -0
- data/lib/rtesseract.rb +20 -16
- data/rtesseract.gemspec +7 -10
- metadata +9 -11
data/Rakefile
CHANGED
@@ -5,7 +5,7 @@ begin
|
|
5
5
|
require 'jeweler'
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = "rtesseract"
|
8
|
-
gem.version = '0.0.
|
8
|
+
gem.version = '0.0.8'
|
9
9
|
gem.summary = "Ruby library for working with the Tesseract OCR."
|
10
10
|
gem.description = "Ruby library for working with the Tesseract OCR."
|
11
11
|
gem.email = "dannnylo@gmail.com"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'mini_magick'
|
2
|
+
module MiniMagickProcessor
|
3
|
+
def image_to_tiff
|
4
|
+
generate_uid
|
5
|
+
tmp_file = Pathname.new(Dir::tmpdir).join("#{@uid}_#{@source.basename}.tif").to_s
|
6
|
+
cat = MiniMagick::Image.open(@source.to_s)
|
7
|
+
cat.format("tif")
|
8
|
+
cat.crop("#{@w}x#{@h}+#{@x}+#{@y}") unless [@x, @y, @w, @h].compact == []
|
9
|
+
cat.write tmp_file.to_s
|
10
|
+
return tmp_file
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "RMagick"
|
2
|
+
module RMagickProcessor
|
3
|
+
def image_to_tiff
|
4
|
+
generate_uid
|
5
|
+
tmp_file = Pathname.new(Dir::tmpdir).join("#{@uid}_#{@source.basename}.tif").to_s
|
6
|
+
cat = Magick::Image.read(@source.to_s).first
|
7
|
+
cat.crop!(@x, @y, @w, @h) unless [@x, @y, @w, @h].compact == []
|
8
|
+
cat.write tmp_file.to_s
|
9
|
+
return tmp_file
|
10
|
+
end
|
11
|
+
end
|
data/lib/rtesseract.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require "RMagick"
|
2
1
|
require "pathname"
|
3
2
|
require "tempfile"
|
4
3
|
|
@@ -6,22 +5,25 @@ require "rtesseract/errors"
|
|
6
5
|
require "rtesseract/mixed"
|
7
6
|
|
8
7
|
class RTesseract
|
9
|
-
VERSION = '0.0.
|
8
|
+
VERSION = '0.0.8'
|
10
9
|
attr_accessor :options
|
11
10
|
attr_writer :lang
|
12
11
|
attr_writer :psm
|
12
|
+
attr_reader :processor
|
13
13
|
|
14
|
-
def initialize(src="", options={})
|
15
|
-
@uid
|
14
|
+
def initialize(src = "", options = {})
|
15
|
+
@uid = options.delete(:uid) || nil
|
16
16
|
@source = Pathname.new src
|
17
17
|
@command = options.delete(:command) || "tesseract"
|
18
|
-
@lang = options.delete(:lang)
|
19
|
-
@psm
|
18
|
+
@lang = options.delete(:lang) || options.delete("lang") || ""
|
19
|
+
@psm = options.delete(:psm) || options.delete("psm") || nil
|
20
20
|
@clear_console_output = options.delete(:clear_console_output)
|
21
21
|
@clear_console_output = true if @clear_console_output.nil?
|
22
22
|
@options = options
|
23
23
|
@value = ""
|
24
|
-
@x
|
24
|
+
@x, @y, @w, @h = []
|
25
|
+
@processor = options.delete(:processor) || options.delete("processor")
|
26
|
+
choose_processor!
|
25
27
|
end
|
26
28
|
|
27
29
|
def source= src
|
@@ -33,15 +35,6 @@ class RTesseract
|
|
33
35
|
@source.basename
|
34
36
|
end
|
35
37
|
|
36
|
-
#Convert image to tiff
|
37
|
-
def image_to_tiff
|
38
|
-
generate_uid
|
39
|
-
tmp_file = Pathname.new(Dir::tmpdir).join("#{@uid}_#{@source.basename}.tif").to_s
|
40
|
-
cat = Magick::Image.read(@source.to_s).first
|
41
|
-
cat.crop!(@x, @y, @w, @h) unless [@x,@y,@w,@h].compact == []
|
42
|
-
cat.write tmp_file.to_s
|
43
|
-
return tmp_file
|
44
|
-
end
|
45
38
|
|
46
39
|
#Crop image to convert
|
47
40
|
def crop!(x,y,width,height)
|
@@ -149,5 +142,16 @@ class RTesseract
|
|
149
142
|
def to_s_without_spaces
|
150
143
|
to_s.gsub(" ","").gsub("\n","").gsub("\r","")
|
151
144
|
end
|
145
|
+
|
146
|
+
private
|
147
|
+
def choose_processor!
|
148
|
+
if @processor.to_s == "mini_magick"
|
149
|
+
require File.expand_path(File.dirname(__FILE__) + "/processors/mini_magick.rb")
|
150
|
+
self.class.send(:include, MiniMagickProcessor)
|
151
|
+
else
|
152
|
+
require File.expand_path(File.dirname(__FILE__) + "/processors/rmagick.rb")
|
153
|
+
self.class.send(:include, RMagickProcessor)
|
154
|
+
end
|
155
|
+
end
|
152
156
|
end
|
153
157
|
|
data/rtesseract.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{rtesseract}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date = %q{2011-
|
11
|
+
s.authors = [%q{Danilo Jeremias da Silva}]
|
12
|
+
s.date = %q{2011-09-20}
|
13
13
|
s.description = %q{Ruby library for working with the Tesseract OCR.}
|
14
14
|
s.email = %q{dannnylo@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -21,6 +21,8 @@ Gem::Specification.new do |s|
|
|
21
21
|
"LICENSE",
|
22
22
|
"README.rdoc",
|
23
23
|
"Rakefile",
|
24
|
+
"lib/processors/mini_magick.rb",
|
25
|
+
"lib/processors/rmagick.rb",
|
24
26
|
"lib/rtesseract.rb",
|
25
27
|
"lib/rtesseract/errors.rb",
|
26
28
|
"lib/rtesseract/mixed.rb",
|
@@ -36,14 +38,9 @@ Gem::Specification.new do |s|
|
|
36
38
|
"test/test_rtesseract.rb"
|
37
39
|
]
|
38
40
|
s.homepage = %q{http://github.com/dannnylo/rtesseract}
|
39
|
-
s.require_paths = [
|
40
|
-
s.rubygems_version = %q{1.
|
41
|
+
s.require_paths = [%q{lib}]
|
42
|
+
s.rubygems_version = %q{1.8.7}
|
41
43
|
s.summary = %q{Ruby library for working with the Tesseract OCR.}
|
42
|
-
s.test_files = [
|
43
|
-
"test/helper.rb",
|
44
|
-
"test/test_mixed.rb",
|
45
|
-
"test/test_rtesseract.rb"
|
46
|
-
]
|
47
44
|
|
48
45
|
if s.respond_to? :specification_version then
|
49
46
|
s.specification_version = 3
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rtesseract
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Danilo Jeremias da Silva
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-09-20 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: jeweler
|
@@ -78,6 +77,8 @@ files:
|
|
78
77
|
- LICENSE
|
79
78
|
- README.rdoc
|
80
79
|
- Rakefile
|
80
|
+
- lib/processors/mini_magick.rb
|
81
|
+
- lib/processors/rmagick.rb
|
81
82
|
- lib/rtesseract.rb
|
82
83
|
- lib/rtesseract/errors.rb
|
83
84
|
- lib/rtesseract/mixed.rb
|
@@ -91,7 +92,6 @@ files:
|
|
91
92
|
- test/images/test1.tif
|
92
93
|
- test/test_mixed.rb
|
93
94
|
- test/test_rtesseract.rb
|
94
|
-
has_rdoc: true
|
95
95
|
homepage: http://github.com/dannnylo/rtesseract
|
96
96
|
licenses: []
|
97
97
|
|
@@ -121,11 +121,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
121
121
|
requirements: []
|
122
122
|
|
123
123
|
rubyforge_project:
|
124
|
-
rubygems_version: 1.
|
124
|
+
rubygems_version: 1.8.7
|
125
125
|
signing_key:
|
126
126
|
specification_version: 3
|
127
127
|
summary: Ruby library for working with the Tesseract OCR.
|
128
|
-
test_files:
|
129
|
-
|
130
|
-
- test/test_mixed.rb
|
131
|
-
- test/test_rtesseract.rb
|
128
|
+
test_files: []
|
129
|
+
|