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
|