Пример #1
0
    def predict_port_outside(self, image):
        """
        Args:
            image: Screenshot.

        Returns:
            np.ndarray: Coordinate of the center of port icon, relative to radar center.
                Such as [57.70732954 50.89636818].
        """
        radius = (15, 82)
        image = crop(
            image,
            area_offset((-radius[1], -radius[1], radius[1], radius[1]),
                        self.center))
        # image.show()
        points = np.where(
            color_similarity_2d(image, color=(255, 255, 255)) > 250)
        points = np.array(points).T[:, ::-1] - (radius[1], radius[1])
        distance = np.linalg.norm(points, axis=1)
        points = points[np.all([distance < radius[1], distance > radius[0]],
                               axis=0)]
        point = fit_points(points, mod=(1000, 1000), encourage=5)
        point[point > 500] -= 1000
        self.port_loca = point
        return point
Пример #2
0
    def image_color_button(self,
                           area,
                           color,
                           color_threshold=250,
                           encourage=5,
                           name='COLOR_BUTTON'):
        """
        Find an area with pure color on image, convert into a Button.

        Args:
            area (tuple[int]): Area to search from
            color (tuple[int]): Target color
            color_threshold (int): 0-255, 255 means exact match
            encourage (int): Radius of button
            name (str): Name of the button

        Returns:
            Button: Or None if nothing matched.
        """
        image = color_similarity_2d(self.image_crop(area), color=color)
        points = np.array(np.where(image > color_threshold)).T[:, ::-1]
        if points.shape[0] < encourage**2:
            # Not having enough pixels to match
            return None

        point = fit_points(points, mod=image_size(image), encourage=encourage)
        point = ensure_int(point + area[:2])
        button_area = area_offset(
            (-encourage, -encourage, encourage, encourage), offset=point)
        color = get_color(self.device.image, button_area)
        return Button(area=button_area,
                      color=color,
                      button=button_area,
                      name=name)
Пример #3
0
    def get_mission_zone(self):
        """
        Returns:
            Zone:
        """
        area = (341, 72, 1217, 648)
        # Points of the yellow `!`
        image = color_similarity_2d(self.image_area(area), color=(255, 207, 66))
        points = np.array(np.where(image > 235)).T[:, ::-1]
        if not len(points):
            logger.warning('Unable to find mission on OS mission map')

        point = fit_points(points, mod=(1000, 1000), encourage=5) + (0, 11)
        # Location of zone.
        # (2570, 1694) is the shape of os_globe_map.png
        point *= np.array(GLOBE_MAP_SHAPE) / np.subtract(area[2:], area[:2])

        zone = self.camera_to_zone(tuple(point))
        return zone