mork 0.6.0 → 0.7.0
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.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/mork/coord.rb +58 -0
- data/lib/mork/grid.rb +44 -35
- data/lib/mork/grid_const.rb +11 -6
- data/lib/mork/grid_omr.rb +76 -62
- data/lib/mork/magicko.rb +162 -0
- data/lib/mork/mimage.rb +102 -177
- data/lib/mork/npatch.rb +38 -56
- data/lib/mork/sheet_omr.rb +45 -43
- data/lib/mork/sheet_pdf.rb +16 -16
- data/lib/mork/version.rb +1 -1
- data/mork.gemspec +2 -2
- data/mork.sublime-project +9 -0
- data/spec/mork/coord_spec.rb +55 -0
- data/spec/mork/grid_omr_spec.rb +62 -85
- data/spec/mork/grid_spec.rb +7 -7
- data/spec/mork/magicko_spec.rb +46 -0
- data/spec/mork/mimage_spec.rb +30 -20
- data/spec/mork/npatch_spec.rb +46 -39
- data/spec/mork/sheet_omr_spec.rb +82 -40
- data/spec/mork/sheet_pdf_spec.rb +8 -8
- data/spec/samples/angolo.jpg +0 -0
- data/spec/samples/grid.yml +53 -0
- data/spec/samples/info.yml +12 -11
- data/spec/samples/layout.yml +9 -5
- data/spec/samples/lucrezia/border1.pdf +0 -0
- data/spec/samples/lucrezia/border2.pdf +0 -0
- data/spec/samples/lucrezia/bw1.pdf +0 -0
- data/spec/samples/lucrezia/bw2.pdf +0 -0
- data/spec/samples/lucrezia/gray1.pdf +0 -0
- data/spec/samples/lucrezia/gray2.pdf +0 -0
- data/spec/samples/out-1.jpg +0 -0
- data/spec/samples/rm00.jpeg +0 -0
- data/spec/samples/slanted.jpg +0 -0
- data/spec/samples/slanted.yml +54 -0
- data/spec/samples/syst/IMG_20150104_0004.jpg +0 -0
- data/spec/samples/syst/IMG_20150104_0004.txt +4955 -0
- data/spec/samples/syst/IMG_20150104_0009.jpg +0 -0
- data/spec/samples/syst/IMG_20150104_0009.txt +4955 -0
- data/spec/samples/syst/IMG_20150104_0011.jpg +0 -0
- data/spec/samples/syst/IMG_20150104_0011.txt +4955 -0
- data/spec/samples/syst/SCN_0001.jpg +0 -0
- data/spec/samples/syst/SCN_0001.txt +4955 -0
- data/spec/samples/syst/barr0.jpg +0 -0
- data/spec/samples/syst/barr0.txt +4955 -0
- data/spec/samples/syst/barr1.jpg +0 -0
- data/spec/samples/syst/barr1.txt +4955 -0
- data/spec/samples/syst/barr2.jpg +0 -0
- data/spec/samples/syst/barr2.txt +4955 -0
- data/spec/samples/syst/bell0.jpg +0 -0
- data/spec/samples/syst/bell0.txt +4955 -0
- data/spec/samples/syst/bell1.jpg +0 -0
- data/spec/samples/syst/bell1.txt +4955 -0
- data/spec/samples/syst/bell2.jpg +0 -0
- data/spec/samples/syst/bell2.txt +4955 -0
- data/spec/samples/syst/bila0.jpg +0 -0
- data/spec/samples/syst/bila0.txt +4955 -0
- data/spec/samples/syst/bila1.jpg +0 -0
- data/spec/samples/syst/bila1.txt +4955 -0
- data/spec/samples/syst/bila2.jpg +0 -0
- data/spec/samples/syst/bila2.txt +4955 -0
- data/spec/samples/syst/bila3.jpg +0 -0
- data/spec/samples/syst/bila3.txt +4955 -0
- data/spec/samples/syst/bila4.jpg +0 -0
- data/spec/samples/syst/bila4.txt +4955 -0
- data/spec/samples/syst/bone0.jpg +0 -0
- data/spec/samples/syst/bone0.txt +4955 -0
- data/spec/samples/syst/bone1.jpg +0 -0
- data/spec/samples/syst/bone1.txt +4955 -0
- data/spec/samples/syst/bone2.jpg +0 -0
- data/spec/samples/syst/bone2.txt +4955 -0
- data/spec/samples/syst/cost0.jpg +0 -0
- data/spec/samples/syst/cost0.txt +4955 -0
- data/spec/samples/syst/cost1.jpg +0 -0
- data/spec/samples/syst/cost1.txt +4955 -0
- data/spec/samples/syst/cost2.jpg +0 -0
- data/spec/samples/syst/cost2.txt +4955 -0
- data/spec/samples/syst/cost3.jpg +0 -0
- data/spec/samples/syst/cost3.txt +4955 -0
- data/spec/samples/syst/cost4.jpg +0 -0
- data/spec/samples/syst/cost4.txt +4955 -0
- data/spec/samples/syst/dald0.jpg +0 -0
- data/spec/samples/syst/dald0.txt +4955 -0
- data/spec/samples/syst/dald1.jpg +0 -0
- data/spec/samples/syst/dald1.txt +4955 -0
- data/spec/samples/syst/dald2.jpg +0 -0
- data/spec/samples/syst/dald2.txt +4955 -0
- data/spec/samples/syst/dald3.jpg +0 -0
- data/spec/samples/syst/dald3.txt +4955 -0
- data/spec/samples/syst/dald4.jpg +0 -0
- data/spec/samples/syst/dald4.txt +4955 -0
- data/spec/samples/syst/dign0.jpg +0 -0
- data/spec/samples/syst/dign0.txt +4955 -0
- data/spec/samples/syst/dign1.jpg +0 -0
- data/spec/samples/syst/dign1.txt +4955 -0
- data/spec/samples/syst/dign2.jpg +0 -0
- data/spec/samples/syst/dign2.txt +4955 -0
- data/spec/samples/syst/dive0.jpg +0 -0
- data/spec/samples/syst/dive0.txt +4955 -0
- data/spec/samples/syst/dive1.jpg +0 -0
- data/spec/samples/syst/dive1.txt +4955 -0
- data/spec/samples/syst/dive2.jpg +0 -0
- data/spec/samples/syst/dive2.txt +4955 -0
- data/spec/samples/syst/histo.m +42 -0
- data/spec/samples/syst/out0000.jpg +0 -0
- data/spec/samples/syst/out0000.txt +4955 -0
- data/spec/samples/syst/out0001.jpg +0 -0
- data/spec/samples/syst/out0001.txt +4955 -0
- data/spec/samples/syst/out0002.jpg +0 -0
- data/spec/samples/syst/out0002.txt +4955 -0
- data/spec/samples/syst/qzc013.jpg +0 -0
- data/spec/samples/syst/qzc013.txt +4955 -0
- data/spec/samples/syst/sample_gray.jpg +0 -0
- data/spec/samples/syst/sample_gray.txt +4955 -0
- data/spec/samples/syst_grid.yml +53 -0
- data/spec/spec_helper.rb +18 -10
- data/test_reg.m +39 -0
- metadata +105 -8
- data/spec/samples/io.jpg +0 -0
data/lib/mork/sheet_pdf.rb
CHANGED
|
@@ -2,15 +2,15 @@ require 'mork/grid_pdf'
|
|
|
2
2
|
require 'prawn'
|
|
3
3
|
|
|
4
4
|
module Mork
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
#TODO: read the prawn manual, we should probably use views
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
class SheetPDF < Prawn::Document
|
|
9
9
|
def initialize(content, grip=GridPDF.new)
|
|
10
10
|
@grip = case grip
|
|
11
11
|
when String, Hash; GridPDF.new grip
|
|
12
12
|
when Mork::GridPDF; grip
|
|
13
|
-
else raise 'Invalid initialization parameter'
|
|
13
|
+
else raise ArgumentError, 'Invalid initialization parameter'
|
|
14
14
|
end
|
|
15
15
|
super my_page_params
|
|
16
16
|
# @content should be an array of hashes, one per page;
|
|
@@ -18,11 +18,11 @@ module Mork
|
|
|
18
18
|
@content = content.class == Hash ? [content] : content
|
|
19
19
|
process
|
|
20
20
|
end
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
def save(fn)
|
|
23
23
|
render_file fn
|
|
24
24
|
end
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
def to_pdf
|
|
27
27
|
render
|
|
28
28
|
end
|
|
@@ -35,7 +35,7 @@ module Mork
|
|
|
35
35
|
margin: @grip.margins
|
|
36
36
|
}
|
|
37
37
|
end
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
def process
|
|
40
40
|
# for all sheets
|
|
41
41
|
line_width 0.3
|
|
@@ -52,14 +52,14 @@ module Mork
|
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
|
-
|
|
55
|
+
|
|
56
56
|
def make_repeaters
|
|
57
57
|
if equal_choice_number?
|
|
58
58
|
repeat(:all) do
|
|
59
59
|
questions_and_choices ch_len.first
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
|
-
|
|
62
|
+
|
|
63
63
|
repeat(:all) do
|
|
64
64
|
calibration_cells
|
|
65
65
|
fill do
|
|
@@ -69,11 +69,11 @@ module Mork
|
|
|
69
69
|
end
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
|
-
|
|
72
|
+
|
|
73
73
|
def calibration_cells
|
|
74
74
|
@grip.calibration_cells_xy.each { |c| stamp_at 'X', c }
|
|
75
75
|
end
|
|
76
|
-
|
|
76
|
+
|
|
77
77
|
def barcode(code)
|
|
78
78
|
# draw the dark calibration bar
|
|
79
79
|
stamp_at 'barcode', @grip.ink_black_xy
|
|
@@ -81,7 +81,7 @@ module Mork
|
|
|
81
81
|
# least to most significant bit, left to right
|
|
82
82
|
@grip.barcode_xy_for(code).each { |c| stamp_at 'barcode', c }
|
|
83
83
|
end
|
|
84
|
-
|
|
84
|
+
|
|
85
85
|
def header(content)
|
|
86
86
|
content.each do |k,v|
|
|
87
87
|
font_size @grip.header_size(k) do
|
|
@@ -110,7 +110,7 @@ module Mork
|
|
|
110
110
|
stamp_at "s#{n}", @grip.item_xy(i)
|
|
111
111
|
end
|
|
112
112
|
end
|
|
113
|
-
|
|
113
|
+
|
|
114
114
|
def create_stamps
|
|
115
115
|
create_choice_stamps
|
|
116
116
|
create_stamp('X') do
|
|
@@ -122,7 +122,7 @@ module Mork
|
|
|
122
122
|
end
|
|
123
123
|
end
|
|
124
124
|
end
|
|
125
|
-
|
|
125
|
+
|
|
126
126
|
def create_choice_stamps
|
|
127
127
|
ch_len.flatten.uniq.each do |t|
|
|
128
128
|
create_stamp("s#{t}") do
|
|
@@ -145,7 +145,7 @@ module Mork
|
|
|
145
145
|
align: :center,
|
|
146
146
|
valign: :center
|
|
147
147
|
end
|
|
148
|
-
|
|
148
|
+
|
|
149
149
|
def equal_choice_number?
|
|
150
150
|
return false unless ch_len.all? { |c| c.length == ch_len[0].length }
|
|
151
151
|
ch_len[0].each_with_index do |c, i|
|
|
@@ -153,11 +153,11 @@ module Mork
|
|
|
153
153
|
end
|
|
154
154
|
true
|
|
155
155
|
end
|
|
156
|
-
|
|
156
|
+
|
|
157
157
|
def ch_len
|
|
158
158
|
@all_choice_lengths ||= @content.collect { |c| c[:choices] }
|
|
159
159
|
end
|
|
160
|
-
|
|
160
|
+
|
|
161
161
|
# Choices are labeled 'A', 'B', ...
|
|
162
162
|
def letter_for(c)
|
|
163
163
|
(65+c).chr
|
data/lib/mork/version.rb
CHANGED
data/mork.gemspec
CHANGED
|
@@ -19,8 +19,8 @@ Gem::Specification.new do |s|
|
|
|
19
19
|
|
|
20
20
|
# dependencies:
|
|
21
21
|
s.add_dependency 'narray', '~> 0.6'
|
|
22
|
-
s.add_dependency 'mini_magick', '~> 4.
|
|
23
|
-
s.add_dependency 'prawn', '~> 1
|
|
22
|
+
s.add_dependency 'mini_magick', '~> 4.5'
|
|
23
|
+
s.add_dependency 'prawn', '~> 2.1'
|
|
24
24
|
s.add_development_dependency 'rake', '~> 10.3'
|
|
25
25
|
s.add_development_dependency 'rspec', '~> 3.1'
|
|
26
26
|
s.add_development_dependency 'guard', '~> 2.6'
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Mork
|
|
4
|
+
describe Coord do
|
|
5
|
+
let(:co) { Coord.new 50 }
|
|
6
|
+
|
|
7
|
+
it 'creates a Coord' do
|
|
8
|
+
expect(co).to be_a Coord
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
context 'returning coordinates' do
|
|
12
|
+
it 'works with just the width' do
|
|
13
|
+
expect(co.x).to eq 0
|
|
14
|
+
expect(co.y).to eq 0
|
|
15
|
+
expect(co.w).to eq 50
|
|
16
|
+
expect(co.h).to eq 50
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'yields modified coords with a coefficient' do
|
|
20
|
+
c = Coord.new 50, cx: 1.07
|
|
21
|
+
expect(c.x).to eq 0
|
|
22
|
+
expect(c.y).to eq 0
|
|
23
|
+
expect(c.w).to eq (50 * 1.07).round
|
|
24
|
+
expect(c.h).to eq (50 * 1.07).round
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'works with all arguments' do
|
|
28
|
+
c = Coord.new 50, cy: 1.04, h: 60, y: 25, cx: 0.97, x: 19
|
|
29
|
+
expect(c.y).to eq (25 * 1.04).round
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
context 'returning strings for imagemagick use' do
|
|
34
|
+
describe '#rect_points' do
|
|
35
|
+
it 'returns a well-formed string' do
|
|
36
|
+
expect(co.rect_points).to eq "0 0 50 50"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe '#cropper' do
|
|
41
|
+
it 'returns a well-formed string' do
|
|
42
|
+
expect(co.cropper).to eq "50x50+0+0"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'returns an X range' do
|
|
48
|
+
expect(co.x_rng).to eq(0...50)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'returns a Y range' do
|
|
52
|
+
expect(co.y_rng).to eq(0...50)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
data/spec/mork/grid_omr_spec.rb
CHANGED
|
@@ -6,101 +6,46 @@ module Mork
|
|
|
6
6
|
@grom = GridOMR.new 'spec/samples/layout.yml'
|
|
7
7
|
@grom.set_page_size 1601, 2281
|
|
8
8
|
end
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
describe '#choice_cell_area' do
|
|
11
11
|
it 'returns the coordinates of the first choice cell' do
|
|
12
|
-
@grom.choice_cell_area(0,0).
|
|
12
|
+
expect(@grom.choice_cell_area(0,0)).to have_coords(63, 436, 51, 41)
|
|
13
13
|
end
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
it 'returns the coordinates of the last choice cell' do
|
|
16
|
-
@grom.choice_cell_area(119,4).
|
|
16
|
+
expect(@grom.choice_cell_area(119,4)).to have_coords(1411, 2108, 51, 41)
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
|
-
|
|
20
|
-
describe '#barcode_bit_area' do
|
|
21
|
-
# it 'returns the coordinates of the first barcode bit area' do
|
|
22
|
-
# @grom.barcode_bit_area(0).should == {x: 160, y: 2260, w: 25, h: 21}
|
|
23
|
-
# end
|
|
24
|
-
#
|
|
25
|
-
# it 'returns the coordinates of the last barcode bit area' do
|
|
26
|
-
# @grom.barcode_bit_area(39).should == {x: 1475, y: 2260, w: 25, h: 21}
|
|
27
|
-
# end
|
|
28
|
-
#
|
|
29
|
-
# it 'fails if an invalid barcode bit is requested' do
|
|
30
|
-
# lambda { @grom.barcode_bit_area(40) }.should raise_error
|
|
31
|
-
# end
|
|
32
|
-
end
|
|
33
19
|
|
|
34
|
-
describe '#
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
c = @grom.rm_search_area :tl, 0
|
|
38
|
-
c.should == {x: 15, y: 15, w: 91, h: 92}
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it 'returns an {:x, :y, :w, :h} hash of coordinates in pixels for the :tr reg_mark corner' do
|
|
42
|
-
c = @grom.rm_search_area :tr, 0
|
|
43
|
-
c.should == { x: 1494, y: 15, w: 91, h: 92 }
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it 'returns an {:x, :y, :w, :h} hash of coordinates in pixels for the :br reg_mark corner' do
|
|
47
|
-
c = @grom.rm_search_area :br, 0
|
|
48
|
-
c.should == { x: 1494, y: 2173, w: 91, h: 92 }
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it 'returns an {:x, :y, :w, :h} hash of coordinates in pixels for the :bl reg_mark corner' do
|
|
52
|
-
c = @grom.rm_search_area :bl, 0
|
|
53
|
-
c.should == { x: 15, y: 2173, w: 91, h: 92 }
|
|
54
|
-
end
|
|
20
|
+
describe '#barcode_bit_area' do
|
|
21
|
+
it 'returns the coordinates of the first barcode bit area' do
|
|
22
|
+
expect(@grom.barcode_bit_area(0)).to have_coords(126, 2260, 25, 21)
|
|
55
23
|
end
|
|
56
24
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
c = @grom.rm_search_area :tl, 2
|
|
60
|
-
c.should == { x: 15, y: 15, w: 130, h: 131 }
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it 'returns an {:x, :y, :w, :h} hash of coordinates in pixels for the :tr reg_mark corner' do
|
|
64
|
-
c = @grom.rm_search_area :tr, 2
|
|
65
|
-
c.should == { x: 1456, y: 15, w: 130, h: 131 }
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it 'returns an {:x, :y, :w, :h} hash of coordinates in pixels for the :br reg_mark corner' do
|
|
69
|
-
c = @grom.rm_search_area :br, 2
|
|
70
|
-
c.should == { x: 1456, y: 2135, w: 130, h: 131 }
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
it 'returns an {:x, :y, :w, :h} hash of coordinates in pixels for the :bl reg_mark corner' do
|
|
74
|
-
c = @grom.rm_search_area :bl, 2
|
|
75
|
-
c.should == { x: 15, y: 2135, w: 130, h: 131 }
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
describe '#rm_edgy_x' do
|
|
81
|
-
it 'returns the minimum acceptable number of pixels from the regmark center to the edge of the rm_search_area' do
|
|
82
|
-
@grom.rm_edgy_x.should == 24
|
|
83
|
-
end
|
|
84
|
-
it 'returns an integer' do
|
|
85
|
-
@grom.rm_edgy_x.should be_a Fixnum
|
|
25
|
+
it 'returns the coordinates of the last barcode bit area' do
|
|
26
|
+
expect(@grom.barcode_bit_area(39)).to have_coords(1441, 2260, 25, 21)
|
|
86
27
|
end
|
|
87
28
|
end
|
|
88
29
|
|
|
89
|
-
describe '#
|
|
90
|
-
it 'returns
|
|
91
|
-
@grom.
|
|
30
|
+
describe '#rm_crop_area' do
|
|
31
|
+
it 'returns a Coord object for the :tl reg_mark corner' do
|
|
32
|
+
c = @grom.rm_crop_area :tl
|
|
33
|
+
expect(c). to have_coords(15, 15, 91, 92)
|
|
92
34
|
end
|
|
93
|
-
|
|
94
|
-
|
|
35
|
+
|
|
36
|
+
it 'returns a Coord object for the :tr reg_mark corner' do
|
|
37
|
+
c = @grom.rm_crop_area :tr
|
|
38
|
+
expect(c).to have_coords(1494, 15, 91, 92)
|
|
95
39
|
end
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
@grom.rm_max_search_area_side.should == 400
|
|
40
|
+
|
|
41
|
+
it 'returns a Coord object for the :br reg_mark corner' do
|
|
42
|
+
c = @grom.rm_crop_area :br
|
|
43
|
+
expect(c).to have_coords(1494, 2173, 91, 92)
|
|
101
44
|
end
|
|
102
|
-
|
|
103
|
-
|
|
45
|
+
|
|
46
|
+
it 'returns a Coord object for the :bl reg_mark corner' do
|
|
47
|
+
c = @grom.rm_crop_area :bl
|
|
48
|
+
expect(c).to have_coords(15, 2173, 91, 92)
|
|
104
49
|
end
|
|
105
50
|
end
|
|
106
51
|
|
|
@@ -109,17 +54,49 @@ module Mork
|
|
|
109
54
|
@grom.max_choices_per_question.should == 5
|
|
110
55
|
end
|
|
111
56
|
end
|
|
112
|
-
|
|
57
|
+
|
|
113
58
|
describe '#paper_white_area' do
|
|
114
59
|
it 'returns the coordinates of the white area used for barcode calibration' do
|
|
115
|
-
@grom.paper_white_area.
|
|
60
|
+
expect(@grom.paper_white_area).to have_coords(93, 2260, 25, 21)
|
|
116
61
|
end
|
|
117
62
|
end
|
|
118
|
-
|
|
63
|
+
|
|
119
64
|
describe '#ink_black_area' do
|
|
120
65
|
it 'returns the coordinates of the barcode calibration bar' do
|
|
121
|
-
@grom.ink_black_area.
|
|
66
|
+
expect(@grom.ink_black_area).to have_coords(126, 2260, 25, 21)
|
|
122
67
|
end
|
|
123
68
|
end
|
|
124
69
|
end
|
|
125
|
-
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# it 'fails if an invalid barcode bit is requested' do
|
|
74
|
+
# lambda { @grom.barcode_bit_area(40) }.should raise_error
|
|
75
|
+
# end
|
|
76
|
+
|
|
77
|
+
# describe '#rm_edgy_x' do
|
|
78
|
+
# it 'returns the minimum acceptable number of pixels from the regmark center to the edge of the rm_crop_area' do
|
|
79
|
+
# @grom.rm_edgy_x.should == 24
|
|
80
|
+
# end
|
|
81
|
+
# it 'returns an integer' do
|
|
82
|
+
# @grom.rm_edgy_x.should be_a Fixnum
|
|
83
|
+
# end
|
|
84
|
+
# end
|
|
85
|
+
|
|
86
|
+
# describe '#rm_edgy_y' do
|
|
87
|
+
# it 'returns the minimum acceptable number of pixels from the regmark center to the edge of the rm_crop_area' do
|
|
88
|
+
# @grom.rm_edgy_y.should == 24
|
|
89
|
+
# end
|
|
90
|
+
# it 'returns an integer' do
|
|
91
|
+
# @grom.rm_edgy_y.should be_a Fixnum
|
|
92
|
+
# end
|
|
93
|
+
# end
|
|
94
|
+
|
|
95
|
+
# describe '#rm_max_search_area_side' do
|
|
96
|
+
# it 'returns the maximum extent of the regmark search area, 1/4 of the raw image horizontal pixels' do
|
|
97
|
+
# @grom.rm_max_search_area_side.should == 400
|
|
98
|
+
# end
|
|
99
|
+
# it 'returns an integer' do
|
|
100
|
+
# @grom.rm_max_search_area_side.should be_a Fixnum
|
|
101
|
+
# end
|
|
102
|
+
# end
|
data/spec/mork/grid_spec.rb
CHANGED
|
@@ -4,7 +4,7 @@ module Mork
|
|
|
4
4
|
describe Grid do
|
|
5
5
|
context 'init params' do
|
|
6
6
|
it 'does not work with an integer' do
|
|
7
|
-
expect {Grid.new 1}.to raise_error
|
|
7
|
+
expect {Grid.new 1}.to raise_error RuntimeError
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
|
|
@@ -12,13 +12,13 @@ module Mork
|
|
|
12
12
|
before(:all) do
|
|
13
13
|
@grid = Grid.new 'spec/samples/layout.yml'
|
|
14
14
|
end
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
describe '#max_questions' do
|
|
17
17
|
it 'returns the maximum number of questions in a sheet' do
|
|
18
18
|
@grid.max_questions.should == 120
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
describe '#barcode_bits' do
|
|
23
23
|
it 'returns the number of bits used to define the form barcode' do
|
|
24
24
|
@grid.send(:barcode_bits).should == 40
|
|
@@ -26,7 +26,7 @@ module Mork
|
|
|
26
26
|
end
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
# describe "#cell_x" do
|
|
31
31
|
# context "for 1st-column questions" do
|
|
32
32
|
# it "returns the distance from the registration frame of the left edge of the 1st choice" do
|
|
@@ -68,7 +68,7 @@ end
|
|
|
68
68
|
# it "returns a hash" do
|
|
69
69
|
# grid.question_area(1).should be_an_instance_of(Hash)
|
|
70
70
|
# end
|
|
71
|
-
#
|
|
71
|
+
#
|
|
72
72
|
# it "returns the location in pixels of the first question patch" do
|
|
73
73
|
# c = grid.question_area(1)
|
|
74
74
|
# c[:x].should be_within(4).of(90)
|
|
@@ -79,13 +79,13 @@ end
|
|
|
79
79
|
# c[:x].should be_within(4).of(90)
|
|
80
80
|
# c[:y].should be_within(4).of(3120)
|
|
81
81
|
# end
|
|
82
|
-
#
|
|
82
|
+
#
|
|
83
83
|
# it "returns the location in pixels of the 121th question patch" do
|
|
84
84
|
# c = grid.question_area(121)
|
|
85
85
|
# c[:x].should be_within(4).of(1887)
|
|
86
86
|
# c[:y].should be_within(4).of(388)
|
|
87
87
|
# end
|
|
88
|
-
#
|
|
88
|
+
#
|
|
89
89
|
# it "returns the location in pixels of the last question patch" do
|
|
90
90
|
# c = grid.question_area(160)
|
|
91
91
|
# c[:x].should be_within(4).of(1887)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Mork
|
|
4
|
+
describe Magicko do
|
|
5
|
+
let(:sh) { sample_img :slanted }
|
|
6
|
+
let(:ma) { Magicko.new sh.filename }
|
|
7
|
+
let(:co) { Coord.new 50}
|
|
8
|
+
let(:pp) { { tl: {x: 10, y: 10}, tr: {x: 1000, y: 10}, bl: {x: 10, y: 1700}, br: {x: 1000, y: 1700}} }
|
|
9
|
+
|
|
10
|
+
it 'exists' do
|
|
11
|
+
expect(Magicko.new 1).to be_a Magicko
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe '#width' do
|
|
15
|
+
it 'returns the image width' do
|
|
16
|
+
expect(ma.width).to eq sh.width
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe '#height' do
|
|
21
|
+
it 'returns the image height' do
|
|
22
|
+
expect(ma.height).to eq sh.height
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
describe '#rm_patch' do
|
|
27
|
+
it 'returns an array of bytes for the registration mark area' do
|
|
28
|
+
expect(ma.rm_patch co).to be_an Array
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'returns an Array of appropriate size' do
|
|
32
|
+
expect(ma.rm_patch(co).length).to eq 2500
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
describe '#registered_bytes' do
|
|
37
|
+
it 'returns an array of bytes for the registered image' do
|
|
38
|
+
expect(ma.registered_bytes pp).to be_an Array
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'returns an array of bytes of the same size as the original image' do
|
|
42
|
+
expect(ma.registered_bytes(pp).length).to eq sh.height*sh.width
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
data/spec/mork/mimage_spec.rb
CHANGED
|
@@ -3,11 +3,33 @@ require 'spec_helper'
|
|
|
3
3
|
module Mork
|
|
4
4
|
describe Mimage do
|
|
5
5
|
let(:qna) { [5] * 100 }
|
|
6
|
+
|
|
7
|
+
context 'new age on slanted' do
|
|
8
|
+
let(:img) { sample_img 'slanted' }
|
|
9
|
+
let(:mim) { Mimage.new img.filename, qna, GridOMR.new(img.grid_file) }
|
|
10
|
+
describe 'basics' do
|
|
11
|
+
it 'should be valid' do
|
|
12
|
+
mim.highlight_rm_centers
|
|
13
|
+
mim.highlight_rm_areas
|
|
14
|
+
mim.write 'spec/out/slanted.jpg', false
|
|
15
|
+
expect(mim.valid?).to be_truthy
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'should return the correct regmark coordinates' do
|
|
19
|
+
[:tl, :tr, :br, :bl].each do |corner|
|
|
20
|
+
crn = mim.rm[corner]
|
|
21
|
+
expect(crn[:x]).to be_within(2).of(img.info[corner.to_s][0])
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
6
28
|
context 'problematic sheets' do
|
|
7
29
|
let(:mim) { Mimage.new 'spec/samples/out-1.jpg', qna, GridOMR.new('spec/samples/grid.yml') }
|
|
8
30
|
let(:bila) { Mimage.new 'spec/samples/syst/bila0.jpg', qna, GridOMR.new('spec/samples/grid.yml') }
|
|
9
|
-
|
|
10
|
-
|
|
31
|
+
|
|
32
|
+
it 'writes all cell values to a text file', exclude: true do
|
|
11
33
|
d=Dir['spec/samples/syst/*.jpg']
|
|
12
34
|
d.each do |f|
|
|
13
35
|
fn = File.basename f, '.jpg'
|
|
@@ -28,35 +50,23 @@ module Mork
|
|
|
28
50
|
end
|
|
29
51
|
end
|
|
30
52
|
end
|
|
31
|
-
|
|
53
|
+
|
|
32
54
|
context 'Old specs' do
|
|
33
55
|
let(:sgi) { sample_img 'sample-gray' }
|
|
34
56
|
let(:sg) { Mimage.new sgi.filename, qna, GridOMR.new(sgi.grid_file) }
|
|
35
|
-
|
|
57
|
+
|
|
36
58
|
describe 'basics' do
|
|
37
|
-
it 'returns the width' do
|
|
38
|
-
expect(sg.width).to eq sgi.width
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
it 'returns the height' do
|
|
42
|
-
expect(sg.height).to eq sgi.height
|
|
43
|
-
end
|
|
44
|
-
|
|
45
59
|
it 'returns the pixels as an array' do
|
|
46
|
-
expect(sg.send :
|
|
60
|
+
expect(sg.send :reg_pixels).to be_a NPatch
|
|
47
61
|
end
|
|
48
|
-
|
|
62
|
+
|
|
49
63
|
it 'returns the correct number of pixels' do
|
|
50
|
-
expect(sg.send(:
|
|
64
|
+
expect(sg.send(:reg_pixels).length).to eq sgi.width * sgi.height
|
|
51
65
|
end
|
|
52
66
|
|
|
53
67
|
it 'returns the stretched array' do
|
|
54
68
|
expect(sg.send(:reg_pixels).length).to eq sgi.width * sgi.height
|
|
55
69
|
end
|
|
56
|
-
|
|
57
|
-
it 'raises an error if the file is not found' do
|
|
58
|
-
expect { Mimage.new 'non_existing_file' }.to raise_error
|
|
59
|
-
end
|
|
60
70
|
end
|
|
61
71
|
|
|
62
72
|
describe 'inspecting' do
|
|
@@ -75,4 +85,4 @@ module Mork
|
|
|
75
85
|
end
|
|
76
86
|
end
|
|
77
87
|
end
|
|
78
|
-
end
|
|
88
|
+
end
|