Class: ImageRoi
- Includes:
- CanHaveSpecialMethods
- Defined in:
- lib/roi/image/image_roi.rb
Overview
The ImageRoi class defines an image Roi and its methods
Instance Attribute Summary collapse
-
#img_height ⇒ Object
Returns the value of attribute img_height.
-
#img_width ⇒ Object
Returns the value of attribute img_width.
-
#img_x ⇒ Object
Returns the value of attribute img_x.
-
#img_y ⇒ Object
Returns the value of attribute img_y.
-
#similarity ⇒ Object
Returns the value of attribute similarity.
Attributes inherited from Roi
#height, #name, #ref_img, #width, #x, #y
Instance Method Summary collapse
-
#displayed?(args = {}) ⇒ Boolean
Public: Checks if image is displayed as defined in the given ROI.
-
#info ⇒ Object
Public: Gets image Roi info.
-
#initialize(dut, args = {}) ⇒ ImageRoi
constructor
Public: Initializes an image Roi.
-
#precise_time_to_change(args = {}) ⇒ Object
Public: Measures the precise time for the given image Roi to change.
-
#retrieve(args = {}) ⇒ Object
TODO: come up with a use for this that makes sense in the context of a specific image Roi (area).
-
#time_to_change(args = {}) ⇒ Object
Public: Measures the approximate time for the given image Roi to change.
Methods included from CanHaveSpecialMethods
Methods inherited from Roi
#find_frame_displayed, #find_frame_not_displayed, #precise_time_to_disappear, #precise_time_to_display, #precise_time_to_match_dut, #precise_time_to_transition, #press_key_until_displayed?, #rectangle, #rectangle=, #time_to_disappear, #time_to_display, #time_to_transition, #wait_for_change?, #wait_for_transition?, #wait_until_displayed?, #wait_until_not_displayed?
Constructor Details
#initialize(dut, args = {}) ⇒ ImageRoi
Public: Initializes an image Roi.
dut - Platform (or subclass) instance to which this Roi belongs. x - Integer x coordinate (default: nil). y - Integer y coordinate (default: nil). width - Integer width (default: nil). height - Integer height (default: nil). rectangle - Hash defining rectangle with keys :x, :y, :width, :height (default: nil). element - Hash same as rectangle (default: nil). img_x - Integer secondary Roi x coordinate (default: nil). Required. img_y - Integer secondary Roi y coordinate (default: nil). Required. img_width - Integer secondary Roi width (default: nil). Required. img_height - Integer secondary Roi height (default: nil). Required. ref_img - String path to reference image (default: nil). Required. similarity - Integer image similarity threshold 0 - 100 (default: 80).
Returns nothing.
28 29 30 31 32 33 34 35 36 |
# File 'lib/roi/image/image_roi.rb', line 28 def initialize(dut, args={}) args.fetch(:ref_img) # required super(dut, args) @img_x = args.fetch(:img_x) @img_y = args.fetch(:img_y) @img_width = args.fetch(:img_width) @img_height = args.fetch(:img_height) @similarity = args.fetch(:similarity, 80) end |
Instance Attribute Details
#img_height ⇒ Object
Returns the value of attribute img_height.
9 10 11 |
# File 'lib/roi/image/image_roi.rb', line 9 def img_height @img_height end |
#img_width ⇒ Object
Returns the value of attribute img_width.
9 10 11 |
# File 'lib/roi/image/image_roi.rb', line 9 def img_width @img_width end |
#img_x ⇒ Object
Returns the value of attribute img_x.
9 10 11 |
# File 'lib/roi/image/image_roi.rb', line 9 def img_x @img_x end |
#img_y ⇒ Object
Returns the value of attribute img_y.
9 10 11 |
# File 'lib/roi/image/image_roi.rb', line 9 def img_y @img_y end |
#similarity ⇒ Object
Returns the value of attribute similarity.
9 10 11 |
# File 'lib/roi/image/image_roi.rb', line 9 def similarity @similarity end |
Instance Method Details
#displayed?(args = {}) ⇒ Boolean
Public: Checks if image is displayed as defined in the given ROI.
Corresponds to: api_is_image_area_displayed??
key - String name of key to press to trigger evaluation (default: nil).
If default, no keys will be pressed.
delay - Integer total milliseconds to delay before starting evaluation (default: 0). timeout - Integer total milliseconds to allow before timing out (default: 0). scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false). verifies_for - Integer total milliseconds for which the ROI must verify in order to succeed (default: 0).
If default, the ROI must only verify once.
priority - Symbol representing evaluation priority used to throttle CPU usage (default: :normal):
:critical - Sleep 10 milliseconds between intensive tasks (should be used sparingly).
:high - Sleep 100 milliseconds between intensive tasks.
:normal - Sleep 1 second between intensive tasks (default).
:low - Sleep 10 seconds between intensive tasks.
:background - Sleep 1 minute between intensive tasks (should be used sparingly).
log_every - Integer interval in milliseconds between logs (default: 1000). ref_img - String path to reference image to override the one in the Roi (default: nil).
Returns a Boolean true if image is displayed before the timeout, otherwise false.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/roi/image/image_roi.rb', line 65 def displayed?(args={}) logger.info('Checking if image area is displayed') scale = args.fetch(:scale, false) frame = args[:frame] ref_img_json = ref_img_roi_to_json(ref_img: args[:ref_img]) verify(args) do if frame.nil? right_roi = to_json json = get_json_for_match_2(ref_img_json, right_roi, scale: scale) result = test_case.send(:tmc_post, "/api/roi/image/actions/#{dut.slot}", json: json)['value'] logger.roi(self, args.merge(message: "Image is#{result ? '' : ' not'} displayed on screen", use_last_image: true)) else right_roi = to_json(ref_img: frame) json = get_json_for_match_2(ref_img_json, right_roi, scale: scale) result = test_case.send(:tmc_post, '/api/roi/image/actions', json: json)['value'] logger.roi(self, args.merge(message: "Image is#{result ? '' : ' not'} displayed in frame", screenshot: false)) end result end end |
#info ⇒ Object
Public: Gets image Roi info.
Returns a tidy String with image Roi info.
41 42 43 |
# File 'lib/roi/image/image_roi.rb', line 41 def info "#{super} Img.X=#{@img_x} Img.Y=#{@img_y} Img.Width=#{@img_width} Img.Height=#{@img_height} Similarity=#{@similarity}" end |
#precise_time_to_change(args = {}) ⇒ Object
Public: Measures the precise time for the given image Roi to change.
Corresponds to: api_hp_time_for_screen_to_change
key - String key press to trigger evaluation (default: nil).
If default, no key will be pressed.
delay - Integer total milliseconds to delay before starting evaluation (default: 0). timeout - Integer total milliseconds to allow before timing out (default: nil).
If default, timeout will be calculated as [ delay + 5000 ].
scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false). priority - Symbol evaluation priority used to throttle CPU usage (default: :normal):
:critical - Sleep 10 ms between intensive tasks (USE SPARINGLY)
:high - Sleep 100 ms between intensive tasks
:normal - Sleep 1 second between intensive tasks
:low - Sleep 10 seconds between intensive tasks
:background - Sleep 1 minute between intensive tasks (USE SPARINGLY)
log_every - Integer total milliseconds between logs (default: 1000). report - Boolean indicating whether to report measurements to ITMS (default: true).
Returns the Float total milliseconds for the image Roi to change.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/roi/image/image_roi.rb', line 148 def precise_time_to_change(args={}) logger.info('Measuring precise time for image to change') args[:precise] = true scale = args.fetch(:scale, false) values = [] measure(args, values) do |frame, frames| roi = to_json(ref_img: frame) if frames.empty? frames << frame result = false #TODO: do we need to implement this? logger.roi(self, args.merge(message: "Image #{result ? 'changed' : 'did not change'} on screen", use_last_image: true)) else json = get_json_for_match_2(roi, roi, scale: scale) resp = test_case.send(:tmc_post, '/api/roi/image/actions', json: json) result = !resp['value'] logger.roi(self, args.merge(message: "Image #{result ? 'changed' : 'did not change'} in frame", screenshot: false)) end result end end |
#retrieve(args = {}) ⇒ Object
TODO: come up with a use for this that makes sense in the context of a specific image Roi (area)
89 90 91 92 |
# File 'lib/roi/image/image_roi.rb', line 89 def retrieve(args={}) logger.info('Retrieving image area') raise 'ImageRoi retrieve not implemented! Did you mean dut.capture_screen?' end |
#time_to_change(args = {}) ⇒ Object
Public: Measures the approximate time for the given image Roi to change.
Corresponds to: api_time_for_screen_to_change
key - String key press to trigger evaluation (default: nil).
If default, no key will be pressed.
delay - Integer total milliseconds to delay before starting evaluation (default: 0). timeout - Integer total milliseconds to allow before timing out (default: nil).
If default, timeout will be calculated as [ delay + 5000 ].
scale - Boolean if the larger image should be scaled to the size of the smaller image (default: false). priority - Symbol evaluation priority used to throttle CPU usage (default: :normal):
:critical - Sleep 10 ms between intensive tasks (USE SPARINGLY)
:high - Sleep 100 ms between intensive tasks
:normal - Sleep 1 second between intensive tasks
:low - Sleep 10 seconds between intensive tasks
:background - Sleep 1 minute between intensive tasks (USE SPARINGLY)
log_every - Integer total milliseconds between logs (default: 1000). report - Boolean indicating whether to report measurements to ITMS (default: true).
Returns the Float total milliseconds for the image Roi to change.
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/roi/image/image_roi.rb', line 114 def time_to_change(args={}) logger.info('Measuring time for image to change') scale = args.fetch(:scale, false) next_img = dut.capture_screen measure(args) do roi = to_json(ref_img: next_img) json = get_json_for_match_2(roi, roi, scale: scale) resp = test_case.send(:tmc_post, "/api/roi/image/actions/#{dut.id}", json: json) result = !resp['value'] logger.roi(self, args.merge(message: "Image #{result ? 'changed' : 'did not change'}", use_last_image: true)) result end end |