Module: Credo::Detector
- Defined in:
- lib/credo/detector.rb,
lib/credo/detector/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Attribute Summary collapse
-
#last_ping ⇒ Object
readonly
Returns the value of attribute last_ping.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
Class Method Summary collapse
Instance Attribute Details
#last_ping ⇒ Object (readonly)
Returns the value of attribute last_ping.
8 9 10 |
# File 'lib/credo/detector.rb', line 8 def last_ping @last_ping end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
8 9 10 |
# File 'lib/credo/detector.rb', line 8 def threshold @threshold end |
Class Method Details
.detect(device_id: 0, threshold: 60) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/credo/detector.rb', line 12 def self.detect(device_id: 0, threshold: 60) @last_ping = linux_time @last_detection_time = 0 Framegrabber.open(device_id) sample_number = sample_save = 0 print("Start sampling...") sleep(2) loop do time_dat = DateTime.now.strftime("%Y-%m-%d %H:%M:%S:%f") detection_time = linux_time sample_number += 1 grab_frame! print("\r Sample: #{sample_number} | Saved #{sample_save} | Press Ctrl + c to exit") sleep(0.000001) counter = 0 xy_coordinates = [] flattened = @frame.flatten coords = [] if flattened.any? { |subpixel| subpixel > threshold } @frame.each_with_index do |row, x| row.each_with_index do |pixel, y| coords << [x, y] if pixel.any? { |subpixel| subpixel > threshold } end end end end ensure Framegrabber.release end |