mork 0.3.0 → 0.4.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 +2 -2
- data/lib/mork/mimage.rb +36 -8
- data/lib/mork/npatch.rb +2 -0
- data/lib/mork/sheet_omr.rb +7 -4
- data/lib/mork/sheet_pdf.rb +0 -23
- data/lib/mork/version.rb +1 -1
- data/spec/mork/sheet_omr_spec.rb +24 -0
- data/spec/samples/info.yml +8 -23
- metadata +2 -4
- data/spec/samples/sample01.jpg +0 -0
- data/spec/samples/sample03.jpg +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ce19962ba0e1e21013a7081f9ac040e57d0bfa1
|
4
|
+
data.tar.gz: 2b86b3f7a6338384e6b9ffdf9157cb0a92205dea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d6a2ef2db4358a02a2ba9d3cbdac0505d9208b2b169fbfee67e76a71311844b970a306d19c8a72fbd400288ef269397c645d65f126b284c4832c6283870ba79
|
7
|
+
data.tar.gz: 3efa05963a68fd82f672f4c0aadf06d739e3eec442a7e0f0c70c82f0422c35f699df3495ab5196d264ab4497ccc85cd579eefbaac3819ccfa5d427e47c61bf83
|
data/lib/mork/grid_omr.rb
CHANGED
@@ -83,7 +83,7 @@ module Mork
|
|
83
83
|
def ppu_x() @px / page_width end
|
84
84
|
def ppu_y() @py / page_height end
|
85
85
|
|
86
|
-
# finding the
|
86
|
+
# finding the x position of the registration area based on iteration
|
87
87
|
def rmx(corner, i)
|
88
88
|
case corner
|
89
89
|
when :tl; reg_off
|
@@ -93,7 +93,7 @@ module Mork
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
# finding the
|
96
|
+
# finding the y position of the registration area based on iteration
|
97
97
|
def rmy(corner, i)
|
98
98
|
case corner
|
99
99
|
when :tl; reg_off
|
data/lib/mork/mimage.rb
CHANGED
@@ -11,12 +11,23 @@ module Mork
|
|
11
11
|
@grom.set_page_size width, height
|
12
12
|
@rm = {} # registration mark centers
|
13
13
|
@rmsa = {} # registration mark search area
|
14
|
-
@
|
14
|
+
@valid = register
|
15
|
+
@writing = nil
|
15
16
|
@cmd = []
|
16
17
|
end
|
17
18
|
|
19
|
+
def valid?
|
20
|
+
@valid
|
21
|
+
end
|
22
|
+
|
18
23
|
def status
|
19
|
-
|
24
|
+
{
|
25
|
+
tl: @rm[:tl][:status],
|
26
|
+
tr: @rm[:tr][:status],
|
27
|
+
br: @rm[:br][:status],
|
28
|
+
bl: @rm[:bl][:status],
|
29
|
+
write: @writing
|
30
|
+
}
|
20
31
|
end
|
21
32
|
|
22
33
|
def ink_black
|
@@ -84,7 +95,7 @@ module Mork
|
|
84
95
|
|
85
96
|
def highlight_reg_area
|
86
97
|
highlight_rect [@rmsa[:tl], @rmsa[:tr], @rmsa[:br], @rmsa[:bl]]
|
87
|
-
return unless
|
98
|
+
return unless valid?
|
88
99
|
join [@rm[:tl], @rm[:tr], @rm[:br], @rm[:bl]]
|
89
100
|
end
|
90
101
|
|
@@ -131,9 +142,20 @@ module Mork
|
|
131
142
|
# if the 2nd arg is false, then stretching is not applied
|
132
143
|
def write(fname=nil, reg=true)
|
133
144
|
if fname
|
134
|
-
img = MiniMagick::Image.open @path
|
135
|
-
img.combine_options {|c| exec_mm_cmd c, reg }
|
136
|
-
|
145
|
+
# img = MiniMagick::Image.open @path
|
146
|
+
# img.combine_options {|c| exec_mm_cmd c, reg }
|
147
|
+
# begin
|
148
|
+
# img.write fname
|
149
|
+
# @write = :ok
|
150
|
+
# rescue Exception
|
151
|
+
# @write = :fail
|
152
|
+
# end
|
153
|
+
MiniMagick::Tool::Convert.new(false) do |img|
|
154
|
+
img << @path
|
155
|
+
img.distort(:perspective, perspective_points) if reg
|
156
|
+
@cmd.each { |cmd| img.send *cmd }
|
157
|
+
img << fname
|
158
|
+
end
|
137
159
|
else
|
138
160
|
MiniMagick::Image.new(@path) { |c| exec_mm_cmd c, reg }
|
139
161
|
end
|
@@ -144,6 +166,7 @@ module Mork
|
|
144
166
|
# ============================================================#
|
145
167
|
def exec_mm_cmd(c, reg)
|
146
168
|
c.distort(:perspective, perspective_points) if reg
|
169
|
+
|
147
170
|
@cmd.each do |cmd|
|
148
171
|
c.send *cmd
|
149
172
|
end
|
@@ -197,11 +220,14 @@ module Mork
|
|
197
220
|
def register
|
198
221
|
# find the XY coordinates of the 4 registration marks
|
199
222
|
@rm[:tl] = reg_centroid_on(:tl)
|
223
|
+
# puts "TL: #{@rm[:tl][:status].inspect}"
|
200
224
|
@rm[:tr] = reg_centroid_on(:tr)
|
225
|
+
# puts "TR: #{@rm[:tr][:status].inspect}"
|
201
226
|
@rm[:br] = reg_centroid_on(:br)
|
227
|
+
# puts "BR: #{@rm[:br][:status].inspect}"
|
202
228
|
@rm[:bl] = reg_centroid_on(:bl)
|
203
|
-
#
|
204
|
-
@rm.all? { |k,v| v[:status] == :ok }
|
229
|
+
# puts "BL: #{@rm[:bl][:status].inspect}"
|
230
|
+
@rm.all? { |k,v| v[:status] == :ok }
|
205
231
|
end
|
206
232
|
|
207
233
|
# returns the centroid of the dark region within the given area
|
@@ -209,6 +235,8 @@ module Mork
|
|
209
235
|
def reg_centroid_on(corner)
|
210
236
|
1000.times do |i|
|
211
237
|
@rmsa[corner] = @grom.rm_search_area(corner, i)
|
238
|
+
# puts "================================================================"
|
239
|
+
# puts "Corner #{corner} - Iteration #{i} - Coo #{@rmsa[corner].inspect}"
|
212
240
|
cx, cy = raw_pixels.dark_centroid @rmsa[corner]
|
213
241
|
if cx.nil?
|
214
242
|
status = :no_contrast
|
data/lib/mork/npatch.rb
CHANGED
@@ -34,6 +34,7 @@ module Mork
|
|
34
34
|
# find the intensity trough
|
35
35
|
ctr_x = xp.find_index(xp.min)
|
36
36
|
ctr_y = yp.find_index(yp.min)
|
37
|
+
# puts "Centroid: #{ctr_x}, #{ctr_y} - MinX #{xp.min/xp.length}, MaxX #{xp.max/xp.length}, MinY #{yp.min/yp.length}, MaxY #{yp.max/yp.length}"
|
37
38
|
return ctr_x, ctr_y
|
38
39
|
end
|
39
40
|
|
@@ -49,6 +50,7 @@ module Mork
|
|
49
50
|
end
|
50
51
|
|
51
52
|
def sufficient_contrast?(p)
|
53
|
+
# puts "Contrast: #{p.stddev}"
|
52
54
|
# tested with the few examples: spec/samples/rm0x.jpeg
|
53
55
|
p.stddev > 20
|
54
56
|
end
|
data/lib/mork/sheet_omr.rb
CHANGED
@@ -7,11 +7,14 @@ module Mork
|
|
7
7
|
def initialize(path, grom=nil)
|
8
8
|
@grom = GridOMR.new grom
|
9
9
|
@mim = Mimage.new path, @grom
|
10
|
-
@ok_reg = @mim.status
|
11
10
|
end
|
12
11
|
|
13
12
|
def valid?
|
14
|
-
@
|
13
|
+
@mim.valid?
|
14
|
+
end
|
15
|
+
|
16
|
+
def status
|
17
|
+
@mim.status
|
15
18
|
end
|
16
19
|
|
17
20
|
# barcode
|
@@ -161,8 +164,8 @@ module Mork
|
|
161
164
|
end
|
162
165
|
|
163
166
|
def not_registered
|
164
|
-
unless
|
165
|
-
puts "---=={ Unregistered image. Reason: '#{@
|
167
|
+
unless valid?
|
168
|
+
puts "---=={ Unregistered image. Reason: '#{@mim.status.inspect}' }==---"
|
166
169
|
true
|
167
170
|
end
|
168
171
|
end
|
data/lib/mork/sheet_pdf.rb
CHANGED
@@ -120,26 +120,3 @@ module Mork
|
|
120
120
|
end
|
121
121
|
end
|
122
122
|
end
|
123
|
-
|
124
|
-
# def control(content)
|
125
|
-
# font_size @grip.control_size do
|
126
|
-
# text_box content[:string], at: @grip.control_xy,
|
127
|
-
# width: @grip.control_width,
|
128
|
-
# align: :right
|
129
|
-
# stroke do
|
130
|
-
# stroke_color "ff0000"
|
131
|
-
# # dark
|
132
|
-
# a = @grip.ctrl_area_dark
|
133
|
-
# rounded_rectangle a[:p], a[:w], a[:h], [a[:h], a[:w]].min / 2
|
134
|
-
# fill_color "ff0000"
|
135
|
-
# draw_text content[:labels][0], at: @grip.dark_control_letter_xy
|
136
|
-
# # light
|
137
|
-
# a = @grip.ctrl_area_light
|
138
|
-
# rounded_rectangle a[:p], a[:w], a[:h], [a[:h], a[:w]].min / 2
|
139
|
-
# fill_color "ff0000"
|
140
|
-
# draw_text content[:labels][1], at: @grip.light_control_letter_xy
|
141
|
-
#
|
142
|
-
# end
|
143
|
-
# end
|
144
|
-
# end
|
145
|
-
#
|
data/lib/mork/version.rb
CHANGED
data/spec/mork/sheet_omr_spec.rb
CHANGED
@@ -3,6 +3,30 @@ require 'fileutils'
|
|
3
3
|
|
4
4
|
module Mork
|
5
5
|
describe SheetOMR do
|
6
|
+
# context 'problematic' do
|
7
|
+
# let(:shinfo) { sample_img 'bianchi' }
|
8
|
+
# let(:sheet) { SheetOMR.new shinfo.filename, shinfo.grid_file }
|
9
|
+
#
|
10
|
+
# it 'has a status' do
|
11
|
+
# sheet.status.should == {:tl=>:ok, :tr=>:ok, :br=>:ok, :bl=>:ok, :write=>nil}
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# it 'has a barcode' do
|
15
|
+
# sheet.barcode.should == shinfo.barcode_int
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# it 'writes the registered and marked image' do
|
19
|
+
# sheet.cross_marked
|
20
|
+
# sheet.write 'spec/out/bianchi.jpg'
|
21
|
+
# sheet.status[:write].should == :fail
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# it 'writes the registration areas' do
|
25
|
+
# sheet.highlight_registration
|
26
|
+
# sheet.write_raw 'spec/out/reg_bianchi.jpg'
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# end
|
6
30
|
|
7
31
|
context 'highlighting' do
|
8
32
|
# since these specs change the @crop, they must be run in isolation
|
data/spec/samples/info.yml
CHANGED
@@ -12,30 +12,15 @@ sample-gray:
|
|
12
12
|
grid-file: spec/samples/layout.yml
|
13
13
|
width: 1654
|
14
14
|
height: 2339
|
15
|
-
|
16
15
|
|
17
|
-
|
18
|
-
filename: spec/samples/
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
tl-y: 90
|
26
|
-
tr-x: 2245
|
27
|
-
tr-y: 97
|
28
|
-
br-x: 2230
|
29
|
-
br-y: 3217
|
30
|
-
bl-x: 78
|
31
|
-
bl-y: 3205
|
32
|
-
q-boxes:
|
33
|
-
q001:
|
34
|
-
tl-x: 175
|
35
|
-
tl-y: 379
|
36
|
-
q160:
|
37
|
-
tl-x: 1818
|
38
|
-
tl-y: 2974
|
16
|
+
bianchi:
|
17
|
+
# filename: spec/samples/IMG_20150104_0005.jpg
|
18
|
+
# filename: spec/samples/out0000.jpg
|
19
|
+
# filename: spec/samples/SCN_0001.jpg
|
20
|
+
# filename: spec/samples/IMG_20150104_0011.jpg
|
21
|
+
# filename: spec/samples/IMG_20150104_0009.jpg
|
22
|
+
grid-file: spec/samples/bianchi.yml
|
23
|
+
barcode-int: 9350
|
39
24
|
|
40
25
|
reg-mark:
|
41
26
|
filename: spec/samples/reg_mark.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.4.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:
|
11
|
+
date: 2015-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: narray
|
@@ -185,9 +185,7 @@ files:
|
|
185
185
|
- spec/samples/rm03.jpeg
|
186
186
|
- spec/samples/rm04.jpeg
|
187
187
|
- spec/samples/rm05.jpeg
|
188
|
-
- spec/samples/sample01.jpg
|
189
188
|
- spec/samples/sample02.jpg
|
190
|
-
- spec/samples/sample03.jpg
|
191
189
|
- spec/samples/sample_gray.jpg
|
192
190
|
- spec/samples/sheet.jpg
|
193
191
|
- spec/samples/sheet666.jpg
|
data/spec/samples/sample01.jpg
DELETED
Binary file
|
data/spec/samples/sample03.jpg
DELETED
Binary file
|