rtesseract 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +2 -2
- data/lib/rtesseract.rb +15 -4
- data/rtesseract.gemspec +5 -5
- data/test/test_rtesseract.rb +8 -0
- metadata +7 -7
data/Rakefile
CHANGED
|
@@ -5,14 +5,14 @@ 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.4'
|
|
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"
|
|
12
12
|
gem.homepage = "http://github.com/dannnylo/rtesseract"
|
|
13
13
|
gem.authors = ["Danilo Jeremias da Silva"]
|
|
14
14
|
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
|
15
|
-
gem.add_runtime_dependency "rmagick", '>= 2.
|
|
15
|
+
gem.add_runtime_dependency "rmagick", '>= 2.10.1'
|
|
16
16
|
end
|
|
17
17
|
Jeweler::GemcutterTasks.new
|
|
18
18
|
rescue LoadError
|
data/lib/rtesseract.rb
CHANGED
|
@@ -3,7 +3,7 @@ require "pathname"
|
|
|
3
3
|
require "tempfile"
|
|
4
4
|
|
|
5
5
|
class RTesseract
|
|
6
|
-
VERSION = '0.0.
|
|
6
|
+
VERSION = '0.0.4'
|
|
7
7
|
attr_accessor :options
|
|
8
8
|
attr_writer :lang
|
|
9
9
|
|
|
@@ -13,6 +13,7 @@ class RTesseract
|
|
|
13
13
|
@lang = options.delete(:lang) || options.delete("lang") || ""
|
|
14
14
|
@options = options
|
|
15
15
|
@value = ""
|
|
16
|
+
@x,@y,@w,@h = []
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
def source= src
|
|
@@ -27,11 +28,18 @@ class RTesseract
|
|
|
27
28
|
#Convert image to tiff
|
|
28
29
|
def image_to_tiff
|
|
29
30
|
tmp_file = Pathname.new(Dir::tmpdir).join("#{@source.basename}.tif").to_s
|
|
30
|
-
cat = Magick::
|
|
31
|
+
cat = Magick::Image.read(@source.to_s).first
|
|
32
|
+
cat.crop!(@x, @y, @w, @h) unless [@x,@y,@w,@h].compact == []
|
|
31
33
|
cat.write tmp_file.to_s
|
|
32
34
|
return tmp_file
|
|
33
35
|
end
|
|
34
36
|
|
|
37
|
+
#Crop image to convert
|
|
38
|
+
def crop!(x,y,width,height)
|
|
39
|
+
@x, @y, @w, @h = x, y, width, height
|
|
40
|
+
self
|
|
41
|
+
end
|
|
42
|
+
|
|
35
43
|
#Remove files
|
|
36
44
|
def remove_file(files=[])
|
|
37
45
|
files.each do |file|
|
|
@@ -74,14 +82,17 @@ class RTesseract
|
|
|
74
82
|
end
|
|
75
83
|
|
|
76
84
|
def config_file
|
|
77
|
-
|
|
85
|
+
return "" if @options == {}
|
|
86
|
+
conf = Tempfile.new("config")
|
|
87
|
+
conf.write(config)
|
|
88
|
+
conf.path
|
|
78
89
|
end
|
|
79
90
|
|
|
80
91
|
#Convert image to string
|
|
81
92
|
def convert
|
|
82
93
|
tmp_file = Pathname.new(Dir::tmpdir).join("#{@source.basename}")
|
|
83
94
|
tmp_image = image_to_tiff
|
|
84
|
-
`#{@command} #{tmp_image} #{tmp_file.to_s} #{lang}`
|
|
95
|
+
`#{@command} #{tmp_image} #{tmp_file.to_s} #{lang} #{config_file}`
|
|
85
96
|
@value = File.read("#{tmp_file.to_s}.txt").to_s
|
|
86
97
|
remove_file([tmp_image,"#{tmp_file.to_s}.txt"])
|
|
87
98
|
rescue
|
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.4"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Danilo Jeremias da Silva"]
|
|
12
|
-
s.date = %q{2010-
|
|
12
|
+
s.date = %q{2010-11-04}
|
|
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 = [
|
|
@@ -48,14 +48,14 @@ Gem::Specification.new do |s|
|
|
|
48
48
|
|
|
49
49
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
50
50
|
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
|
51
|
-
s.add_runtime_dependency(%q<rmagick>, [">= 2.
|
|
51
|
+
s.add_runtime_dependency(%q<rmagick>, [">= 2.10.1"])
|
|
52
52
|
else
|
|
53
53
|
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
|
54
|
-
s.add_dependency(%q<rmagick>, [">= 2.
|
|
54
|
+
s.add_dependency(%q<rmagick>, [">= 2.10.1"])
|
|
55
55
|
end
|
|
56
56
|
else
|
|
57
57
|
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
|
58
|
-
s.add_dependency(%q<rmagick>, [">= 2.
|
|
58
|
+
s.add_dependency(%q<rmagick>, [">= 2.10.1"])
|
|
59
59
|
end
|
|
60
60
|
end
|
|
61
61
|
|
data/test/test_rtesseract.rb
CHANGED
|
@@ -56,6 +56,14 @@ class TestRtesseract < Test::Unit::TestCase
|
|
|
56
56
|
assert_equal RTesseract.new(@image_tiff,{:chop_enable=>0,:enable_assoc=>0,:display_text=>0}).config , "chop_enable 0\nenable_assoc 0\ndisplay_text 0"
|
|
57
57
|
assert_equal RTesseract.new(@image_tiff,{:chop_enable=>0}).config , "chop_enable 0"
|
|
58
58
|
assert_equal RTesseract.new(@image_tiff,{:enable_assoc=>0,:chop_enable=>0}).config , "chop_enable 0\nenable_assoc 0"
|
|
59
|
+
assert_equal RTesseract.new(@image_tiff,{:chop_enable=>0}).to_s_without_spaces , "43ZZ"
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
should "crop image" do
|
|
63
|
+
assert_equal RTesseract.new(@image_tiff).crop!(140,10,36,40).to_s_without_spaces, "4"
|
|
64
|
+
assert_equal RTesseract.new(@image_tiff).crop!(180,10,36,40).to_s_without_spaces, "3"
|
|
65
|
+
assert_equal RTesseract.new(@image_tiff).crop!(200,10,36,40).to_s_without_spaces, "Z"
|
|
66
|
+
assert_equal RTesseract.new(@image_tiff).crop!(220,10,30,40).to_s_without_spaces, "Z"
|
|
59
67
|
end
|
|
60
68
|
end
|
|
61
69
|
end
|
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: 23
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 0.0.
|
|
9
|
+
- 4
|
|
10
|
+
version: 0.0.4
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Danilo Jeremias da Silva
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
|
15
15
|
bindir: bin
|
|
16
16
|
cert_chain: []
|
|
17
17
|
|
|
18
|
-
date: 2010-
|
|
18
|
+
date: 2010-11-04 00:00:00 -02:00
|
|
19
19
|
default_executable:
|
|
20
20
|
dependencies:
|
|
21
21
|
- !ruby/object:Gem::Dependency
|
|
@@ -40,12 +40,12 @@ dependencies:
|
|
|
40
40
|
requirements:
|
|
41
41
|
- - ">="
|
|
42
42
|
- !ruby/object:Gem::Version
|
|
43
|
-
hash:
|
|
43
|
+
hash: 37
|
|
44
44
|
segments:
|
|
45
45
|
- 2
|
|
46
|
-
-
|
|
46
|
+
- 10
|
|
47
47
|
- 1
|
|
48
|
-
version: 2.
|
|
48
|
+
version: 2.10.1
|
|
49
49
|
type: :runtime
|
|
50
50
|
version_requirements: *id002
|
|
51
51
|
description: Ruby library for working with the Tesseract OCR.
|