sqed 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sqed.rb +29 -29
- data/lib/sqed/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 764316ed1537a871299cafd5c1f1df6045c525ec
|
4
|
+
data.tar.gz: ebc12360ba5d9eabe0b895c4238d7785bb1d8d4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcee70b54a7cc400fcdf220de15f2c79a479102cb0fa1cd57e6e81ca9e4d92247c9a40fad717f43051adaae40d30c511be4eff3dcd84e60baf7bdad5eef7e189
|
7
|
+
data.tar.gz: e191bbc0ca11a86c0ec7a6a06bf0068a0cfa78e97766e6533f1182bb9e6f73c790fbd3ff7ba3702910b1dc8749554cba779664d509700d40e81107f941be0ba7
|
data/lib/sqed.rb
CHANGED
@@ -3,14 +3,14 @@
|
|
3
3
|
recent_ruby = RUBY_VERSION >= '2.1.1'
|
4
4
|
raise "IMPORTANT: sqed gem requires ruby >= 2.1.1" unless recent_ruby
|
5
5
|
|
6
|
-
require "
|
6
|
+
require "rmagick"
|
7
7
|
|
8
8
|
# Instances take the following
|
9
9
|
# 1) A base image @image
|
10
10
|
# 2) A target extraction pattern, or individually specified attributes
|
11
11
|
#
|
12
12
|
# Return a Sqed::Result
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# a = Sqed.new(pattern: :vertical_offset_cross, image: image)
|
15
15
|
# b = a.result # => Sqed::Result instance
|
16
16
|
#
|
@@ -26,7 +26,7 @@ class Sqed
|
|
26
26
|
# !optional! A lookup macro that if provided sets boundary_finder, layout, and metadata_map. These can be individually overwritten.
|
27
27
|
# Legal values are symbols taken from SqedConfig::EXTRACTION_PATTERNS.
|
28
28
|
# DO NOT pass pattern outside of a sqed instance!
|
29
|
-
#
|
29
|
+
#
|
30
30
|
# !! Always passed as an option :target_pattern, an persisted as :pattern
|
31
31
|
attr_accessor :pattern
|
32
32
|
|
@@ -36,42 +36,42 @@ class Sqed
|
|
36
36
|
# the image that is the cropped content for parsing
|
37
37
|
attr_accessor :stage_image
|
38
38
|
|
39
|
-
# a Sqed::Boundaries instance that stores the coordinates of the stage
|
39
|
+
# a Sqed::Boundaries instance that stores the coordinates of the stage
|
40
40
|
attr_accessor :stage_boundary
|
41
|
-
|
41
|
+
|
42
42
|
# a Sqed::Boundaries instances that contains the coordinates of the interan stage sections
|
43
43
|
attr_accessor :boundaries
|
44
|
-
|
44
|
+
|
45
45
|
# Boolean, whether to detect the border on initialization, i.e. new()
|
46
|
-
attr_accessor :has_border
|
47
|
-
|
48
|
-
# a symbol, :red, :green, :blue, describing the boundary color within the stage
|
46
|
+
attr_accessor :has_border
|
47
|
+
|
48
|
+
# a symbol, :red, :green, :blue, describing the boundary color within the stage
|
49
49
|
attr_accessor :boundary_color
|
50
50
|
|
51
|
-
# Boolean, whether to do the boundary detection (not stage detection at present) against a thumbnail version of the passed image (faster, less accurate, true be default)
|
51
|
+
# Boolean, whether to do the boundary detection (not stage detection at present) against a thumbnail version of the passed image (faster, less accurate, true be default)
|
52
52
|
attr_accessor :use_thumbnail
|
53
53
|
|
54
|
-
# Provide a metadata map, overrides metadata taken from pattern.
|
54
|
+
# Provide a metadata map, overrides metadata taken from pattern.
|
55
55
|
# !! Always passed as an option :target_metadata_map, an persisted as :metadata_map
|
56
56
|
attr_accessor :metadata_map
|
57
57
|
|
58
58
|
# Provide a boundary_finder, overrides metadata taken from pattern
|
59
|
-
attr_accessor :boundary_finder
|
60
|
-
|
59
|
+
attr_accessor :boundary_finder
|
60
|
+
|
61
61
|
def initialize(target_image: nil, target_pattern: nil, target_layout: nil, has_border: true, boundary_color: :green, use_thumbnail: true, boundary_finder: nil, target_metadata_map: nil)
|
62
|
-
raise 'extraction pattern not defined' if target_pattern && !SqedConfig::EXTRACTION_PATTERNS.keys.include?(target_pattern)
|
62
|
+
raise 'extraction pattern not defined' if target_pattern && !SqedConfig::EXTRACTION_PATTERNS.keys.include?(target_pattern)
|
63
63
|
|
64
64
|
# data, and stubs for results
|
65
65
|
@image = target_image
|
66
66
|
@boundaries = nil
|
67
|
-
@stage_boundary = Sqed::Boundaries.new(:internal_box)
|
67
|
+
@stage_boundary = Sqed::Boundaries.new(:internal_box)
|
68
68
|
|
69
69
|
# extraction metadata
|
70
70
|
@pattern = target_pattern # not required if target_layout, target_metadata_map, and boundary_finder are provided
|
71
71
|
|
72
72
|
@has_border = has_border
|
73
73
|
@boundary_finder = boundary_finder.constantize if boundary_finder
|
74
|
-
@layout = target_layout
|
74
|
+
@layout = target_layout
|
75
75
|
@layout ||= SqedConfig::EXTRACTION_PATTERNS[pattern][:layout] if pattern
|
76
76
|
|
77
77
|
@metadata_map = target_metadata_map
|
@@ -89,12 +89,12 @@ class Sqed
|
|
89
89
|
|
90
90
|
# if pattern is not provided, these must be
|
91
91
|
data[:boundary_finder] = @boundary_finder if boundary_finder
|
92
|
-
data[:target_layout] = layout if layout
|
92
|
+
data[:target_layout] = layout if layout
|
93
93
|
data[:target_metadata_map] = metadata_map if metadata_map
|
94
94
|
|
95
|
-
data[:boundary_color] = boundary_color
|
96
|
-
data[:has_border] = has_border
|
97
|
-
data[:use_thumbnail] = use_thumbnail
|
95
|
+
data[:boundary_color] = boundary_color
|
96
|
+
data[:has_border] = has_border
|
97
|
+
data[:use_thumbnail] = use_thumbnail
|
98
98
|
data
|
99
99
|
end
|
100
100
|
|
@@ -102,7 +102,7 @@ class Sqed
|
|
102
102
|
# set the image if it's not set during initialize(), not commonly used
|
103
103
|
def image=(value)
|
104
104
|
@image = value
|
105
|
-
set_stage_boundary
|
105
|
+
set_stage_boundary
|
106
106
|
@image
|
107
107
|
end
|
108
108
|
|
@@ -118,7 +118,7 @@ class Sqed
|
|
118
118
|
|
119
119
|
def stage_image
|
120
120
|
crop_image if @stage_image.nil?
|
121
|
-
@stage_image
|
121
|
+
@stage_image
|
122
122
|
end
|
123
123
|
|
124
124
|
# Return [Sqed::Boundaries instance]
|
@@ -129,23 +129,23 @@ class Sqed
|
|
129
129
|
@boundaries.offset(stage_boundary)
|
130
130
|
else
|
131
131
|
nil
|
132
|
-
end
|
132
|
+
end
|
133
133
|
end
|
134
134
|
|
135
135
|
# return [Image]
|
136
136
|
# crops the stage if not done, then sets/returns @stage_image
|
137
137
|
def crop_image
|
138
|
-
if has_border
|
138
|
+
if has_border
|
139
139
|
@stage_image = image.crop(*stage_boundary.for(SqedConfig.index_for_section_type(:stage, :stage)), true)
|
140
140
|
else
|
141
|
-
@stage_image = image
|
141
|
+
@stage_image = image
|
142
142
|
end
|
143
143
|
@stage_image
|
144
144
|
end
|
145
145
|
|
146
146
|
def result
|
147
|
-
return false if image.nil?
|
148
|
-
return false if pattern.nil? && (metadata_map.nil? && layout.nil? && boundary_finder.nil?)
|
147
|
+
return false if image.nil?
|
148
|
+
return false if pattern.nil? && (metadata_map.nil? && layout.nil? && boundary_finder.nil?)
|
149
149
|
|
150
150
|
extractor = Sqed::Extractor.new(
|
151
151
|
target_boundaries: boundaries,
|
@@ -168,8 +168,8 @@ class Sqed
|
|
168
168
|
def set_stage_boundary
|
169
169
|
if has_border
|
170
170
|
boundary = Sqed::BoundaryFinder::StageFinder.new(target_image: image).boundaries
|
171
|
-
if boundary.populated?
|
172
|
-
@stage_boundary.set(0, boundary.for(0))
|
171
|
+
if boundary.populated?
|
172
|
+
@stage_boundary.set(0, boundary.for(0))
|
173
173
|
else
|
174
174
|
raise 'error detecting stage'
|
175
175
|
end
|
data/lib/sqed/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Yoder
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-08-
|
12
|
+
date: 2017-08-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|