sqed 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/README.md +2 -2
  4. data/lib/sqed/boundaries.rb +22 -7
  5. data/lib/sqed/boundary_finder/color_line_finder.rb +26 -19
  6. data/lib/sqed/boundary_finder.rb +2 -2
  7. data/lib/sqed/extractor.rb +33 -17
  8. data/lib/sqed/parser/barcode_parser.rb +32 -16
  9. data/lib/sqed/parser/ocr_parser.rb +24 -6
  10. data/lib/sqed/parser.rb +7 -0
  11. data/lib/sqed/result.rb +54 -6
  12. data/lib/sqed/version.rb +1 -1
  13. data/lib/sqed.rb +37 -12
  14. data/lib/sqed_config.rb +14 -8
  15. data/spec/lib/sqed/boundaries_spec.rb +26 -1
  16. data/spec/lib/sqed/boundary_finder_spec.rb +89 -1
  17. data/spec/lib/sqed/extractor_spec.rb +50 -76
  18. data/spec/lib/sqed/parser/barcode_spec.rb +25 -0
  19. data/spec/lib/sqed/parser/ocr_spec.rb +16 -0
  20. data/spec/lib/sqed/parser_spec.rb +6 -1
  21. data/spec/lib/sqed/result_spec.rb +24 -0
  22. data/spec/lib/sqed_spec.rb +58 -144
  23. data/spec/support/files/barcode_images/code_128_barcode.png +0 -0
  24. data/spec/support/files/barcode_images/datamatrix_barcode.png +0 -0
  25. data/spec/support/files/{2Dbarcode.png → barcode_images/osuc_datamatrix_barcode.png} +0 -0
  26. data/spec/support/files/label_images/basic1.png +0 -0
  27. data/spec/support/files/label_images/basic2.png +0 -0
  28. data/spec/support/files/label_images/readme.png +0 -0
  29. data/spec/support/files/{types_21.jpg → misc_images/types_21.jpg} +0 -0
  30. data/spec/support/files/{types_8.jpg → misc_images/types_8.jpg} +0 -0
  31. data/spec/support/files/{CrossyBlackLinesSpecimen.jpg → stage_images/CrossyBlackLinesSpecimen.jpg} +0 -0
  32. data/spec/support/files/{CrossyGreenLinesSpecimen.jpg → stage_images/CrossyGreenLinesSpecimen.jpg} +0 -0
  33. data/spec/support/files/{black_stage_green_line_specimen.jpg → stage_images/black_stage_green_line_specimen.jpg} +0 -0
  34. data/spec/support/files/{boundary_cross_green.jpg → stage_images/boundary_cross_green.jpg} +0 -0
  35. data/spec/support/files/{boundary_left_t_yellow.jpg → stage_images/boundary_left_t_yellow.jpg} +0 -0
  36. data/spec/support/files/{boundary_offset_cross_red.jpg → stage_images/boundary_offset_cross_red.jpg} +0 -0
  37. data/spec/support/files/{boundary_right_t_green.jpg → stage_images/boundary_right_t_green.jpg} +0 -0
  38. data/spec/support/files/stage_images/frost_stage.jpg +0 -0
  39. data/spec/support/files/{greenlineimage.jpg → stage_images/greenlineimage.jpg} +0 -0
  40. data/spec/support/files/test4.jpg +0 -0
  41. data/spec/support/image_helpers.rb +61 -33
  42. data/sqed.gemspec +3 -2
  43. metadata +58 -34
  44. data/spec/support/files/Quadrant_2_3.jpg +0 -0
  45. data/spec/support/files/test4OLD.jpg +0 -0
  46. data/spec/support/files/test_barcode.JPG +0 -0
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Sqed::Boundaries do
4
4
 
5
- let(:s) { Sqed::Boundaries.new}
5
+ let(:s) { Sqed::Boundaries.new }
6
6
  let(:layout) {:horizontal_split}
7
7
 
8
8
  specify "#coordinates defaults to a Hash when no layout provided" do
@@ -32,4 +32,29 @@ describe Sqed::Boundaries do
32
32
  end
33
33
  end
34
34
 
35
+ context '#offset' do
36
+ let(:s) { Sqed.new(image: ImageHelpers.crossy_green_line_specimen, pattern: :offset_cross) }
37
+ let(:offset_boundaries) {
38
+ s.crop_image
39
+ s.boundaries.offset(s.stage_boundary)
40
+ }
41
+
42
+ specify "offset and size should match internal found areas " do
43
+ sbx = s.stage_boundary.x_for(0)
44
+ sby = s.stage_boundary.y_for(0)
45
+
46
+ total_sections = s.boundaries.coordinates.count
47
+ expect(offset_boundaries.complete).to be(true)
48
+
49
+ (0..total_sections - 1).each do |i|
50
+ # check all the x/y
51
+ expect(offset_boundaries.x_for(i)).to eq(s.boundaries.x_for(i) + sbx)
52
+ expect(offset_boundaries.y_for(i)).to eq(s.boundaries.y_for(i) + sby)
53
+
54
+ # check all width/heights
55
+ expect(offset_boundaries.width_for(i)).to eq(s.boundaries.width_for(i))
56
+ expect(offset_boundaries.height_for(i)).to eq(s.boundaries.height_for(i))
57
+ end
58
+ end
59
+ end
35
60
  end
@@ -104,5 +104,93 @@ describe Sqed::BoundaryFinder do
104
104
  expect( Sqed::BoundaryFinder.frequency_stats(i, 15)).to eq(nil)
105
105
  end
106
106
  end
107
-
107
+
108
+ context 'offset boundaries from crossy_black_line_specimen image ' do
109
+ before(:all) {
110
+ @s = Sqed.new(image: ImageHelpers.crossy_black_line_specimen, pattern: :offset_cross, boundary_color: :black)
111
+ @s.crop_image
112
+ @offset_boundaries = @s.boundaries.offset(@s.stage_boundary)
113
+ true
114
+ }
115
+
116
+ ##**** actually fails (?!)
117
+ specify "offset and size should match internal found areas " do
118
+ sbx = @s.stage_boundary.x_for(0)
119
+ sby = @s.stage_boundary.y_for(0)
120
+
121
+ sl = @s.boundaries.coordinates.length # may be convenient to clone this model for other than 4 boundaries found
122
+ expect(sl).to eq(4) #for offset cross pattern and valid image
123
+ expect(@s.boundaries.complete).to be(true)
124
+ expect(@offset_boundaries.complete).to be(true)
125
+ (0..sl - 1).each do |i|
126
+ # check all the x/y
127
+ expect(@offset_boundaries.x_for(i)).to eq(@s.boundaries.x_for(i) + sbx)
128
+ expect(@offset_boundaries.y_for(i)).to eq(@s.boundaries.y_for(i) + sby)
129
+
130
+ # check all width/heights
131
+ expect(@offset_boundaries.width_for(i)).to eq(@s.boundaries.width_for(i))
132
+ expect(@offset_boundaries.height_for(i)).to eq(@s.boundaries.height_for(i))
133
+ end
134
+ end
135
+ end
136
+
137
+ context 'offset boundaries from black_green_line_specimen image ' do
138
+ before(:all) {
139
+ @s = Sqed.new(image: ImageHelpers.black_stage_green_line_specimen, pattern: :offset_cross)
140
+ @s.crop_image
141
+ @offset_boundaries = @s.boundaries.offset(@s.stage_boundary)
142
+ true
143
+ }
144
+
145
+ specify "offset and size should match internal found areas " do
146
+ sbx = @s.stage_boundary.x_for(0)
147
+ sby = @s.stage_boundary.y_for(0)
148
+
149
+ sl = @s.boundaries.coordinates.count # may be convenient to clone this model for other than 4 boundaries found
150
+ expect(sl).to eq(4) #for offset cross pattern and valid image
151
+ expect(@s.boundaries.complete).to be(true)
152
+ expect(@offset_boundaries.complete).to be(true)
153
+ (0..sl - 1).each do |i|
154
+ # check all the x/y
155
+ expect(@offset_boundaries.x_for(i)).to eq(@s.boundaries.x_for(i) + sbx)
156
+ expect(@offset_boundaries.y_for(i)).to eq(@s.boundaries.y_for(i) + sby)
157
+
158
+ # check all width/heights
159
+ expect(@offset_boundaries.width_for(i)).to eq(@s.boundaries.width_for(i))
160
+ expect(@offset_boundaries.height_for(i)).to eq(@s.boundaries.height_for(i))
161
+ end
162
+ end
163
+ end
164
+
165
+ context 'offset boundaries from original red_line image ' do
166
+ before(:all) {
167
+ @s = Sqed.new(image: ImageHelpers.offset_cross_red, pattern: :right_t, boundary_color: :red)
168
+ @s.crop_image
169
+ @offset_boundaries = @s.boundaries.offset(@s.stage_boundary)
170
+ }
171
+
172
+ specify "offset and size should match internal found areas " do
173
+ sbx = @s.stage_boundary.x_for(0) # only a single boundary
174
+ sby = @s.stage_boundary.y_for(0)
175
+ pct = 0.02
176
+
177
+ sl = @s.boundaries.coordinates.count
178
+ expect(sl).to eq(3)
179
+ expect(@s.boundaries.complete).to be(true)
180
+ expect(@offset_boundaries.complete).to be(true)
181
+ expect(@s.stage_boundary.width_for(0)).to be_within(pct*800).of(800)
182
+ expect(@s.stage_boundary.height_for(0)).to be_within(pct*600).of(600)
183
+ (0..sl - 1).each do |i|
184
+ # check all the x/y
185
+ expect(@offset_boundaries.x_for(i)).to eq(@s.boundaries.x_for(i) + sbx)
186
+ expect(@offset_boundaries.y_for(i)).to eq(@s.boundaries.y_for(i) + sby)
187
+
188
+ # check all width/heights
189
+ expect(@offset_boundaries.width_for(i)).to eq(@s.boundaries.width_for(i))
190
+ expect(@offset_boundaries.height_for(i)).to eq(@s.boundaries.height_for(i))
191
+ end
192
+ end
193
+ end
194
+
195
+
108
196
  end
@@ -1,82 +1,56 @@
1
1
  require 'spec_helper'
2
-
3
2
  describe Sqed::Extractor do
4
3
 
5
- let(:s) {Sqed::Extractor.new}
6
-
7
- # context 'attributes' do
8
- # specify '#image' do
9
- # # expect that s.image is a method
10
- # expect(s).to respond_to(:image)
11
- # end
12
-
13
- # specify 'autocropper/edgeDetector works' do
14
- # this_image = ImageHelpers.ocr_image
15
- # expect(Sqed::AutoCropper.new(this_image)).to be_truthy
16
- # end
17
-
18
- # specify 'Sqed.new(image: file) assigns to image' do
19
- # specify 'Sqed.new(image:file) "works"' do
20
- # expect(Sqed.new(image: ImageHelpers.test0_image)).to be_truthy
21
- # end
22
- # end
23
-
24
- # specify 'green line parser does something' do
25
- # this_image = ImageHelpers.greenline_image
26
- # cropped_image = Sqed::AutoCropper.new(this_image).img
27
- # a = Sqed::GreenLineFinder.new(cropped_image)
28
- # b = 0
29
- # end
30
-
31
- # specify 'Sqed.new(image: file) assigns to image' do
32
- # a = Sqed.new(image: ImageHelpers.test0_image)
33
- # expect(a.image == ImageHelpers.test0_image).to be(true)
34
- # end
35
- # end
4
+ let(:metadata_map) {
5
+ {0 => :specimen, 1 => :identifier, 2 => :nothing, 3 => :image_registration }
6
+ }
7
+
8
+ let(:image) { ImageHelpers.crossy_green_line_specimen }
9
+
10
+ let(:boundaries) {
11
+ Sqed::BoundaryFinder::CrossFinder.new(
12
+ image: image
13
+ ).boundaries
14
+ }
15
+
16
+ let(:e) {
17
+ Sqed::Extractor.new(
18
+ boundaries: boundaries,
19
+ image: image,
20
+ metadata_map: metadata_map
21
+ )
22
+ }
23
+
24
+ context 'attributes' do
25
+ specify '#image' do
26
+ expect(e).to respond_to(:image)
27
+ end
28
+
29
+ specify '#metadata_map' do
30
+ expect(e).to respond_to(:metadata_map)
31
+ end
32
+
33
+ specify '#boundaries' do
34
+ expect(e).to respond_to(:boundaries)
35
+ end
36
+ end
37
+
38
+ context 'extracting to a #result' do
39
+ let(:r) { e.result }
40
+
41
+ specify '#result retuns a Sqed::Result' do
42
+ expect(r.class.name).to eq('Sqed::Result')
43
+ end
44
+
45
+ specify '#result is populated with images' do
46
+ expect(r.images.values.first.class.name).to eq('Magick::Image')
47
+ end
48
+
49
+ specify '#result is populated with text' do
50
+ expect(r.text_for(:identifier)).to match('000085067')
51
+ end
52
+ end
36
53
 
37
- # specify 'zbar barcode decodes' do
38
- # eb = Sqed::BarcodeParser.new(image: ImageHelpers.barcode_image) # was barcode_image
39
- # bc = eb.barcodes
40
- # expect(bc).to be_truthy
41
- # expect(bc[2]).to eq('CODE-128:013117001040986')
42
- # expect(bc[3]).to eq('CODE-128:SDLXHD1QTDVGJ')
43
- # expect(bc[4]).to eq('CODE-128:1PPD368LL/A')
44
- # expect(bc[5]).to eq('EAN-13:0885909541171')
45
- # expect(bc[6]).to eq('EAN-13:885909270334')
46
- # expect(bc[7]).to be(nil)
47
- # end
48
-
49
- # specify 'INHS specimen labels' do
50
- # eg = Sqed.new(image: ImageHelpers.labels_image)
51
- # # eg = Sqed.new(image: ImageHelpers.foo3_image)
52
- # eg.image.rotate!(270.0)
53
- # eg.image.write('foo5.jpg')
54
- # egt = eg.text_from_quadrant(3)
55
- # expect(egt).to match(/529 234/)
56
- # end
57
-
58
- # context "foo.jpg" do
59
- # let(:eg) { Sqed.new(image: ImageHelpers.ocr_image) }
60
-
61
- # specify 'all together' do
62
- # # eg = Sqed.new(image: ImageHelpers.ocr_image)
63
- # egt = eg.text_from_quadrant(3)
54
+ end
64
55
 
65
- # expect(egt).to match(/Designed by Apple in California/)
66
- # expect(egt).to match(/8 85909 27035/)
67
- # expect(egt).to match(/EASY/)
68
- # expect(eg.text_from_quadrant(3)).to match(/013‘1700104U986/) #ACTUALLY 013117001040986
69
56
 
70
- # eg = Sqed.new(image: ImageHelpers.ocr_image)
71
- # egb = eg.text_from_quadrant(2)
72
- # u = 1 #pre-test breakpoint
73
- # expect(egb.barcodes[0]).to eq('QR-Code:http://youtu.be/h9fkPPp8Y1c')
74
- # expect(egb.barcodes[1]).to eq('EAN-13:0885909270354')
75
- # expect(egb.barcodes[2]).to eq('CODE-128:013117001040986')
76
- # expect(egb.barcodes[3]).to eq('CODE-128:SDLXHD1QTDVGJ')
77
- # expect(egb.barcodes[4]).to eq('CODE-128:1PPD368LL/A')
78
- # expect(egb.barcodes[5]).to eq('EAN-13:0885909541171')
79
- # expect(egb.barcodes[6]).to be(nil)
80
- # end
81
- # end
82
- end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ # Test barcodes where generated here: http://www.terryburton.co.uk/barcodewriter/generator/, thanks Terry!
4
+ #
5
+ # http://metafloor.github.io/bwip-js/demo/demo.html
6
+ describe Sqed::Parser::BarcodeParser do
7
+
8
+ let(:image) { ImageHelpers.code_128_barcode_image }
9
+ let(:p) { Sqed::Parser::BarcodeParser.new(image) }
10
+
11
+
12
+ specify '#image' do
13
+ expect(p).to respond_to(:image)
14
+ end
15
+
16
+ specify '#barcode' do
17
+ expect(p).to respond_to(:barcode)
18
+ end
19
+
20
+ specify '#barcode returns some text' do
21
+ expect(p.barcode).to eq('Count01234567!')
22
+ end
23
+
24
+ end
25
+
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sqed::Parser::OcrParser do
4
+
5
+ let(:image) { ImageHelpers.readme_text }
6
+ let(:p) { Sqed::Parser::OcrParser.new(image) }
7
+
8
+ specify '#image' do
9
+ expect(p).to respond_to(:image)
10
+ end
11
+
12
+ specify '#text returns some text' do
13
+ expect(p.text).to eq('README.md')
14
+ end
15
+
16
+ end
@@ -2,5 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe Sqed::Parser do
4
4
 
5
- let(:s) {Sqed::Parser.new}
5
+ let(:image) { ImageHelpers.standard_cross_green }
6
+ let(:p) { Sqed::Parser.new(image) }
7
+
8
+ specify '#image' do
9
+ expect(p).to respond_to(:image)
10
+ end
6
11
  end
@@ -4,6 +4,7 @@ describe Sqed::Result do
4
4
  let(:r) {Sqed::Result.new}
5
5
 
6
6
  context "attributes are derived from SqedConfig::LAYOUT_SECTION_TYPES" do
7
+
7
8
  SqedConfig::LAYOUT_SECTION_TYPES.each do |type|
8
9
  specify "##{type}" do
9
10
  expect(r.respond_to?(type.to_sym)).to be_truthy
@@ -12,6 +13,29 @@ describe Sqed::Result do
12
13
  specify "##{type}_image" do
13
14
  expect(r.respond_to?("#{type}_image".to_sym)).to be_truthy
14
15
  end
16
+
17
+ specify "##{type} initializes to {}" do
18
+ expect(r.send(type.to_sym)).to eq({})
19
+ end
15
20
  end
16
21
  end
22
+
23
+ context 'with a new() result' do
24
+ specify '#text_for(section)' do
25
+ expect(r.text_for(:specimen)).to eq(nil)
26
+ end
27
+
28
+ specify '#barcode_text_for(section)' do
29
+ expect(r.barcode_text_for(:identifier)).to eq(nil)
30
+ end
31
+
32
+ specify '#text' do
33
+ expect(r.text).to eq({})
34
+ end
35
+
36
+ specify '#images' do
37
+ expect(r.text).to eq({})
38
+ end
39
+ end
40
+
17
41
  end
@@ -16,6 +16,22 @@ describe Sqed do
16
16
  specify '#stage_image' do
17
17
  expect(s).to respond_to(:image)
18
18
  end
19
+
20
+ specify '#stage_boundary' do
21
+ expect(s).to respond_to(:stage_boundary)
22
+ end
23
+
24
+ specify '#boundaries' do
25
+ expect(s).to respond_to(:boundaries)
26
+ end
27
+
28
+ specify '#auto_detect_border' do
29
+ expect(s).to respond_to(:auto_detect_border)
30
+ end
31
+
32
+ specify '#boundary_color' do
33
+ expect(s).to respond_to(:boundary_color)
34
+ end
19
35
  end
20
36
 
21
37
  context 'initialization' do
@@ -24,37 +40,26 @@ describe Sqed do
24
40
  end
25
41
  end
26
42
 
27
- context 'asking for a result' do
43
+ context '#result' do
28
44
  specify 'without providing an image returns false' do
29
45
  expect(s.result).to eq(false)
30
46
  end
31
47
  end
32
48
 
33
- context 'with a test image' do
34
- let(:a) { ImageHelpers.test0_image }
35
- before {
36
- s.image = a
37
- }
38
-
39
- specify '#crop_image' do #should expand to multiple cases of image border types
49
+ # test intent is to just test wrapping functionality, see
50
+ # other tests for specifics on finders
51
+ context '#crop_image (with bordered stage)' do
52
+ specify 'finds a cropped image smaller than original' do
53
+ s.image = ImageHelpers.test3_image
40
54
  expect(s.crop_image).to be_truthy
41
- expect(s.stage_image.columns < a.columns).to be(true)
42
- expect(s.stage_image.rows < a.rows).to be(true)
43
- end
44
-
45
- specify '#boundaries returns a Sqed::Boundaries instance' do
46
- s.pattern = :standard_cross
47
- expect(s.boundaries.class).to eq(Sqed::Boundaries)
55
+ expect(s.stage_image.columns < s.image.columns).to be(true)
56
+ expect(s.stage_image.rows < s.image.rows).to be(true)
48
57
  end
49
- end
50
58
 
51
- context 'stage image with a border' do
52
- let(:a) { ImageHelpers.standard_cross_green }
53
- before {
54
- s.image = a
55
- s.crop_image
56
- }
57
- specify 'stage boundary is created for standard_ cross_green ~ (100,94, 800, 600)' do
59
+ specify 'properly sets stage boundaries ' do
60
+ s.image = ImageHelpers.standard_cross_green
61
+ s.crop_image
62
+ # ~ (100,94, 800, 600)
58
63
  expect(s.stage_boundary.x_for(0)).to be_within(2).of 100
59
64
  expect(s.stage_boundary.y_for(0)).to be_within(2).of 94
60
65
  expect(s.stage_boundary.width_for(0)).to be_within(2).of 800
@@ -62,139 +67,48 @@ describe Sqed do
62
67
  end
63
68
  end
64
69
 
65
- context 'offset boundaries from original crossy_green_line_specimen image ' do
66
- before(:all) {
67
- @s = Sqed.new(image: ImageHelpers.crossy_green_line_specimen, pattern: :offset_cross)
68
- @s.crop_image
69
- @offset_boundaries = @s.boundaries.offset(@s.stage_boundary)
70
- wtf = 0
71
- }
72
-
73
- specify "offset and size should match internal found areas " do
74
- sbx = @s.stage_boundary.x_for(0)
75
- sby = @s.stage_boundary.y_for(0)
76
-
77
- sl = @s.boundaries.coordinates.length # may be convenient to clone this model for other than 4 boundaries found
78
- expect(sl).to eq(4) #for offset cross pattern and valid image
79
- expect(@s.boundaries.complete).to be(true)
80
- expect(@offset_boundaries.complete).to be(true)
81
- (0..sl - 1).each do |i|
82
- # check all the x/y
83
- expect(@offset_boundaries.x_for(i)).to eq(@s.boundaries.x_for(i) + sbx)
84
- expect(@offset_boundaries.y_for(i)).to eq(@s.boundaries.y_for(i) + sby)
85
-
86
- # check all width/heights
87
- expect(@offset_boundaries.width_for(i)).to eq(@s.boundaries.width_for(i))
88
- expect(@offset_boundaries.height_for(i)).to eq(@s.boundaries.height_for(i))
89
- end
70
+ context 'all together' do
71
+ let(:image) { ImageHelpers.frost_stage }
72
+ let(:pattern) { :offset_cross }
73
+ let(:s) { Sqed.new(image: image, pattern: pattern) }
74
+
75
+ specify '#boundaries returns a Sqed::Boundaries instance' do
76
+ # s.pattern = :standard_cross
77
+ expect(s.boundaries.class.name).to eq('Sqed::Boundaries')
90
78
  end
91
79
 
92
- specify "find image, barcode, and text content" do
93
- bc = Sqed::Extractor.new(boundaries: [0, 0, @s.image.columns, @s.image.rows], image: @s.image, layout: :offset_cross)
94
- poc = Sqed::Parser::OcrParser.new(bc.extract_image(@offset_boundaries.coordinates[1]))
95
- expect(poc.text).to eq('000085067')
80
+ specify '#stage_image returns an Magick::Image' do
81
+ expect(s.stage_image.class.name).to eq('Magick::Image')
96
82
  end
97
83
 
98
- end
84
+ specify '#crop_image returns an Magick::Image' do
85
+ expect(s.crop_image.class.name).to eq('Magick::Image')
86
+ end
99
87
 
100
- context 'offset boundaries from crossy_black_line_specimen image ' do
101
- before(:all) {
102
- @s = Sqed.new(image: ImageHelpers.crossy_black_line_specimen, pattern: :offset_cross, boundary_color: :black)
103
- @s.crop_image
104
- @offset_boundaries = @s.boundaries.offset(@s.stage_boundary)
105
- wtf = 0
106
- }
107
-
108
- specify "offset and size should match internal found areas " do ##**** actually fails
109
-
110
- sbx = @s.stage_boundary.x_for(0)
111
- sby = @s.stage_boundary.y_for(0)
112
-
113
- sl = @s.boundaries.coordinates.length # may be convenient to clone this model for other than 4 boundaries found
114
- expect(sl).to eq(4) #for offset cross pattern and valid image
115
- expect(@s.boundaries.complete).to be(true)
116
- expect(@offset_boundaries.complete).to be(true)
117
- (0..sl - 1).each do |i|
118
- # check all the x/y
119
- expect(@offset_boundaries.x_for(i)).to eq(@s.boundaries.x_for(i) + sbx)
120
- expect(@offset_boundaries.y_for(i)).to eq(@s.boundaries.y_for(i) + sby)
121
-
122
- # check all width/heights
123
- expect(@offset_boundaries.width_for(i)).to eq(@s.boundaries.width_for(i))
124
- expect(@offset_boundaries.height_for(i)).to eq(@s.boundaries.height_for(i))
125
- end
88
+ specify '#crop_image returns #stage_image' do
89
+ expect(s.crop_image).to eq(s.stage_image)
126
90
  end
127
- end
128
91
 
129
- context 'offset boundaries from black_green_line_specimen image ' do
130
- before(:all) {
131
- @s = Sqed.new(image: ImageHelpers.black_stage_green_line_specimen, pattern: :offset_cross)
132
- @s.crop_image
133
- @offset_boundaries = @s.boundaries.offset(@s.stage_boundary)
134
- wtf = 0
135
- }
136
-
137
- specify "offset and size should match internal found areas " do
138
- sbx = @s.stage_boundary.x_for(0)
139
- sby = @s.stage_boundary.y_for(0)
140
-
141
- sl = @s.boundaries.coordinates.length # may be convenient to clone this model for other than 4 boundaries found
142
- expect(sl).to eq(4) #for offset cross pattern and valid image
143
- expect(@s.boundaries.complete).to be(true)
144
- expect(@offset_boundaries.complete).to be(true)
145
- (0..sl - 1).each do |i|
146
- # check all the x/y
147
- expect(@offset_boundaries.x_for(i)).to eq(@s.boundaries.x_for(i) + sbx)
148
- expect(@offset_boundaries.y_for(i)).to eq(@s.boundaries.y_for(i) + sby)
149
-
150
- # check all width/heights
151
- expect(@offset_boundaries.width_for(i)).to eq(@s.boundaries.width_for(i))
152
- expect(@offset_boundaries.height_for(i)).to eq(@s.boundaries.height_for(i))
92
+ context '#result' do
93
+ let(:r) { s.result }
94
+ specify 'returns a Sqed::Result' do
95
+ expect(r.class.name).to eq('Sqed::Result')
153
96
  end
154
- end
155
97
 
156
- specify "find image, barcode, and text content" do
157
- bc = Sqed::Extractor.new(boundaries: [0, 0, @s.image.columns, @s.image.rows], image: @s.image, layout: :offset_cross)
158
- # ioc = bc.extract_image(@offset_boundaries.coordinates[3])
159
- # iioc = ioc.crop(384, 140, 1420, 572, true)
160
- poc = Sqed::Parser::OcrParser.new(bc.extract_image(@offset_boundaries.coordinates[3]).crop(400, 140, 1420, 600, true))
161
- # expect(poc.text).to eq('000085067')
162
- ppc = Sqed::Parser::OcrParser.new(ImageHelpers.black_stage_green_line_specimen_label)
163
- poc.image.write('tmp/poc.jpg')
164
- ppc.image.write('tmp/ppc.jpg')
165
- expect(ppc.text).to eq(poc.text)
166
- end
98
+ context 'extracted data' do
99
+ specify 'for an :identifier section' do
100
+ expect(r.text_for(:identifier)).to match('000041196')
101
+ end
167
102
 
168
- end
103
+ specify 'for a specimen section' do
104
+ expect(r.text_for(:specimen)).to match('Saucier Creek')
105
+ end
169
106
 
170
- context 'offset boundaries from original red_line image ' do
171
- before(:all) {
172
- @s = Sqed.new(image: ImageHelpers.offset_cross_red, pattern: :right_t, boundary_color: :red)
173
- @s.crop_image
174
- @offset_boundaries = @s.boundaries.offset(@s.stage_boundary)
175
- wtf = 0
176
- }
177
-
178
- specify "offset and size should match internal found areas " do
179
- sbx = @s.stage_boundary.x_for(0) # only a single boundary
180
- sby = @s.stage_boundary.y_for(0)
181
- pct = 0.02
182
-
183
- sl = @s.boundaries.coordinates.length # may be convenient to clone this model for other than 4 boundaries found
184
- expect(sl).to eq(3) #for offset cross pattern and valid image
185
- expect(@s.boundaries.complete).to be(true)
186
- expect(@offset_boundaries.complete).to be(true)
187
- expect(@s.stage_boundary.width_for(0)).to be_within(pct*800).of(800)
188
- expect(@s.stage_boundary.height_for(0)).to be_within(pct*600).of(600)
189
- (0..sl - 1).each do |i|
190
- # check all the x/y
191
- expect(@offset_boundaries.x_for(i)).to eq(@s.boundaries.x_for(i) + sbx)
192
- expect(@offset_boundaries.y_for(i)).to eq(@s.boundaries.y_for(i) + sby)
193
-
194
- # check all width/heights
195
- expect(@offset_boundaries.width_for(i)).to eq(@s.boundaries.width_for(i))
196
- expect(@offset_boundaries.height_for(i)).to eq(@s.boundaries.height_for(i))
107
+ specify 'for a curator_metadata section' do
108
+ expect(r.text_for(:curator_metadata)).to match('Frost Entomological Museum')
109
+ end
197
110
  end
198
111
  end
199
112
  end
113
+
200
114
  end
Binary file