Class: Imatcher::Modes::Base
- Inherits:
-
Object
- Object
- Imatcher::Modes::Base
- Includes:
- ColorMethods
- Defined in:
- lib/imatcher/modes/base.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#bounds ⇒ Object
readonly
Returns the value of attribute bounds.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#threshold ⇒ Object
readonly
Returns the value of attribute threshold.
Instance Method Summary collapse
- #compare(a, b) ⇒ Object
- #diff(bg, diff) ⇒ Object
-
#initialize(threshold: 0.0) ⇒ Base
constructor
A new instance of Base.
- #score ⇒ Object
- #update_bounds(x, y) ⇒ Object
- #update_result(*_args, x, y) ⇒ Object
Methods included from ColorMethods
Constructor Details
Instance Attribute Details
#bounds ⇒ Object (readonly)
Returns the value of attribute bounds.
6 7 8 |
# File 'lib/imatcher/modes/base.rb', line 6 def bounds @bounds end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
6 7 8 |
# File 'lib/imatcher/modes/base.rb', line 6 def result @result end |
#threshold ⇒ Object (readonly)
Returns the value of attribute threshold.
6 7 8 |
# File 'lib/imatcher/modes/base.rb', line 6 def threshold @threshold end |
Instance Method Details
#compare(a, b) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/imatcher/modes/base.rb', line 13 def compare(a, b) result.image = a @bounds = [0, 0, result.image.width - 1, result.image.height - 1] b.compare_each_pixel(a) do |b_pixel, a_pixel, x, y| next if pixels_equal?(b_pixel, a_pixel) update_result(b_pixel, a_pixel, x, y) end result.score = score result end |
#diff(bg, diff) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/imatcher/modes/base.rb', line 26 def diff(bg, diff) diff_image = background(bg) diff.each do |pixels_pair| pixels_diff(diff_image, *pixels_pair) end create_diff_image(bg, diff_image).render_bounds(*bounds) end |
#score ⇒ Object
34 35 36 |
# File 'lib/imatcher/modes/base.rb', line 34 def score @result.diff.length.to_f / @result.image.pixels.length end |
#update_bounds(x, y) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/imatcher/modes/base.rb', line 42 def update_bounds(x, y) bounds[0] = [x, bounds[0]].max bounds[1] = [y, bounds[1]].max bounds[2] = [x, bounds[2]].min bounds[3] = [y, bounds[3]].min end |
#update_result(*_args, x, y) ⇒ Object
38 39 40 |
# File 'lib/imatcher/modes/base.rb', line 38 def update_result(*_args, x, y) update_bounds(x, y) end |