module Mork

Constants

VERSION

Public Instance Methods

barcode_threshold() click to toggle source
# File lib/mork/mimage.rb, line 142
def barcode_threshold
  @barcode_threshold ||= (paper_white + ink_black) / 2
end
cal_cell_mean() click to toggle source
# File lib/mork/mimage.rb, line 137
def cal_cell_mean
  m = @grom.calibration_cell_areas.map { |c| reg_pixels.average c }
  m.inject(:+) / m.length.to_f
end
choice_cell_areas(cells) click to toggle source
# File lib/mork/mimage.rb, line 116
def choice_cell_areas(cells)
  if cells.length > @grom.max_questions
    fail ArgumentError, 'Maximum number of responses exceeded'
  end
  if cells.any? { |q| q.any? { |c| c >= @grom.max_choices_per_question } }
    fail ArgumentError, 'Maximum number of choices exceeded'
  end
  itemator(cells) { |q,c| @grom.choice_cell_area q, c }.flatten
end
choice_threshold() click to toggle source
# File lib/mork/mimage.rb, line 130
def choice_threshold
  @choice_threshold ||= begin
    dcm = choice_mean_darkness.flatten.min
    (cal_cell_mean-dcm) * @grom.choice_threshold + dcm
  end
end
each_corner() { |c| ... } click to toggle source
# File lib/mork/mimage.rb, line 126
def each_corner
  [:tl, :tr, :br, :bl].each { |c| yield c }
end
ink_black() click to toggle source
# File lib/mork/mimage.rb, line 146
def ink_black
  reg_pixels.average @grom.ink_black_area
end
paper_white() click to toggle source
# File lib/mork/mimage.rb, line 150
def paper_white
  reg_pixels.average @grom.paper_white_area
end
reg_pixels() click to toggle source
# File lib/mork/mimage.rb, line 154
def reg_pixels
  @reg_pixels ||= NPatch.new @mack.registered_bytes(@rm), @mack.width, @mack.height
end
register() click to toggle source

find the XY coordinates of the 4 registration marks, plus the stdev of the search area as quality control

# File lib/mork/mimage.rb, line 160
def register
  each_corner { |c| @rm[c] = rm_centroid_on c }
  @rm.all? { |k,v| v[:status] == :ok }
end
rm_centroid_on(corner) click to toggle source

returns the centroid of the dark region within the given area in the XY coordinates of the entire image

# File lib/mork/mimage.rb, line 167
def rm_centroid_on(corner)
  c = @grom.rm_crop_area(corner)
  p = @mack.rm_patch(c, @grom.rm_blur, @grom.rm_dilate)
  # byebug
  n = NPatch.new(p, c.w, c.h)
  cx, cy, sd = n.centroid
  st = (cx < 2) or (cy < 2) or (cy > c.h-2) or (cx > c.w-2)
  status = st ? :edgy : :ok
  return {x: cx+c.x, y: cy+c.y, sd: sd, status: status}
end