rtesseract 0.0.5 → 0.0.6
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 +1 -1
- data/lib/rtesseract.rb +4 -1
- data/lib/rtesseract/errors.rb +4 -0
- data/lib/rtesseract/mixed.rb +53 -0
- data/rtesseract.gemspec +8 -4
- data/test/images/mixed.tif +0 -0
- data/test/test_mixed.rb +28 -0
- metadata +11 -6
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.6'
|
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"
|
data/lib/rtesseract.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
class RTesseract
|
2
|
+
class Mixed
|
3
|
+
def initialize(src="", options={})
|
4
|
+
@source = Pathname.new src
|
5
|
+
@options = options
|
6
|
+
@value = ""
|
7
|
+
@areas = options.delete(:areas) || []
|
8
|
+
yield self if block_given?
|
9
|
+
end
|
10
|
+
|
11
|
+
def area(x, y, width, height)
|
12
|
+
@value = ""
|
13
|
+
@areas << {:x => x, :y => y, :width => width, :height => height}
|
14
|
+
end
|
15
|
+
|
16
|
+
def areas
|
17
|
+
@areas
|
18
|
+
end
|
19
|
+
|
20
|
+
def clear_areas
|
21
|
+
@areas = []
|
22
|
+
end
|
23
|
+
|
24
|
+
#Convert parts of image to string
|
25
|
+
def convert
|
26
|
+
@value = ""
|
27
|
+
@areas.each do |area|
|
28
|
+
image = RTesseract.new(@source.to_s,@options)
|
29
|
+
image.crop!(area[:x].to_i, area[:y].to_i, area[:width].to_i, area[:height].to_i)
|
30
|
+
@value << image.to_s
|
31
|
+
end
|
32
|
+
rescue
|
33
|
+
raise RTesseract::ConversionError
|
34
|
+
end
|
35
|
+
|
36
|
+
#Output value
|
37
|
+
def to_s
|
38
|
+
return @value if @value != ""
|
39
|
+
if @source.file?
|
40
|
+
convert
|
41
|
+
@value
|
42
|
+
else
|
43
|
+
raise "Select a image file."
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
#Remove spaces and break-lines
|
48
|
+
def to_s_without_spaces
|
49
|
+
to_s.gsub(" ","").gsub("\n","").gsub("\r","")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
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.6"
|
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{
|
12
|
+
s.date = %q{2011-03-02}
|
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 = [
|
@@ -22,26 +22,30 @@ Gem::Specification.new do |s|
|
|
22
22
|
"README.rdoc",
|
23
23
|
"Rakefile",
|
24
24
|
"lib/rtesseract.rb",
|
25
|
+
"lib/rtesseract/errors.rb",
|
26
|
+
"lib/rtesseract/mixed.rb",
|
25
27
|
"rtesseract.gemspec",
|
26
28
|
"test/helper.rb",
|
29
|
+
"test/images/mixed.tif",
|
27
30
|
"test/images/test.bmp",
|
28
31
|
"test/images/test.jpg",
|
29
32
|
"test/images/test.png",
|
30
33
|
"test/images/test.tif",
|
31
34
|
"test/images/test1.tif",
|
35
|
+
"test/test_mixed.rb",
|
32
36
|
"test/test_rtesseract.rb"
|
33
37
|
]
|
34
38
|
s.homepage = %q{http://github.com/dannnylo/rtesseract}
|
35
39
|
s.require_paths = ["lib"]
|
36
|
-
s.rubygems_version = %q{1.
|
40
|
+
s.rubygems_version = %q{1.4.2}
|
37
41
|
s.summary = %q{Ruby library for working with the Tesseract OCR.}
|
38
42
|
s.test_files = [
|
39
43
|
"test/helper.rb",
|
44
|
+
"test/test_mixed.rb",
|
40
45
|
"test/test_rtesseract.rb"
|
41
46
|
]
|
42
47
|
|
43
48
|
if s.respond_to? :specification_version then
|
44
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
49
|
s.specification_version = 3
|
46
50
|
|
47
51
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
Binary file
|
data/test/test_mixed.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'pathname'
|
3
|
+
|
4
|
+
class TestMixed < Test::Unit::TestCase
|
5
|
+
context "Path" do
|
6
|
+
setup do
|
7
|
+
@path = Pathname.new(__FILE__.gsub("test_mixed.rb","")).expand_path
|
8
|
+
@image_tiff = @path.join("images","mixed.tif").to_s
|
9
|
+
@image2_tiff = @path.join("images","mixed2.tif").to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
should "be instantiable" do
|
13
|
+
assert_equal RTesseract::Mixed.new.class , RTesseract::Mixed
|
14
|
+
assert_equal RTesseract::Mixed.new(@image_tiff).class , RTesseract::Mixed
|
15
|
+
end
|
16
|
+
|
17
|
+
should "translate parts of the image to text" do
|
18
|
+
mix_block = RTesseract::Mixed.new(@image_tiff) do |image|
|
19
|
+
image.area(28, 19, 25, 25) #position of 4
|
20
|
+
image.area(180, 22, 20, 28) # position of 3
|
21
|
+
image.area(218, 22, 24, 28) # position of z
|
22
|
+
image.area(248, 24, 22, 22) # position of z
|
23
|
+
end
|
24
|
+
assert_equal mix_block.to_s_without_spaces , "43ZZ"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
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:
|
5
|
-
prerelease:
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
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:
|
18
|
+
date: 2011-03-02 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -63,13 +63,17 @@ files:
|
|
63
63
|
- README.rdoc
|
64
64
|
- Rakefile
|
65
65
|
- lib/rtesseract.rb
|
66
|
+
- lib/rtesseract/errors.rb
|
67
|
+
- lib/rtesseract/mixed.rb
|
66
68
|
- rtesseract.gemspec
|
67
69
|
- test/helper.rb
|
70
|
+
- test/images/mixed.tif
|
68
71
|
- test/images/test.bmp
|
69
72
|
- test/images/test.jpg
|
70
73
|
- test/images/test.png
|
71
74
|
- test/images/test.tif
|
72
75
|
- test/images/test1.tif
|
76
|
+
- test/test_mixed.rb
|
73
77
|
- test/test_rtesseract.rb
|
74
78
|
has_rdoc: true
|
75
79
|
homepage: http://github.com/dannnylo/rtesseract
|
@@ -101,10 +105,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
105
|
requirements: []
|
102
106
|
|
103
107
|
rubyforge_project:
|
104
|
-
rubygems_version: 1.
|
108
|
+
rubygems_version: 1.4.2
|
105
109
|
signing_key:
|
106
110
|
specification_version: 3
|
107
111
|
summary: Ruby library for working with the Tesseract OCR.
|
108
112
|
test_files:
|
109
113
|
- test/helper.rb
|
114
|
+
- test/test_mixed.rb
|
110
115
|
- test/test_rtesseract.rb
|