Ejemplo n.º 1
0
def get_window_areas():
    mapping = {
        "score": config["calibration.pct.score"],
        "lines": config["calibration.pct.lines"],
        "level": config["calibration.pct.level"],
        "field": config["calibration.pct.field"],
        "black_n_white": config["calibration.pct.black_n_white"],
        "stats2": config.stats2_percentages,
        "preview": config["calibration.pct.preview"],
        "flash": config["calibration.pct.flash"],
        # das trainer
        "current_piece": config["calibration.pct.das.current_piece"],
        "current_piece_das": config["calibration.pct.das.current_piece_das"],
        "instant_das": config["calibration.pct.das.instant_das"],
    }

    base_map = {
        key: xywh_to_ltrb(mult_rect(config["calibration.game_coords"], value))
        for key, value in mapping.items()
    }

    # stats are handled in a special manner
    base_map["stats"] = {
        piece: xywh_to_ltrb(coords)
        for (piece, coords) in generate_stats(
            config["calibration.game_coords"],
            config["calibration.pct.stats"],
            config["calibration.pct.score"][3],
        ).items()
    }

    # calibration of the color blocks include the edges (black),
    # and some of the "shine" white pixels
    # For the stats pieces, the color is in the lower-right quadrant of the piece block
    for color in ("color1", "color2"):
        x, y, w, h = mult_rect(config["calibration.game_coords"],
                               config["calibration.pct." + color])

        xywh = (
            x + floor(w * 0.5),
            y + floor(h * 0.5),
            ceil(w * 0.4),
            ceil(h * 0.4),
        )

        base_map[color] = xywh_to_ltrb(xywh)

    return base_map
Ejemplo n.º 2
0
def captureArea(coords=None):
    _, image = capture.get_image(rgb=True)

    if not coords:
        return image

    return image.crop(xywh_to_ltrb(coords))
Ejemplo n.º 3
0
def captureArea(coords=None, image=None):
    if image is None:
        _, image = uncached_capture().get_image(rgb=True)

    if not coords:
        return image

    return image.crop(xywh_to_ltrb(coords))
Ejemplo n.º 4
0
    def get_image(self, rgb: bool = False) -> Tuple[float, Image.Image]:
        if not self.cv2_retval:
            raise Exception("Faulty capturing device")

        with self.read_lock:
            cv2_image = self.frame_buffer.popleft()

        if rgb:
            cv2_image = cv2.cvtColor(cv2_image, cv2.COLOR_BGR2RGB)

        image = Image.fromarray(cv2_image).crop(xywh_to_ltrb(self.xywh_box))

        return 0.0, image
Ejemplo n.º 5
0
    def get_image(self, rgb: bool = False) -> Tuple[float, Image.Image]:
        self.cur_frame += 1
        cv2_retval, cv2_image = self.cap.read()

        if not cv2_retval:
            return None, None

        if rgb:
            cv2_image = cv2.cvtColor(cv2_image, cv2.COLOR_BGR2RGB)

        image = Image.fromarray(cv2_image).crop(xywh_to_ltrb(self.xywh_box))
        ts = self.cur_frame * self.frame_duration

        return ts, image
Ejemplo n.º 6
0
 def get_image(self, rgb: bool = False) -> Tuple[float, Image.Image]:
     return time.time(), self.source_img.crop(xywh_to_ltrb(self.xywh_box))