Example #1
0
 def detect_match(self, image, timeout_secs=10, noise_threshold=0.16):
     """
     Generator that yields a sequence of one `MatchResult` for each frame in
     the source video stream.
 
     Returns after `timeout_secs` seconds. (Note that the caller can also choose
     to stop iterating over this function's results at any time.)
 
     `noise_threshold` is a parameter used by the templatematch algorithm.
     Increase `noise_threshold` to avoid false negatives, at the risk of
     increasing false positives (a value of 1.0 will report a match every time).
     """
     if not isinstance(timeout_secs, (int, float, long)):
         raise ScriptApiParamError("detect_match", "timeout_secs", timeout_secs, tuple(int, float, long))
     if not isinstance(noise_threshold, float):
         raise ScriptApiParamError("detect_match", "noise_threshold", noise_threshold, tuple(float))
     params = {"template": findPath(image), "noiseThreshold": noise_threshold}
     self._debugger.debug("Searching for " + params["template"])
     if not os.path.isfile(params["template"]):
         raise UITestError("No such template file: %s" % image)
     for message, buf in self._display.detect("template_match", params, timeout_secs, self.checkAborted):
         self.checkAborted()
         # Discard messages generated from previous call with different template
         if message["template_path"] == params["template"]:
             result = MatchResult(
                 timestamp=buf.timestamp,
                 match=message["match"],
                 position=Position(message["x"], message["y"]),
                 first_pass_result=message["first_pass_result"],
             )
             self._debugger.debug("%s found: %s" % ("Match" if result.match else "Weak match", str(result)))
             yield result
Example #2
0
 def detect_motion(self, timeout_secs=10, noise_threshold=0.84, mask=None):
     """
     Generator that yields a sequence of one `MotionResult` for each frame
     processed from the source video stream.
 
     Returns after `timeout_secs` seconds. (Note that the caller can also choose
     to stop iterating over this function's results at any time.)
 
     `noise_threshold` is a parameter used by the motiondetect algorithm.
     Increase `noise_threshold` to avoid false negatives, at the risk of
     increasing false positives (a value of 0.0 will never report motion).
     This is particularly useful with noisy analogue video sources.
 
     `mask` is a black and white image that specifies which part of the image
     to search for motion. White pixels select the area to search; black pixels
     the area to ignore.
     """
     if not isinstance(timeout_secs, (int, float, long)):
         raise ScriptApiParamError("detect_motion", "timeout_secs",
                                   timeout_secs, tuple(int, float, long))
     self._debugger.debug("Searching for motion")
     params = {
         "enabled": True,
         "noiseThreshold": noise_threshold,
     }
     if mask:
         params["mask"] = findPath(mask)
         self._debugger.debug("Using mask %s" % (params["mask"]))
         if not os.path.isfile(params["mask"]):
             self._debugger.debug("No such mask file: %s" % mask)
             raise UITestError("No such mask file: %s" % mask)
     for msg, buf in self._display.detect("motiondetect", params,
                                          timeout_secs):
         self.checkAborted()
         # Discard messages generated from previous calls with a different mask
         if ((mask and msg["masked"] and msg["mask_path"] == params["mask"])
                 or (not mask and not msg["masked"])):
             result = MotionResult(timestamp=buf.timestamp,
                                   motion=msg["has_motion"])
             self._debugger.debug(
                 "%s detected. Timestamp: %d." %
                 ("Motion" if result.motion else "No motion",
                  result.timestamp))
             yield result
Example #3
0
 def detect_match(self, image, timeout_secs=10, noise_threshold=0.16):
     """
     Generator that yields a sequence of one `MatchResult` for each frame in
     the source video stream.
 
     Returns after `timeout_secs` seconds. (Note that the caller can also choose
     to stop iterating over this function's results at any time.)
 
     `noise_threshold` is a parameter used by the templatematch algorithm.
     Increase `noise_threshold` to avoid false negatives, at the risk of
     increasing false positives (a value of 1.0 will report a match every time).
     """
     if not isinstance(timeout_secs, (int, float, long)):
         raise ScriptApiParamError("detect_match", "timeout_secs",
                                   timeout_secs, tuple(int, float, long))
     if not isinstance(noise_threshold, float):
         raise ScriptApiParamError("detect_match", "noise_threshold",
                                   noise_threshold, tuple(float))
     params = {
         "template": findPath(image),
         "noiseThreshold": noise_threshold,
     }
     self._debugger.debug("Searching for " + params["template"])
     if not os.path.isfile(params["template"]):
         raise UITestError("No such template file: %s" % image)
     for message, buf in self._display.detect("template_match", params,
                                              timeout_secs,
                                              self.checkAborted):
         self.checkAborted()
         # Discard messages generated from previous call with different template
         if message["template_path"] == params["template"]:
             result = MatchResult(
                 timestamp=buf.timestamp,
                 match=message["match"],
                 position=Position(message["x"], message["y"]),
                 first_pass_result=message["first_pass_result"])
             self._debugger.debug(
                 "%s found: %s" %
                 ("Match" if result.match else "Weak match", str(result)))
             yield result
Example #4
0
 def detect_motion(self, timeout_secs=10, noise_threshold=0.84, mask=None):
     """
     Generator that yields a sequence of one `MotionResult` for each frame
     processed from the source video stream.
 
     Returns after `timeout_secs` seconds. (Note that the caller can also choose
     to stop iterating over this function's results at any time.)
 
     `noise_threshold` is a parameter used by the motiondetect algorithm.
     Increase `noise_threshold` to avoid false negatives, at the risk of
     increasing false positives (a value of 0.0 will never report motion).
     This is particularly useful with noisy analogue video sources.
 
     `mask` is a black and white image that specifies which part of the image
     to search for motion. White pixels select the area to search; black pixels
     the area to ignore.
     """
     if not isinstance(timeout_secs, (int, float, long)):
         raise ScriptApiParamError("detect_motion", "timeout_secs", timeout_secs, tuple(int, float, long))
     self._debugger.debug("Searching for motion")
     params = {"enabled": True, "noiseThreshold": noise_threshold}
     if mask:
         params["mask"] = findPath(mask)
         self._debugger.debug("Using mask %s" % (params["mask"]))
         if not os.path.isfile(params["mask"]):
             self._debugger.debug("No such mask file: %s" % mask)
             raise UITestError("No such mask file: %s" % mask)
     for msg, buf in self._display.detect("motiondetect", params, timeout_secs):
         self.checkAborted()
         # Discard messages generated from previous calls with a different mask
         if (mask and msg["masked"] and msg["mask_path"] == params["mask"]) or (not mask and not msg["masked"]):
             result = MotionResult(timestamp=buf.timestamp, motion=msg["has_motion"])
             self._debugger.debug(
                 "%s detected. Timestamp: %d." % ("Motion" if result.motion else "No motion", result.timestamp)
             )
             yield result