mirror of
https://github.com/283375/arcaea-offline-ocr.git
synced 2025-07-02 21:06:27 +00:00
wip: split different versions of device
This commit is contained in:
0
src/arcaea_offline_ocr/device/__init__.py
Normal file
0
src/arcaea_offline_ocr/device/__init__.py
Normal file
64
src/arcaea_offline_ocr/device/v1/crop.py
Normal file
64
src/arcaea_offline_ocr/device/v1/crop.py
Normal file
@ -0,0 +1,64 @@
|
||||
from math import floor
|
||||
from typing import Any, Tuple
|
||||
|
||||
from numpy import all, array, count_nonzero
|
||||
|
||||
from ...types import Mat
|
||||
from .definition import Device
|
||||
|
||||
__all__ = [
|
||||
"crop_img",
|
||||
"crop_from_device_attr",
|
||||
"crop_to_pure",
|
||||
"crop_to_far",
|
||||
"crop_to_lost",
|
||||
"crop_to_max_recall",
|
||||
"crop_to_rating_class",
|
||||
"crop_to_score",
|
||||
"crop_to_title",
|
||||
"crop_black_edges",
|
||||
]
|
||||
|
||||
|
||||
def crop_img(img: Mat, *, top: int, left: int, bottom: int, right: int):
|
||||
return img[top:bottom, left:right]
|
||||
|
||||
|
||||
def crop_from_device_attr(img: Mat, rect: Tuple[int, int, int, int]):
|
||||
x, y, w, h = rect
|
||||
return crop_img(img, top=y, left=x, bottom=y + h, right=x + w)
|
||||
|
||||
|
||||
def crop_to_pure(screenshot: Mat, device: Device):
|
||||
return crop_from_device_attr(screenshot, device.pure)
|
||||
|
||||
|
||||
def crop_to_far(screenshot: Mat, device: Device):
|
||||
return crop_from_device_attr(screenshot, device.far)
|
||||
|
||||
|
||||
def crop_to_lost(screenshot: Mat, device: Device):
|
||||
return crop_from_device_attr(screenshot, device.lost)
|
||||
|
||||
|
||||
def crop_to_max_recall(screenshot: Mat, device: Device):
|
||||
return crop_from_device_attr(screenshot, device.max_recall)
|
||||
|
||||
|
||||
def crop_to_rating_class(screenshot: Mat, device: Device):
|
||||
return crop_from_device_attr(screenshot, device.rating_class)
|
||||
|
||||
|
||||
def crop_to_score(screenshot: Mat, device: Device):
|
||||
return crop_from_device_attr(screenshot, device.score)
|
||||
|
||||
|
||||
def crop_to_title(screenshot: Mat, device: Device):
|
||||
return crop_from_device_attr(screenshot, device.title)
|
||||
|
||||
|
||||
def is_black_edge(list_of_pixels: Mat, black_pixel=None):
|
||||
if black_pixel is None:
|
||||
black_pixel = array([0, 0, 0], list_of_pixels.dtype)
|
||||
pixels = list_of_pixels.reshape([-1, 3])
|
||||
return count_nonzero(all(pixels < black_pixel, axis=1)) > floor(len(pixels) * 0.6)
|
37
src/arcaea_offline_ocr/device/v1/definition.py
Normal file
37
src/arcaea_offline_ocr/device/v1/definition.py
Normal file
@ -0,0 +1,37 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Dict, Tuple
|
||||
|
||||
__all__ = ["Device"]
|
||||
|
||||
|
||||
@dataclass(kw_only=True)
|
||||
class Device:
|
||||
version: int
|
||||
uuid: str
|
||||
name: str
|
||||
pure: Tuple[int, int, int, int]
|
||||
far: Tuple[int, int, int, int]
|
||||
lost: Tuple[int, int, int, int]
|
||||
max_recall: Tuple[int, int, int, int]
|
||||
rating_class: Tuple[int, int, int, int]
|
||||
score: Tuple[int, int, int, int]
|
||||
title: Tuple[int, int, int, int]
|
||||
|
||||
@classmethod
|
||||
def from_json_object(cls, json_dict: Dict[str, Any]):
|
||||
if json_dict["version"] == 1:
|
||||
return cls(
|
||||
version=1,
|
||||
uuid=json_dict["uuid"],
|
||||
name=json_dict["name"],
|
||||
pure=json_dict["pure"],
|
||||
far=json_dict["far"],
|
||||
lost=json_dict["lost"],
|
||||
max_recall=json_dict["max_recall"],
|
||||
rating_class=json_dict["rating_class"],
|
||||
score=json_dict["score"],
|
||||
title=json_dict["title"],
|
||||
)
|
||||
|
||||
def repr_info(self):
|
||||
return f"Device(version={self.version}, uuid={repr(self.uuid)}, name={repr(self.name)})"
|
0
src/arcaea_offline_ocr/device/v2/__init__.py
Normal file
0
src/arcaea_offline_ocr/device/v2/__init__.py
Normal file
Reference in New Issue
Block a user