ruby_marks 0.2.9 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
data/lib/ruby_marks/config.rb
CHANGED
@@ -7,7 +7,7 @@ module RubyMarks
|
|
7
7
|
:default_mark_width, :default_mark_height, :scan_timeout,
|
8
8
|
:default_mark_width_tolerance, :default_mark_height_tolerance,
|
9
9
|
:default_distance_between_marks, :default_expected_lines,
|
10
|
-
:default_block_width_tolerance, :default_block_height_tolerance
|
10
|
+
:default_block_width_tolerance, :default_block_height_tolerance, :scan_mode
|
11
11
|
|
12
12
|
|
13
13
|
def initialize(recognizer)
|
@@ -135,8 +135,12 @@ module RubyMarks
|
|
135
135
|
block = find_block_marks(file_str, group_center[:x], group_center[:y], group)
|
136
136
|
if block
|
137
137
|
group.coordinates = {x1: block[:x1], x2: block[:x2], y1: block[:y1], y2: block[:y2]}
|
138
|
-
|
139
|
-
|
138
|
+
|
139
|
+
if @config.scan_mode == :grid
|
140
|
+
marks_blocks = find_marks_grid(group)
|
141
|
+
else
|
142
|
+
marks_blocks = find_marks(original_file_str, group)
|
143
|
+
end
|
140
144
|
marks_blocks.sort!{ |a,b| a[:y1] <=> b[:y1] }
|
141
145
|
mark_ant = nil
|
142
146
|
marks_blocks.each do |mark|
|
@@ -294,6 +298,26 @@ module RubyMarks
|
|
294
298
|
end
|
295
299
|
end
|
296
300
|
|
301
|
+
def find_marks_grid(group)
|
302
|
+
block = group.coordinates
|
303
|
+
blocks = []
|
304
|
+
blocks.tap do |blocks|
|
305
|
+
block_width = RubyMarks::ImageUtils.calc_width(block[:x1], block[:x2])
|
306
|
+
block_height = RubyMarks::ImageUtils.calc_height(block[:y1], block[:y2])
|
307
|
+
lines = @config.default_expected_lines
|
308
|
+
columns = @config.default_marks_options.size
|
309
|
+
distance_lin = block_height / lines
|
310
|
+
distance_col = block_width / columns
|
311
|
+
lines.times do |lin|
|
312
|
+
columns.times do |col|
|
313
|
+
blocks << { :x1 => block[:x1] + (col * distance_col),
|
314
|
+
:y1 => block[:y1] + (lin * distance_lin),
|
315
|
+
:x2 => block[:x1] + (col * distance_col) + distance_col,
|
316
|
+
:y2 => block[:y1] + (lin * distance_lin) + distance_col }
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
297
321
|
|
298
322
|
def find_marks(image, group)
|
299
323
|
block = group.coordinates
|
data/lib/ruby_marks/version.rb
CHANGED
@@ -0,0 +1,97 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class RubyMarks::RecognizerGridTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@file = 'assets/sheet_demo_grid.png'
|
7
|
+
@recognizer = RubyMarks::Recognizer.new
|
8
|
+
@positions = {}
|
9
|
+
@positions[:marked_position] = {x: 161, y: 794}
|
10
|
+
@positions[:unmarked_position] = {x: 161, y: 994}
|
11
|
+
|
12
|
+
@recognizer.configure do |config|
|
13
|
+
|
14
|
+
config.scan_mode = :grid
|
15
|
+
config.default_expected_lines = 5
|
16
|
+
config.intensity_percentual = 25
|
17
|
+
|
18
|
+
config.define_group :um do |group|
|
19
|
+
group.expected_coordinates = {x1: 100, y1: 200, x2: 250, y2: 350}
|
20
|
+
end
|
21
|
+
|
22
|
+
config.define_group :dois do |group|
|
23
|
+
group.expected_coordinates = {x1: 350, y1: 200, x2: 500, y2: 350}
|
24
|
+
end
|
25
|
+
|
26
|
+
config.define_group :tres do |group|
|
27
|
+
group.expected_coordinates = {x1: 570, y1: 200, x2: 720, y2: 350}
|
28
|
+
end
|
29
|
+
|
30
|
+
config.define_group :quatro do |group|
|
31
|
+
group.expected_coordinates = {x1: 790, y1: 200, x2: 940, y2: 350}
|
32
|
+
end
|
33
|
+
|
34
|
+
config.define_group :cinco do |group|
|
35
|
+
group.expected_coordinates = {x1: 1010, y1: 200, x2: 1160, y2: 350}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
@recognizer.file = @file
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_should_return_the_recognizer_with_all_marks_flagged
|
44
|
+
flagged_recognizer = @recognizer.flag_all_marks
|
45
|
+
assert_equal Magick::Image, flagged_recognizer.class
|
46
|
+
|
47
|
+
temp_filename = "sheet_demo_grid2.png"
|
48
|
+
File.delete(temp_filename) if File.exist?(temp_filename)
|
49
|
+
flagged_recognizer.write(temp_filename)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_should_scan_the_recognizer_and_get_a_hash_of_marked_marks
|
53
|
+
expected_hash = {
|
54
|
+
um: {
|
55
|
+
1 => ['B'],
|
56
|
+
2 => ['B'],
|
57
|
+
3 => ['A'],
|
58
|
+
4 => ['B'],
|
59
|
+
5 => ['A']
|
60
|
+
},
|
61
|
+
dois: {
|
62
|
+
1 => ['D'],
|
63
|
+
2 => ['A'],
|
64
|
+
3 => ['C'],
|
65
|
+
4 => ['A'],
|
66
|
+
5 => ['D']
|
67
|
+
},
|
68
|
+
tres: {
|
69
|
+
1 => ['B'],
|
70
|
+
2 => ['A'],
|
71
|
+
3 => ['A'],
|
72
|
+
4 => ['A'],
|
73
|
+
5 => ['B']
|
74
|
+
},
|
75
|
+
quatro: {
|
76
|
+
1 => ['B'],
|
77
|
+
2 => ['C'],
|
78
|
+
3 => ['A'],
|
79
|
+
4 => ['C'],
|
80
|
+
5 => ['E']
|
81
|
+
},
|
82
|
+
cinco: {
|
83
|
+
1 => ['A'],
|
84
|
+
2 => ['B'],
|
85
|
+
3 => ['A'],
|
86
|
+
4 => ['A'],
|
87
|
+
5 => ['C']
|
88
|
+
}
|
89
|
+
}
|
90
|
+
result = @recognizer.scan
|
91
|
+
result.each_pair do |group, lines|
|
92
|
+
lines.delete_if { |line, value| value.empty? }
|
93
|
+
end
|
94
|
+
result.delete_if { |group, lines| lines.empty? }
|
95
|
+
assert_equal expected_hash, result
|
96
|
+
end
|
97
|
+
end
|
@@ -10,6 +10,7 @@ class RubyMarks::RecognizerTest < Test::Unit::TestCase
|
|
10
10
|
@positions[:unmarked_position] = {x: 161, y: 994}
|
11
11
|
|
12
12
|
@recognizer.configure do |config|
|
13
|
+
config.scan_mode = :grid
|
13
14
|
config.define_group :first do |group|
|
14
15
|
group.expected_coordinates = {x1: 145, y1: 780, x2: 270, y2: 1290}
|
15
16
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_marks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -37,19 +37,20 @@ extensions: []
|
|
37
37
|
extra_rdoc_files: []
|
38
38
|
files:
|
39
39
|
- README.md
|
40
|
-
- lib/ruby_marks
|
41
|
-
- lib/ruby_marks/group.rb
|
42
|
-
- lib/ruby_marks/image_utils.rb
|
43
|
-
- lib/ruby_marks/mark.rb
|
44
|
-
- lib/ruby_marks/recognizer.rb
|
45
|
-
- lib/ruby_marks/support.rb
|
40
|
+
- lib/ruby_marks.rb
|
46
41
|
- lib/ruby_marks/version.rb
|
42
|
+
- lib/ruby_marks/support.rb
|
43
|
+
- lib/ruby_marks/mark.rb
|
44
|
+
- lib/ruby_marks/group.rb
|
47
45
|
- lib/ruby_marks/watcher.rb
|
48
|
-
- lib/ruby_marks.rb
|
49
|
-
-
|
46
|
+
- lib/ruby_marks/recognizer.rb
|
47
|
+
- lib/ruby_marks/config.rb
|
48
|
+
- lib/ruby_marks/image_utils.rb
|
49
|
+
- test/test_helper.rb
|
50
50
|
- test/ruby_marks/recognizer_test.rb
|
51
|
+
- test/ruby_marks/recognizer_grid_test.rb
|
51
52
|
- test/ruby_marks/watcher_test.rb
|
52
|
-
- test/
|
53
|
+
- test/ruby_marks/image_utils_test.rb
|
53
54
|
homepage: https://github.com/andrerpbts/ruby_marks.git
|
54
55
|
licenses:
|
55
56
|
- MIT
|
@@ -77,12 +78,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
78
|
version: '0'
|
78
79
|
requirements: []
|
79
80
|
rubyforge_project: ruby_marks
|
80
|
-
rubygems_version: 1.8.
|
81
|
+
rubygems_version: 1.8.25
|
81
82
|
signing_key:
|
82
83
|
specification_version: 3
|
83
84
|
summary: A simple OMR tool
|
84
85
|
test_files:
|
85
|
-
- test/
|
86
|
+
- test/test_helper.rb
|
86
87
|
- test/ruby_marks/recognizer_test.rb
|
88
|
+
- test/ruby_marks/recognizer_grid_test.rb
|
87
89
|
- test/ruby_marks/watcher_test.rb
|
88
|
-
- test/
|
90
|
+
- test/ruby_marks/image_utils_test.rb
|