ocarina 0.0.1
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/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE +204 -0
- data/NOTICE +13 -0
- data/README.md +83 -0
- data/Rakefile +146 -0
- data/data/.gitkeep +0 -0
- data/data/images/letterpress/board1.png +0 -0
- data/data/images/letterpress/board2.png +0 -0
- data/data/images/letterpress/board3.png +0 -0
- data/data/images/letterpress/board4.png +0 -0
- data/data/images/letterpress/board5.png +0 -0
- data/data/images/noise/.gitkeep +0 -0
- data/data/images/noise/0.gif +0 -0
- data/data/images/noise/1.gif +0 -0
- data/data/images/noise/2.gif +0 -0
- data/data/images/noise/3.gif +0 -0
- data/data/images/noise/4.gif +0 -0
- data/data/images/noise/5.gif +0 -0
- data/data/images/noise/6.gif +0 -0
- data/data/images/noise/7.gif +0 -0
- data/data/images/noise/8.gif +0 -0
- data/data/images/noise/9.gif +0 -0
- data/data/images/noise/A.gif +0 -0
- data/data/images/noise/B.gif +0 -0
- data/data/images/noise/C.gif +0 -0
- data/data/images/noise/D.gif +0 -0
- data/data/images/noise/E.gif +0 -0
- data/data/images/noise/F.gif +0 -0
- data/data/images/noise/G.gif +0 -0
- data/data/images/noise/H.gif +0 -0
- data/data/images/noise/I.gif +0 -0
- data/data/images/noise/J.gif +0 -0
- data/data/images/noise/K.gif +0 -0
- data/data/images/noise/L.gif +0 -0
- data/data/images/noise/M.gif +0 -0
- data/data/images/noise/N.gif +0 -0
- data/data/images/noise/O.gif +0 -0
- data/data/images/noise/P.gif +0 -0
- data/data/images/noise/Q.gif +0 -0
- data/data/images/noise/R.gif +0 -0
- data/data/images/noise/S.gif +0 -0
- data/data/images/noise/T.gif +0 -0
- data/data/images/noise/U.gif +0 -0
- data/data/images/noise/V.gif +0 -0
- data/data/images/noise/W.gif +0 -0
- data/data/images/noise/X.gif +0 -0
- data/data/images/noise/Y.gif +0 -0
- data/data/images/noise/Z.gif +0 -0
- data/data/images/noise/a_lower.gif +0 -0
- data/data/images/noise/b_lower.gif +0 -0
- data/data/images/noise/c_lower.gif +0 -0
- data/data/images/noise/d_lower.gif +0 -0
- data/data/images/noise/e_lower.gif +0 -0
- data/data/images/noise/f_lower.gif +0 -0
- data/data/images/noise/g_lower.gif +0 -0
- data/data/images/noise/h_lower.gif +0 -0
- data/data/images/noise/i_lower.gif +0 -0
- data/data/images/noise/j_lower.gif +0 -0
- data/data/images/noise/k_lower.gif +0 -0
- data/data/images/noise/l_lower.gif +0 -0
- data/data/images/noise/m_lower.gif +0 -0
- data/data/images/noise/n_lower.gif +0 -0
- data/data/images/noise/o_lower.gif +0 -0
- data/data/images/noise/p_lower.gif +0 -0
- data/data/images/noise/q_lower.gif +0 -0
- data/data/images/noise/r_lower.gif +0 -0
- data/data/images/noise/s_lower.gif +0 -0
- data/data/images/noise/t_lower.gif +0 -0
- data/data/images/noise/u_lower.gif +0 -0
- data/data/images/noise/v_lower.gif +0 -0
- data/data/images/noise/w_lower.gif +0 -0
- data/data/images/noise/x_lower.gif +0 -0
- data/data/images/noise/y_lower.gif +0 -0
- data/data/images/noise/z_lower.gif +0 -0
- data/data/images/reference/.gitkeep +0 -0
- data/data/images/reference/0.gif +0 -0
- data/data/images/reference/1.gif +0 -0
- data/data/images/reference/2.gif +0 -0
- data/data/images/reference/3.gif +0 -0
- data/data/images/reference/4.gif +0 -0
- data/data/images/reference/5.gif +0 -0
- data/data/images/reference/6.gif +0 -0
- data/data/images/reference/7.gif +0 -0
- data/data/images/reference/8.gif +0 -0
- data/data/images/reference/9.gif +0 -0
- data/data/images/reference/A.gif +0 -0
- data/data/images/reference/B.gif +0 -0
- data/data/images/reference/C.gif +0 -0
- data/data/images/reference/D.gif +0 -0
- data/data/images/reference/E.gif +0 -0
- data/data/images/reference/F.gif +0 -0
- data/data/images/reference/G.gif +0 -0
- data/data/images/reference/H.gif +0 -0
- data/data/images/reference/I.gif +0 -0
- data/data/images/reference/J.gif +0 -0
- data/data/images/reference/K.gif +0 -0
- data/data/images/reference/L.gif +0 -0
- data/data/images/reference/M.gif +0 -0
- data/data/images/reference/N.gif +0 -0
- data/data/images/reference/O.gif +0 -0
- data/data/images/reference/P.gif +0 -0
- data/data/images/reference/Q.gif +0 -0
- data/data/images/reference/R.gif +0 -0
- data/data/images/reference/S.gif +0 -0
- data/data/images/reference/T.gif +0 -0
- data/data/images/reference/U.gif +0 -0
- data/data/images/reference/V.gif +0 -0
- data/data/images/reference/W.gif +0 -0
- data/data/images/reference/X.gif +0 -0
- data/data/images/reference/Y.gif +0 -0
- data/data/images/reference/Z.gif +0 -0
- data/data/images/reference/a_lower.gif +0 -0
- data/data/images/reference/b_lower.gif +0 -0
- data/data/images/reference/c_lower.gif +0 -0
- data/data/images/reference/d_lower.gif +0 -0
- data/data/images/reference/e_lower.gif +0 -0
- data/data/images/reference/f_lower.gif +0 -0
- data/data/images/reference/g_lower.gif +0 -0
- data/data/images/reference/h_lower.gif +0 -0
- data/data/images/reference/i_lower.gif +0 -0
- data/data/images/reference/j_lower.gif +0 -0
- data/data/images/reference/k_lower.gif +0 -0
- data/data/images/reference/l_lower.gif +0 -0
- data/data/images/reference/m_lower.gif +0 -0
- data/data/images/reference/n_lower.gif +0 -0
- data/data/images/reference/o_lower.gif +0 -0
- data/data/images/reference/p_lower.gif +0 -0
- data/data/images/reference/q_lower.gif +0 -0
- data/data/images/reference/r_lower.gif +0 -0
- data/data/images/reference/s_lower.gif +0 -0
- data/data/images/reference/t_lower.gif +0 -0
- data/data/images/reference/u_lower.gif +0 -0
- data/data/images/reference/v_lower.gif +0 -0
- data/data/images/reference/w_lower.gif +0 -0
- data/data/images/reference/x_lower.gif +0 -0
- data/data/images/reference/y_lower.gif +0 -0
- data/data/images/reference/z_lower.gif +0 -0
- data/data/letterpress-train.bin +0 -0
- data/data/train.bin +0 -0
- data/lib/ocarina.rb +12 -0
- data/lib/ocarina/character_generator.rb +87 -0
- data/lib/ocarina/config.rb +35 -0
- data/lib/ocarina/error_stats.rb +62 -0
- data/lib/ocarina/letterpress_character_generator.rb +93 -0
- data/lib/ocarina/letterpress_cropper.rb +84 -0
- data/lib/ocarina/network.rb +264 -0
- data/lib/ocarina/util.rb +92 -0
- data/lib/ocarina/version.rb +3 -0
- data/ocarina.gemspec +20 -0
- data/ocarina.png +0 -0
- data/test/test_letterpress.rb +60 -0
- metadata +231 -0
data/data/.gitkeep
ADDED
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/data/train.bin
ADDED
|
Binary file
|
data/lib/ocarina.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require_relative 'ocarina/version'
|
|
2
|
+
require_relative 'ocarina/config'
|
|
3
|
+
require_relative 'ocarina/network'
|
|
4
|
+
require_relative 'ocarina/util'
|
|
5
|
+
require_relative 'ocarina/error_stats'
|
|
6
|
+
require_relative 'ocarina/character_generator'
|
|
7
|
+
require_relative 'ocarina/letterpress_character_generator'
|
|
8
|
+
require_relative 'ocarina/letterpress_cropper'
|
|
9
|
+
|
|
10
|
+
module Ocarina
|
|
11
|
+
|
|
12
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
require 'RMagick'
|
|
2
|
+
|
|
3
|
+
module Ocarina
|
|
4
|
+
|
|
5
|
+
# creates bitmap images for characters using RMagick's drawing canvas
|
|
6
|
+
#
|
|
7
|
+
class CharacterGenerator
|
|
8
|
+
include Ocarina::Util
|
|
9
|
+
|
|
10
|
+
attr_accessor :reference_image_hash, :noise_image_hash
|
|
11
|
+
|
|
12
|
+
def initialize(config)
|
|
13
|
+
@config = config
|
|
14
|
+
|
|
15
|
+
# generate reference images
|
|
16
|
+
#
|
|
17
|
+
@reference_image_hash = { }
|
|
18
|
+
|
|
19
|
+
@config.char_set.each_char do |char|
|
|
20
|
+
@reference_image_hash[char] = generate_reference_gif_for_char char
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# generate noise images
|
|
24
|
+
#
|
|
25
|
+
@noise_image_hash = { }
|
|
26
|
+
|
|
27
|
+
@config.char_set.each_char do |char|
|
|
28
|
+
@noise_image_hash[char] = generate_noise_gif_for_char char
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# save the reference and noise images to disk
|
|
33
|
+
#
|
|
34
|
+
def persist_tiles
|
|
35
|
+
reference_image_hash.each_pair do |char, image|
|
|
36
|
+
puts "saving to: #{filename_for_training_image(char, 'gif')}"
|
|
37
|
+
|
|
38
|
+
image.write(filename_for_training_image(char, 'gif'))
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
noise_image_hash.each_pair do |char, image|
|
|
42
|
+
image.write(filename_for_noise_image(char, 'gif'))
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# draws the image, but does not save it
|
|
47
|
+
#
|
|
48
|
+
def draw_image_for_char(char)
|
|
49
|
+
canvas = Magick::Image.new(@config.char_width, @config.char_height)
|
|
50
|
+
gc = Magick::Draw.new
|
|
51
|
+
gc.pointsize = 20.0
|
|
52
|
+
#gc.font_family = "Helvetica"
|
|
53
|
+
#gc.font_weight = Magick::BoldWeight
|
|
54
|
+
|
|
55
|
+
gc.stroke('transparent')
|
|
56
|
+
gc.fill('black')
|
|
57
|
+
gc.gravity = Magick::CenterGravity
|
|
58
|
+
gc.annotate(canvas, 0, 0, 0, 0, char)
|
|
59
|
+
|
|
60
|
+
gc.draw(canvas)
|
|
61
|
+
|
|
62
|
+
canvas
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
# generate the gif image for the given character
|
|
67
|
+
#
|
|
68
|
+
def generate_reference_gif_for_char(char)
|
|
69
|
+
draw_image_for_char char
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# generate the gif image for the given character, but with added noise
|
|
73
|
+
#
|
|
74
|
+
def generate_noise_gif_for_char(char)
|
|
75
|
+
image = @reference_image_hash[char]
|
|
76
|
+
|
|
77
|
+
#image = image.wave(10, 100)
|
|
78
|
+
image = image.add_noise(Magick::PoissonNoise)
|
|
79
|
+
#image = image.rotate(5)
|
|
80
|
+
#image = image.resize_to_fit(@config.char_width, @config.char_height)
|
|
81
|
+
|
|
82
|
+
image
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require_relative 'util'
|
|
2
|
+
|
|
3
|
+
module Ocarina
|
|
4
|
+
|
|
5
|
+
# OCR configuration
|
|
6
|
+
#
|
|
7
|
+
class Config
|
|
8
|
+
include Ocarina::Util
|
|
9
|
+
|
|
10
|
+
attr_reader :char_set, :num_outputs, :char_width, :char_height
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# chars_set : the string of characters to be recognized
|
|
14
|
+
# num_outputs : the number of output nodes for the network (# of bits to designate a recognized character)
|
|
15
|
+
# char_width : width in pixels of the input samples
|
|
16
|
+
# char_height : height in pixels of the input samples
|
|
17
|
+
#
|
|
18
|
+
#
|
|
19
|
+
def initialize(char_set, num_outputs, char_width, char_height)
|
|
20
|
+
@char_set = char_set
|
|
21
|
+
@num_outputs = num_outputs
|
|
22
|
+
@char_width = char_width
|
|
23
|
+
@char_height = char_height
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# the number of inputs for the network
|
|
27
|
+
#
|
|
28
|
+
def num_inputs
|
|
29
|
+
@char_width * @char_height
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|