mork 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mork/grid_omr.rb +5 -0
- data/lib/mork/mimage.rb +46 -27
- data/lib/mork/sheet_omr.rb +25 -2
- data/lib/mork/version.rb +1 -1
- data/mork.gemspec +1 -1
- data/spec/mork/sheet_omr_spec.rb +19 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f86f0bbe05ae9f4eb62d0d61598a76fcd595e08
|
4
|
+
data.tar.gz: 547f41d90cc045f797ca98254638723c650fd2f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdfe684595e84ccc61c03f07e30c0a171fa438be0b9a7e46d0cf563e77f17b15772f0b80f8d7e7a69eb3079fab46d971eef3337f6e97661785a515efc864dc45
|
7
|
+
data.tar.gz: 37b009ebc52a62517ee8c03a55e3163747f49632f721fa585d8561bb4a304eefda61dc208430b5b99e298d40905111cc580305f57051abc11ecc19608beee4af
|
data/lib/mork/grid_omr.rb
CHANGED
data/lib/mork/mimage.rb
CHANGED
@@ -9,6 +9,8 @@ module Mork
|
|
9
9
|
@path = path
|
10
10
|
@grom = grom
|
11
11
|
@grom.set_page_size width, height
|
12
|
+
@rm = {} # registration mark centers
|
13
|
+
@rmsa = {} # registration mark search area
|
12
14
|
@status = register
|
13
15
|
@cmd = []
|
14
16
|
end
|
@@ -54,7 +56,7 @@ module Mork
|
|
54
56
|
@cmd << [:stroke, 'green']
|
55
57
|
@cmd << [:strokewidth, '4']
|
56
58
|
@cmd << [:fill, 'none']
|
57
|
-
|
59
|
+
coordinates_of(cells).each do |c|
|
58
60
|
roundedness ||= [c[:h], c[:w]].min / 2
|
59
61
|
pts = [c[:x], c[:y], c[:x]+c[:w], c[:y]+c[:h], roundedness, roundedness].join ' '
|
60
62
|
@cmd << [:draw, "roundrectangle #{pts}"]
|
@@ -73,7 +75,7 @@ module Mork
|
|
73
75
|
return if cells.empty?
|
74
76
|
@cmd << [:stroke, 'none']
|
75
77
|
@cmd << [:fill, 'rgba(255, 255, 0, 0.3)']
|
76
|
-
|
78
|
+
coordinates_of(cells).each do |c|
|
77
79
|
roundedness ||= [c[:h], c[:w]].min / 2
|
78
80
|
pts = [c[:x], c[:y], c[:x]+c[:w], c[:y]+c[:h], roundedness, roundedness].join ' '
|
79
81
|
@cmd << [:draw, "roundrectangle #{pts}"]
|
@@ -101,32 +103,51 @@ module Mork
|
|
101
103
|
end
|
102
104
|
end
|
103
105
|
|
104
|
-
def
|
106
|
+
def cross(cells)
|
107
|
+
return if cells.empty?
|
105
108
|
cells = [cells] if cells.is_a? Hash
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
109
|
+
@cmd << [:stroke, 'red']
|
110
|
+
@cmd << [:strokewidth, '3']
|
111
|
+
coordinates_of(cells).each do |c|
|
112
|
+
pts = [
|
113
|
+
c[:x]+corner,
|
114
|
+
c[:y]+corner,
|
115
|
+
c[:x]+c[:w]-corner,
|
116
|
+
c[:y]+c[:h]-corner
|
117
|
+
].join ' '
|
118
|
+
@cmd << [:draw, "line #{pts}"]
|
119
|
+
pts = [
|
120
|
+
c[:x]+corner,
|
121
|
+
c[:y]+c[:h]-corner,
|
122
|
+
c[:x]+c[:w]-corner,
|
123
|
+
c[:y]+corner
|
124
|
+
].join ' '
|
125
|
+
@cmd << [:draw, "line #{pts}"]
|
111
126
|
end
|
112
127
|
end
|
113
128
|
|
114
129
|
# write the underlying MiniMagick::Image to disk;
|
130
|
+
# if no file name is given, image is processed in-place;
|
115
131
|
# if the 2nd arg is false, then stretching is not applied
|
116
|
-
def write(fname, reg=true)
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
132
|
+
def write(fname=nil, reg=true)
|
133
|
+
if fname
|
134
|
+
img = MiniMagick::Image.open @path
|
135
|
+
img.combine_options {|c| exec_mm_cmd c, reg }
|
136
|
+
img.write fname
|
137
|
+
else
|
138
|
+
MiniMagick::Image.new(@path) { |c| exec_mm_cmd c, reg }
|
123
139
|
end
|
124
|
-
img.write fname
|
125
140
|
end
|
126
141
|
|
127
142
|
# ============================================================#
|
128
143
|
private #
|
129
144
|
# ============================================================#
|
145
|
+
def exec_mm_cmd(c, reg)
|
146
|
+
c.distort(:perspective, perspective_points) if reg
|
147
|
+
@cmd.each do |cmd|
|
148
|
+
c.send *cmd
|
149
|
+
end
|
150
|
+
end
|
130
151
|
|
131
152
|
def img_size
|
132
153
|
@img_size ||= IO.read("|identify -format '%w,%h' #{@path}").split ','
|
@@ -163,20 +184,18 @@ module Mork
|
|
163
184
|
@cmd << [:draw, "polygon #{pts}"]
|
164
185
|
end
|
165
186
|
|
166
|
-
def
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
187
|
+
def coordinates_of(cells)
|
188
|
+
cells.collect.each_with_index do |q, i|
|
189
|
+
q.collect { |c| @grom.choice_cell_area(i, c) }
|
190
|
+
end.flatten
|
191
|
+
end
|
192
|
+
|
193
|
+
def corner
|
194
|
+
@corner_size ||= @grom.cell_corner_size
|
174
195
|
end
|
175
196
|
|
176
197
|
def register
|
177
198
|
# find the XY coordinates of the 4 registration marks
|
178
|
-
@rm = {} # registration mark centers
|
179
|
-
@rmsa = {} # registration mark search area
|
180
199
|
@rm[:tl] = reg_centroid_on(:tl)
|
181
200
|
@rm[:tr] = reg_centroid_on(:tr)
|
182
201
|
@rm[:br] = reg_centroid_on(:br)
|
@@ -192,7 +211,7 @@ module Mork
|
|
192
211
|
@rmsa[corner] = @grom.rm_search_area(corner, i)
|
193
212
|
cx, cy = raw_pixels.dark_centroid @rmsa[corner]
|
194
213
|
if cx.nil?
|
195
|
-
status = :
|
214
|
+
status = :no_contrast
|
196
215
|
elsif (cx < @grom.rm_edgy_x) or
|
197
216
|
(cy < @grom.rm_edgy_y) or
|
198
217
|
(cy > @rmsa[corner][:h] - @grom.rm_edgy_y) or
|
data/lib/mork/sheet_omr.rb
CHANGED
@@ -77,6 +77,17 @@ module Mork
|
|
77
77
|
@mim.outline cells
|
78
78
|
end
|
79
79
|
|
80
|
+
def cross(cells)
|
81
|
+
return if not_registered
|
82
|
+
raise "Invalid ‘cells’ argument" unless cells.kind_of? Array
|
83
|
+
@mim.cross cells
|
84
|
+
end
|
85
|
+
|
86
|
+
def cross_marked
|
87
|
+
return if not_registered
|
88
|
+
@mim.cross mark_array
|
89
|
+
end
|
90
|
+
|
80
91
|
def highlight_marked
|
81
92
|
return if not_registered
|
82
93
|
@mim.highlight_cells mark_array
|
@@ -96,12 +107,24 @@ module Mork
|
|
96
107
|
@mim.highlight_reg_area
|
97
108
|
end
|
98
109
|
|
99
|
-
|
110
|
+
# write(output_path_file_name)
|
111
|
+
#
|
112
|
+
# writes out a copy of the source image after registration;
|
113
|
+
# the output image will also contain any previously applied overlays;
|
114
|
+
# if the argument is omitted, the image is created in-place,
|
115
|
+
# i.e. the original source image is overwritten.
|
116
|
+
def write(fname=nil)
|
100
117
|
return if not_registered
|
101
118
|
@mim.write(fname)
|
102
119
|
end
|
103
120
|
|
104
|
-
|
121
|
+
# write_raw(output_path_file_name)
|
122
|
+
#
|
123
|
+
# writes out a copy of the source image before registration;
|
124
|
+
# the output image will also contain any previously applied overlays
|
125
|
+
# if the argument is omitted, the image is created in-place,
|
126
|
+
# i.e. the original source image is overwritten.
|
127
|
+
def write_raw(fname=nil)
|
105
128
|
@mim.write(fname, false)
|
106
129
|
end
|
107
130
|
|
data/lib/mork/version.rb
CHANGED
data/mork.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
|
20
20
|
# dependencies:
|
21
21
|
s.add_dependency 'narray', '~> 0.6'
|
22
|
-
s.add_dependency 'mini_magick', '~>
|
22
|
+
s.add_dependency 'mini_magick', '~> 4.0'
|
23
23
|
s.add_dependency 'prawn', '~> 1.3'
|
24
24
|
s.add_development_dependency 'rake', '~> 10.3'
|
25
25
|
s.add_development_dependency 'rspec', '~> 3.1'
|
data/spec/mork/sheet_omr_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
2
3
|
|
3
4
|
module Mork
|
4
5
|
describe SheetOMR do
|
@@ -24,12 +25,29 @@ module Mork
|
|
24
25
|
sheet.write 'spec/out/marked_highlights.jpg'
|
25
26
|
end
|
26
27
|
|
28
|
+
it 'crossed marked cells' do
|
29
|
+
sheet.cross_marked
|
30
|
+
sheet.write 'spec/out/marked_crosses.jpg'
|
31
|
+
end
|
32
|
+
|
27
33
|
it 'outlines some responses' do
|
28
34
|
sheet.outline [[1],[1],[2],[2],[3,4],[],[0,1,2,3,4], [],[1],[2],[2],[3,4],[],[0,1,2,3,4]]
|
29
35
|
sheet.write 'spec/out/outlines.jpg'
|
30
36
|
end
|
31
37
|
|
32
|
-
it '
|
38
|
+
it 'cross some responses' do
|
39
|
+
sheet.cross [[1],[1],[2],[2],[3,4],[],[0,1,2,3,4], [],[1],[2],[2],[3,4],[],[0,1,2,3,4]]
|
40
|
+
sheet.write 'spec/out/crosses.jpg'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'outlines some responses in-place (rewriting the source image)' do
|
44
|
+
FileUtils.cp shinfo.filename, 'spec/out/inplace.jpg'
|
45
|
+
tsheet = SheetOMR.new 'spec/out/inplace.jpg', shinfo.grid_file
|
46
|
+
tsheet.outline [[1],[1],[2],[2],[3,4],[],[0,1,2,3,4], [],[1],[2],[2],[3,4],[],[0,1,2,3,4]]
|
47
|
+
tsheet.write
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'highlights marked cells and outline correct responses' do
|
33
51
|
sheet.highlight_marked
|
34
52
|
sheet.outline [[1],[1],[2],[2],[3,4],[],[0,1,2,3,4], [],[1],[2],[2],[3,4],[],[0,1,2,3,4]]
|
35
53
|
sheet.write 'spec/out/marks_and_outs.jpg'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Giuseppe Bertini
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: narray
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '4.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '4.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: prawn
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|