Module: Credo::Calibration

Defined in:
lib/credo/calibration.rb

Class Method Summary collapse

Class Method Details

.calibrate(tests: 300, device_id: 0) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/credo/calibration.rb', line 3

def self.calibrate(tests: 300, device_id: 0)
  puts "Calibration..."
  Framegrabber.open(device_id)
  max_values = tests.times.map do |test_number|
    frame = grab_frame
    print "\r Test no.: #{test_number + 1} / #{tests} "
    print "Max: #{frame.max} "
    print "Average: #{"%.4f" % (frame.sum.to_f / frame.size)} "
    print "Exit ctrl+c"
    sleep 1
    frame.max
  end
  puts
  puts "Calibration completed"
  puts "Maximum value: #{max_values.max}"
  puts "Average of maximum values: #{max_values.sum.to_f / max_values.size}"
ensure
  Framegrabber.release
  "Calibration interrupted"
end

.grab_frameObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/credo/calibration.rb', line 24

def self.grab_frame
  frame = Framegrabber.grab_frame
  frame.shift(10)
  frame.pop(10)
  frame.map! do |row|
    row.shift(10)
    row.pop(10)
    row
  end.flatten
end