ruby_marks 0.2.7 → 0.2.8
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.
- data/README.md +38 -15
- data/lib/ruby_marks/config.rb +5 -4
- data/lib/ruby_marks/group.rb +5 -1
- data/lib/ruby_marks/recognizer.rb +5 -4
- data/lib/ruby_marks/version.rb +1 -1
- data/lib/ruby_marks.rb +5 -2
- metadata +6 -6
data/README.md
CHANGED
@@ -162,8 +162,7 @@ flagged_document = recognizer.flag_all_marks
|
|
162
162
|
flagged_document.write(temp_filename)
|
163
163
|
```
|
164
164
|
|
165
|
-
Will return the image below
|
166
|
-
each mark position in a red cross:
|
165
|
+
Will return the image below:
|
167
166
|
|
168
167
|
[](https://github.com/andrerpbts/ruby_marks/blob/master/assets/sheet_demo2_flagged.png)
|
169
168
|
|
@@ -252,7 +251,7 @@ config.threshold_level = 60
|
|
252
251
|
# Sets a timeout in seconds, to break long time scans.
|
253
252
|
# The default value is 0 (zero) and means there's no timeout. Any value will quit the scan and raise timed_out_watcher
|
254
253
|
|
255
|
-
config.
|
254
|
+
config.scan_timeout = 0
|
256
255
|
```
|
257
256
|
|
258
257
|
### Expected lines
|
@@ -265,6 +264,22 @@ config.scan_timeou = 0
|
|
265
264
|
config.default_expected_lines = 20
|
266
265
|
```
|
267
266
|
|
267
|
+
|
268
|
+
### Default blocks sizes tolerances
|
269
|
+
|
270
|
+
```ruby
|
271
|
+
# Defines the tolerance in width and height of the group blocks (in pixels) to compare with de expected block size.
|
272
|
+
# This tolerance is intended to make the scan recognizes the correct whole group. The scanned area + this tolerance
|
273
|
+
# should be greater than the expected sizes of the block, in order to consider it.
|
274
|
+
# In small size groups, you should reduce this parameter in order to don't capture weong groups positions, such a
|
275
|
+
# not marked bubble as a group, for example.
|
276
|
+
# The default values is 100 for both width and height, and should be adjusted for your documents.
|
277
|
+
|
278
|
+
config.default_block_width_tolerance = 100
|
279
|
+
config.default_block_height_tolerance = 100
|
280
|
+
```
|
281
|
+
|
282
|
+
|
268
283
|
### Default mark sizes
|
269
284
|
|
270
285
|
```ruby
|
@@ -280,8 +295,8 @@ config.default_mark_height = 20
|
|
280
295
|
### Default mark sizes tolerances
|
281
296
|
|
282
297
|
```ruby
|
283
|
-
# Defines the tolerance in width and height of the marks (in pixels). With
|
284
|
-
# mark exceeds or stricts those values, it will be ignored.
|
298
|
+
# Defines the tolerance in width and height of the marks (in pixels). With default_mark_width and default_mark_width
|
299
|
+
# size, if the recognized mark exceeds or stricts those values, it will be ignored.
|
285
300
|
# The default values is 4 for both width and height.
|
286
301
|
|
287
302
|
config.default_mark_width_tolerance = 4
|
@@ -321,16 +336,6 @@ config.default_marks_options = %w{A B C D E}
|
|
321
336
|
config.default_distance_between_marks = 25
|
322
337
|
```
|
323
338
|
|
324
|
-
### Adjust bnconsistent bubbles
|
325
|
-
|
326
|
-
```ruby
|
327
|
-
# If true, it will perform an analysis in each group in order to see if there's more or less than expected bubbles,
|
328
|
-
# an will try to remove or add these inconsistent marks.
|
329
|
-
# The default value is true
|
330
|
-
|
331
|
-
config.adjust_inconsistent_bubbles = true
|
332
|
-
```
|
333
|
-
|
334
339
|
|
335
340
|
Group Configuration Options
|
336
341
|
---------------------------
|
@@ -346,6 +351,15 @@ when defining a group. So:
|
|
346
351
|
group.expected_coordinates = {x1: 145, y1: 780, x2: 270, y2: 1290}
|
347
352
|
```
|
348
353
|
|
354
|
+
### Block sizes tolerances
|
355
|
+
|
356
|
+
```ruby
|
357
|
+
# It overwrites the default_block_width_tolerance and default_block_height_tolerance values for the group you configure it.
|
358
|
+
|
359
|
+
group.block_width_tolerance = RubyMarks.default_block_width_tolerance
|
360
|
+
group.block_height_tolerance = RubyMarks.default_block_height_tolerance
|
361
|
+
```
|
362
|
+
|
349
363
|
### Mark sizes
|
350
364
|
|
351
365
|
```ruby
|
@@ -355,6 +369,15 @@ group.mark_width = RubyMarks.default_mark_width
|
|
355
369
|
group.mark_height = RubyMarks.default_mark_height
|
356
370
|
```
|
357
371
|
|
372
|
+
### Mark sizes tolerances
|
373
|
+
|
374
|
+
```ruby
|
375
|
+
# It overwrites the default_mark_width_tolerance and default_mark_height_tolerance values for the group you configure it.
|
376
|
+
|
377
|
+
group.mark_width_tolerance = RubyMarks.default_mark_width_tolerance
|
378
|
+
group.mark_height_tolerance = RubyMarks.default_mark_height_tolerance
|
379
|
+
```
|
380
|
+
|
358
381
|
### Marks options
|
359
382
|
|
360
383
|
```ruby
|
data/lib/ruby_marks/config.rb
CHANGED
@@ -6,8 +6,8 @@ module RubyMarks
|
|
6
6
|
attr_accessor :intensity_percentual, :edge_level, :default_marks_options, :threshold_level,
|
7
7
|
:default_mark_width, :default_mark_height, :scan_timeout,
|
8
8
|
:default_mark_width_tolerance, :default_mark_height_tolerance,
|
9
|
-
:default_distance_between_marks, :
|
10
|
-
:
|
9
|
+
:default_distance_between_marks, :default_expected_lines,
|
10
|
+
:default_block_width_tolerance, :default_block_height_tolerance
|
11
11
|
|
12
12
|
|
13
13
|
def initialize(recognizer)
|
@@ -16,10 +16,11 @@ module RubyMarks
|
|
16
16
|
@edge_level = RubyMarks.edge_level
|
17
17
|
@scan_timeout = RubyMarks.scan_timeout
|
18
18
|
|
19
|
-
@adjust_inconsistent_bubbles = RubyMarks.adjust_inconsistent_bubbles
|
20
|
-
|
21
19
|
@intensity_percentual = RubyMarks.intensity_percentual
|
22
20
|
|
21
|
+
@default_block_width_tolerance = RubyMarks.default_block_width_tolerance
|
22
|
+
@default_block_height_tolerance = RubyMarks.default_block_height_tolerance
|
23
|
+
|
23
24
|
@default_mark_width = RubyMarks.default_mark_width
|
24
25
|
@default_mark_height = RubyMarks.default_mark_height
|
25
26
|
|
data/lib/ruby_marks/group.rb
CHANGED
@@ -4,12 +4,16 @@ module RubyMarks
|
|
4
4
|
class Group
|
5
5
|
attr_reader :label, :recognizer
|
6
6
|
attr_accessor :mark_width, :mark_height, :marks_options, :coordinates, :expected_coordinates,
|
7
|
-
:mark_width_tolerance, :mark_height_tolerance, :marks, :distance_between_marks
|
7
|
+
:mark_width_tolerance, :mark_height_tolerance, :marks, :distance_between_marks,
|
8
|
+
:block_width_tolerance, :block_height_tolerance
|
8
9
|
|
9
10
|
def initialize(label, recognizer)
|
10
11
|
@label = label
|
11
12
|
@recognizer = recognizer
|
12
13
|
|
14
|
+
@block_width_tolerance = @recognizer.config.default_block_width_tolerance
|
15
|
+
@block_height_tolerance = @recognizer.config.default_block_height_tolerance
|
16
|
+
|
13
17
|
@mark_width = @recognizer.config.default_mark_width
|
14
18
|
@mark_height = @recognizer.config.default_mark_height
|
15
19
|
|
@@ -128,7 +128,7 @@ module RubyMarks
|
|
128
128
|
line = 0
|
129
129
|
group_center = RubyMarks::ImageUtils.image_center(group.expected_coordinates)
|
130
130
|
|
131
|
-
block = find_block_marks(file_str, group_center[:x], group_center[:y], group
|
131
|
+
block = find_block_marks(file_str, group_center[:x], group_center[:y], group)
|
132
132
|
if block
|
133
133
|
group.coordinates = {x1: block[:x1], x2: block[:x2], y1: block[:y1], y2: block[:y2]}
|
134
134
|
|
@@ -259,7 +259,8 @@ module RubyMarks
|
|
259
259
|
end
|
260
260
|
|
261
261
|
|
262
|
-
def find_block_marks(image, x, y,
|
262
|
+
def find_block_marks(image, x, y, group)
|
263
|
+
expected_coordinates = group.expected_coordinates
|
263
264
|
found_blocks = []
|
264
265
|
expected_width = RubyMarks::ImageUtils.calc_width(expected_coordinates[:x1], expected_coordinates[:x2])
|
265
266
|
expected_height = RubyMarks::ImageUtils.calc_height(expected_coordinates[:y1], expected_coordinates[:y2])
|
@@ -274,8 +275,8 @@ module RubyMarks
|
|
274
275
|
block[:width] = RubyMarks::ImageUtils.calc_width(block[:x1], block[:x2])
|
275
276
|
block[:height] = RubyMarks::ImageUtils.calc_height(block[:y1], block[:y2])
|
276
277
|
|
277
|
-
block_width_with_tolerance = block[:width] +
|
278
|
-
block_height_with_tolerance = block[:height] +
|
278
|
+
block_width_with_tolerance = block[:width] + group.block_width_tolerance
|
279
|
+
block_height_with_tolerance = block[:height] + group.block_height_tolerance
|
279
280
|
|
280
281
|
|
281
282
|
return block if block_width_with_tolerance >= expected_width &&
|
data/lib/ruby_marks/version.rb
CHANGED
data/lib/ruby_marks.rb
CHANGED
@@ -15,8 +15,11 @@ module RubyMarks
|
|
15
15
|
mattr_accessor :scan_timeout
|
16
16
|
@@scan_timeout = 0
|
17
17
|
|
18
|
-
mattr_accessor :
|
19
|
-
@@
|
18
|
+
mattr_accessor :default_block_width_tolerance
|
19
|
+
@@default_block_width_tolerance = 100
|
20
|
+
|
21
|
+
mattr_accessor :default_block_height_tolerance
|
22
|
+
@@default_block_height_tolerance = 100
|
20
23
|
|
21
24
|
mattr_accessor :default_mark_width_tolerance
|
22
25
|
@@default_mark_width_tolerance = 4
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_marks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -37,14 +37,14 @@ extensions: []
|
|
37
37
|
extra_rdoc_files: []
|
38
38
|
files:
|
39
39
|
- README.md
|
40
|
-
- lib/ruby_marks/group.rb
|
41
|
-
- lib/ruby_marks/watcher.rb
|
42
40
|
- lib/ruby_marks/config.rb
|
43
|
-
- lib/ruby_marks/
|
44
|
-
- lib/ruby_marks/recognizer.rb
|
45
|
-
- lib/ruby_marks/support.rb
|
41
|
+
- lib/ruby_marks/group.rb
|
46
42
|
- lib/ruby_marks/image_utils.rb
|
47
43
|
- lib/ruby_marks/mark.rb
|
44
|
+
- lib/ruby_marks/recognizer.rb
|
45
|
+
- lib/ruby_marks/support.rb
|
46
|
+
- lib/ruby_marks/version.rb
|
47
|
+
- lib/ruby_marks/watcher.rb
|
48
48
|
- lib/ruby_marks.rb
|
49
49
|
- test/ruby_marks/image_utils_test.rb
|
50
50
|
- test/ruby_marks/recognizer_test.rb
|