Class: VideoRoi
- Includes:
- CanHaveSpecialMethods
- Defined in:
- lib/roi/video/video_roi.rb
Overview
The VideoRoi class defines a video Roi and its methods
Instance Attribute Summary collapse
-
#threshold ⇒ Object
Returns the value of attribute threshold.
Attributes inherited from Roi
#height, #name, #ref_img, #width, #x, #y
Instance Method Summary collapse
-
#displayed?(args = {}) ⇒ Boolean
Public: Checks if motion is detected on the screen as defined in the Roi.
-
#info ⇒ Object
Public: Gets video Roi info.
-
#initialize(dut, args = {}) ⇒ VideoRoi
constructor
Public: Initializes a video Roi.
Methods included from CanHaveSpecialMethods
Methods inherited from Roi
#find_frame_displayed, #find_frame_not_displayed, #precise_time_to_change, #precise_time_to_disappear, #precise_time_to_display, #precise_time_to_match_dut, #precise_time_to_transition, #press_key_until_displayed?, #rectangle, #rectangle=, #retrieve, #time_to_change, #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 = {}) ⇒ VideoRoi
Public: Initializes a video 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). threshold - Float video motion threshold 0.0 - 100.0 (default: 0.1). ref_img - String path to reference image (default: nil).
Returns nothing.
23 24 25 26 |
# File 'lib/roi/video/video_roi.rb', line 23 def initialize(dut, args={}) super(dut, args) self.threshold=(args.fetch(:threshold, 0.1)) # default threshold is 0.1% (0.001) end |
Instance Attribute Details
#threshold ⇒ Object
Returns the value of attribute threshold.
8 9 10 |
# File 'lib/roi/video/video_roi.rb', line 8 def threshold @threshold end |
Instance Method Details
#displayed?(args = {}) ⇒ Boolean
Public: Checks if motion is detected on the screen as defined in the Roi.
Corresponds to:
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). 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).
Returns a Boolean true if motion is detected before the timeout, otherwise false.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/roi/video/video_roi.rb', line 63 def displayed?(args={}) logger.info('Checking if video is playing') frame = args[:frame] last_frame = args[:last_frame] if !frame.nil? && last_frame.nil? return false end verify(args) do if frame.nil? default_timeout = 5.sec video_timeout = args.fetch(:timeout, default_timeout) video_timeout = default_timeout if video_timeout == 0 # video timeout can't be 0 post_timeout = video_timeout + 1.min json = get_json_for_match(roi: to_json.merge(timeout: video_timeout)) result = test_case.send(:tmc_post, "/api/roi/video/actions/#{dut.id}", json: json, timeout: post_timeout)['value'] logger.roi(self, args.merge(message: "Video is#{result ? '' : ' not'} playing on screen", use_last_image: true)) else last_frame = rectangle.merge(:referenceImage => last_frame) this_frame = rectangle.merge(:referenceImage => frame) json = get_json_for_match_2(last_frame, this_frame) result = test_case.send(:tmc_post, '/api/roi/video/actions', json: json)['value'] logger.roi(self, args.merge(message: "Video is#{result ? '' : ' not'} playing in frame", screenshot: false)) end result end end |
#info ⇒ Object
Public: Gets video Roi info.
Returns a tidy String with video Roi info.
41 42 43 |
# File 'lib/roi/video/video_roi.rb', line 41 def info "#{super}; Threshold=#{@threshold}" end |