def _handle_orientated_image(self, image): """ Args: image (np.ndarray): Returns: np.ndarray: """ width, height = image_size(self.image) if width == 1280 and height == 720: return image # Rotate screenshots only when they're not 1280x720 if self.orientation == 0: pass elif self.orientation == 1: image = cv2.rotate(image, cv2.ROTATE_90_COUNTERCLOCKWISE) elif self.orientation == 2: image = cv2.rotate(image, cv2.ROTATE_180) elif self.orientation == 3: image = cv2.rotate(image, cv2.ROTATE_90_CLOCKWISE) else: raise ScriptError( f'Invalid device orientation: {self.orientation}') return image
def check_screen_size(self): """ Screen size must be 1280x720. Take a screenshot before call. """ if self._screen_size_checked: return True orientated = False for _ in range(2): # Check screen size width, height = image_size(self.image) logger.attr('Screen_size', f'{width}x{height}') if width == 1280 and height == 720: self._screen_size_checked = True return True elif not orientated and (width == 720 and height == 1280): logger.info('Received orientated screenshot, handling') self.get_orientation() self.image = self._handle_orientated_image(self.image) orientated = True continue elif self.config.Emulator_Serial == 'wsa-0': self.display_resize_wsa(0) return False elif hasattr(self, 'app_is_running') and not self.app_is_running(): logger.warning( 'Received orientated screenshot, game not running') return True else: logger.critical(f'Resolution not supported: {width}x{height}') logger.critical('Please set emulator resolution to 1280x720') raise RequestHumanTakeover
def _extract(image, file): size = image_size(image) if size != (1280, 720): logger.warning(f'{file} has wrong resolution: {size}') bbox = get_bbox(image) mean = get_color(image=image, area=bbox) mean = tuple(np.rint(mean).astype(int)) return bbox, mean
def unpack(image): """ Split images vertically. Args: image: Returns: list: List of np.ndarray. """ size = image_size(image) if size == (1280, 720): return [image] else: if size[0] != 1280 or size[1] % 720 != 0: raise ImageError(f'Unexpected image size: {size}') return [crop(image, (0, n * 720, 1280, (n + 1) * 720)) for n in range(size[1] // 720)]