Module: Sikuli::Searchable
- Included in:
- Region
- Defined in:
- lib/sikuli/searchable.rb
Instance Method Summary collapse
-
#find(filename, similarity = 0.9) ⇒ Object
Public: search for an image within a Region.
-
#find!(filename, similarity = 0.9) ⇒ Object
Public: search for an image within a region (does not raise ImageNotFound exceptions).
-
#find_all(filename, similarity = 0.9) ⇒ Object
Public: search for an image within a Region and return all matches.
-
#wait(filename, time = 2, similarity = 0.9) ⇒ Object
Public: wait for a match to appear within a region.
Instance Method Details
#find(filename, similarity = 0.9) ⇒ Object
Public: search for an image within a Region
filename - A String representation of the filename to match against similarity - A Float between 0 and 1 representing the threshold for matching an image. Passing 1 corresponds to a 100% pixel for pixel match. Defaults to 0.9 (90% match)
Examples
region.find('needle.png')
region.find('needle.png', 0.5)
Returns an instance of Region representing the best match
Throws Sikuli::FileNotFound if the file could not be found on the system Throws Sikuli::ImageNotMatched if no matches are found within the region
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sikuli/searchable.rb', line 24 def find(filename, similarity = 0.9) begin pattern = build_pattern(filename, similarity) match = Region.new(@java_obj.find(pattern)) match.highlight if Sikuli::Config.highlight_on_find match rescue NativeException => e raise_exception e, filename end end |
#find!(filename, similarity = 0.9) ⇒ Object
Public: search for an image within a region (does not raise ImageNotFound exceptions)
filename - A String representation of the filename to match against similarity - A Float between 0 and 1 representing the threshold for matching an image. Passing 1 corresponds to a 100% pixel for pixel match. Defaults to 0.9 (90% match)
Examples
region.find!('needle.png')
region.find!('needle.png', 0.5)
Returns the match or nil if no match is found
48 49 50 51 52 53 54 |
# File 'lib/sikuli/searchable.rb', line 48 def find!(filename, similarity = 0.9) begin find(filename, similarity) rescue Sikuli::ImageNotFound => e nil end end |
#find_all(filename, similarity = 0.9) ⇒ Object
Public: search for an image within a Region and return all matches
TODO: Sort return results so they are always returned in the same order (top left to bottom right)
filename - A String representation of the filename to match against similarity - A Float between 0 and 1 representing the threshold for matching an image. Passing 1 corresponds to a 100% pixel for pixel match. Defaults to 0.9 (90% match)
Examples
region.find_all('needle.png')
region.find_all('needle.png', 0.5)
Returns an array of Region objects that match the given file and threshold
Throws Sikuli::FileNotFound if the file could not be found on the system Throws Sikuli::ImageNotMatched if no matches are found within the region
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/sikuli/searchable.rb', line 76 def find_all(filename, similarity = 0.9) begin pattern = build_pattern(filename, similarity) matches = @java_obj.findAll(pattern) regions = matches.collect do |r| match = Region.new(r) match.highlight if Sikuli::Config.highlight_on_find match end regions rescue NativeException => e raise_exception e, filename end end |
#wait(filename, time = 2, similarity = 0.9) ⇒ Object
Public: wait for a match to appear within a region
filename - A String representation of the filename to match against time - A Fixnum representing the amount of time to wait defaults to 2 seconds similarity - A Float between 0 and 1 representing the threshold for matching an image. Passing 1 corresponds to a 100% pixel for pixel match. Defaults to 0.9 (90% match)
Examples
region.wait('needle.png') # wait for needle.png to appear for up to 1 second
region.wait('needle.png', 10) # wait for needle.png to appear for 10 seconds
Returns nothing
Throws Sikuli::FileNotFound if the file could not be found on the system Throws Sikuli::ImageNotMatched if no matches are found within the region
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/sikuli/searchable.rb', line 109 def wait(filename, time = 2, similarity = 0.9) begin pattern = build_pattern(filename, similarity) match = Region.new(@java_obj.wait(pattern, time)) match.highlight if Sikuli::Config.highlight_on_find match rescue NativeException => e raise_exception e, filename end end |