| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- # This Python file uses the following encoding: utf-8
- # @author runhey
- # github https://github.com/runhey
- import numpy as np
- from module.base.decorator import cached_property
- from module.logger import logger
- class RuleClick:
- def __init__(self, roi_front: tuple, roi_back: tuple) -> None:
- """
- 初始化
- :param roi_front:
- :param roi_back:
- """
- self.roi_front = roi_front
- self.roi_back = roi_back
- def coord(self) -> tuple:
- """
- 获取坐标, 从roi_front随机获取坐标
- :return:
- """
- x, y, w, h = self.roi_front
- x = np.random.randint(x, x + w)
- y = np.random.randint(y, y + h)
- return x, y
- def coord_more(self) -> tuple:
- """
- 从roi_back随机获取坐标
- :return:
- """
- x, y, w, h = self.roi_back
- x = np.random.randint(x, x + w)
- y = np.random.randint(y, y + h)
- return x, y
- @property
- def center(self) -> tuple:
- """
- 返回roi_front的中心坐标
- :return:
- """
- x, y, w, h = self.roi_front
- return x + w // 2, y + h // 2
- def move(self, x: int, y: int) -> None:
- """
- 移动roi_front, 需要限幅x是0-1280, y是0-720
- :param x:
- :param y:
- :return:
- """
- x, y, w, h = self.roi_front
- x += x
- y += y
- if x <= 0 :
- x = 0
- elif x >= 1280:
- x = 1280
- if y <= 0 :
- y = 0
- elif y >= 720:
- y = 720
- self.roi_front = x, y, w, h
|