Class: Mork::SheetOMR
- Inherits:
-
Object
- Object
- Mork::SheetOMR
- Defined in:
- lib/mork/sheet_omr.rb
Overview
Optical mark recognition of a response sheet that was: 1) generated with SheetPDF, 2) printed on plain paper, 3) filled out by a responder, and 4) acquired as a image file.
The sheet is automatically registered upon object creation, after which it is possible to perform queries, as well as save a copy of the scanned image with various overlays superimposed, highlighting the expected correc choices, the actually marked ones, etc.
Instance Method Summary collapse
-
#barcode ⇒ Integer
Sheet barcode as an integer.
-
#barcode_string ⇒ String
Sheet barcode as a binary-like string.
-
#initialize(path, layout = nil) ⇒ SheetOMR
constructor
A new instance of SheetOMR.
- #low_contrast? ⇒ Boolean
-
#marked?(question, choice) ⇒ Boolean
True if the specified question/choice cell has been marked.
-
#marked_choices ⇒ Array
The set of choice indices marked on the response sheet.
-
#marked_choices_unique ⇒ Array
The set of choice indices marked on the response sheet.
-
#marked_letters ⇒ Array
The set of letters marked on the response sheet.
-
#marked_letters_unique ⇒ Array
The set of letters marked on the response sheet.
-
#overlay(what, where = :marked) ⇒ Object
Apply an overlay on the image.
-
#save(fname) ⇒ Object
Saves a copy of the source image after registration; the output image will also contain any previously applied overlays.
-
#save_registration(fname) ⇒ Object
Saves a copy of the original image with overlays showing the crop areas used to localize the registration marks and the detected registration mark centers.
-
#set_choices(choices) ⇒ Boolean
Setting the choices/questions to analyze.
-
#status ⇒ Hash
Registration status for each of the four corners.
-
#valid? ⇒ Boolean
True if sheet registration completed successfully.
Constructor Details
#initialize(path, layout = nil) ⇒ SheetOMR
Returns a new instance of SheetOMR.
20 21 22 23 |
# File 'lib/mork/sheet_omr.rb', line 20 def initialize(path, layout=nil) grom = GridOMR.new layout @mim = Mimage.new path, grom end |
Instance Method Details
#barcode ⇒ Integer
Sheet barcode as an integer
48 49 50 51 |
# File 'lib/mork/sheet_omr.rb', line 48 def return if not_registered .to_i(2) end |
#barcode_string ⇒ String
Sheet barcode as a binary-like string
57 58 59 60 61 62 |
# File 'lib/mork/sheet_omr.rb', line 57 def return if not_registered @mim..map do |b| b ? '1' : '0' end.join.reverse end |
#low_contrast? ⇒ Boolean
32 33 34 |
# File 'lib/mork/sheet_omr.rb', line 32 def low_contrast? @mim.low_contrast? end |
#marked?(question, choice) ⇒ Boolean
True if the specified question/choice cell has been marked
93 94 95 96 |
# File 'lib/mork/sheet_omr.rb', line 93 def marked?(question, choice) return if not_registered marked_choices[question].find {|x| x==choice} ? true : false end |
#marked_choices ⇒ Array
The set of choice indices marked on the response sheet
106 107 108 109 |
# File 'lib/mork/sheet_omr.rb', line 106 def marked_choices return if not_registered @mim.marked end |
#marked_choices_unique ⇒ Array
The set of choice indices marked on the response sheet. If more than one choice was marked for a question, the response is regarded as invalid and treated as if it had been left blank.
117 118 119 120 121 122 |
# File 'lib/mork/sheet_omr.rb', line 117 def marked_choices_unique return if not_registered marked_choices.map do |c| c.length == 1 ? c.first : nil end end |
#marked_letters ⇒ Array
The set of letters marked on the response sheet. At this time, only the latin sequence 'A, B, C...' is supported.
129 130 131 132 133 134 |
# File 'lib/mork/sheet_omr.rb', line 129 def marked_letters return if not_registered marked_choices.map do |q| q.map { |cho| (65+cho).chr } end end |
#marked_letters_unique ⇒ Array
The set of letters marked on the response sheet. At this time, only the latin sequence 'A, B, C...' is supported. If more than one choice was marked for an item, the response is regarded as invalid and treated as if it had been left blank.
142 143 144 145 146 147 |
# File 'lib/mork/sheet_omr.rb', line 142 def marked_letters_unique return if not_registered marked_choices_unique.map do |c| c.nil?? '' : (65+c).chr end end |
#overlay(what, where = :marked) ⇒ Object
Apply an overlay on the image
161 162 163 164 |
# File 'lib/mork/sheet_omr.rb', line 161 def (what, where=:marked) return if not_registered @mim. what, where end |
#save(fname) ⇒ Object
Saves a copy of the source image after registration; the output image will also contain any previously applied overlays.
171 172 173 174 |
# File 'lib/mork/sheet_omr.rb', line 171 def save(fname) return if not_registered @mim.save(fname, true) end |
#save_registration(fname) ⇒ Object
Saves a copy of the original image with overlays showing the crop areas used to localize the registration marks and the detected registration mark centers.
182 183 184 |
# File 'lib/mork/sheet_omr.rb', line 182 def save_registration(fname) @mim.save_registration fname end |
#set_choices(choices) ⇒ Boolean
Setting the choices/questions to analyze. If this function is not called, the maximum number of choices/questions allowed by the layout will be evaluated.
78 79 80 81 82 83 84 85 86 |
# File 'lib/mork/sheet_omr.rb', line 78 def set_choices(choices) return false unless valid? @mim.set_ch case choices when Integer; @mim.choxq[0...choices] when Array; choices else fail ArgumentError, 'Invalid choice set' end true end |
#status ⇒ Hash
Registration status for each of the four corners
41 42 43 |
# File 'lib/mork/sheet_omr.rb', line 41 def status @mim.status end |
#valid? ⇒ Boolean
True if sheet registration completed successfully
28 29 30 |
# File 'lib/mork/sheet_omr.rb', line 28 def valid? @mim.valid? end |