impr: __all__ for modules, style improvements

This commit is contained in:
2023-06-10 18:47:35 +08:00
parent ea31aaf00c
commit b823339986
9 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,6 @@
from .crop import *
from .device import *
from .mask import *
from .ocr import *
from .recognize import *
from .template import *

View File

@ -4,6 +4,18 @@ from cv2 import Mat
from .device 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",
]
def crop_img(img: Mat, *, top: int, left: int, bottom: int, right: int):
return img[top:bottom, left:right]

View File

@ -1,6 +1,8 @@
from dataclasses import dataclass
from typing import Any, Dict, Tuple
__all__ = ["Device"]
@dataclass(kw_only=True)
class Device:

View File

@ -1,6 +1,28 @@
from cv2 import BORDER_CONSTANT, BORDER_ISOLATED, Mat, bitwise_or, dilate, inRange
from numpy import array, uint8
__all__ = [
"GRAY_MIN_HSV",
"GRAY_MAX_HSV",
"WHITE_MIN_HSV",
"WHITE_MAX_HSV",
"PST_MIN_HSV",
"PST_MAX_HSV",
"PRS_MIN_HSV",
"PRS_MAX_HSV",
"FTR_MIN_HSV",
"FTR_MAX_HSV",
"BYD_MIN_HSV",
"BYD_MAX_HSV",
"mask_gray",
"mask_white",
"mask_pst",
"mask_prs",
"mask_ftr",
"mask_byd",
"mask_rating_class",
]
GRAY_MIN_HSV = array([0, 0, 70], uint8)
GRAY_MAX_HSV = array([0, 70, 200], uint8)

View File

@ -11,6 +11,19 @@ from .template import (
matchTemplateMultiple,
)
__all__ = [
"group_numbers",
"FilterDigitResultDict",
"filter_digit_results",
"ocr_digits",
"ocr_pure",
"ocr_far_lost",
"ocr_score",
"ocr_max_recall",
"ocr_rating_class",
"ocr_title",
]
def group_numbers(numbers: List[int], threshold: int) -> List[List[int]]:
"""

View File

@ -8,6 +8,19 @@ from .device import Device
from .mask import *
from .ocr import *
__all__ = [
"process_digits_ocr_img",
"process_tesseract_ocr_img",
"recognize_pure",
"recognize_far_lost",
"recognize_score",
"recognize_max_recall",
"recognize_rating_class",
"recognize_title",
"RecognizeResult",
"recognize",
]
def process_digits_ocr_img(img_hsv_cropped: Mat, mask=Callable[[Mat], Mat]):
img_hsv_cropped = mask(img_hsv_cropped)

View File

@ -32,6 +32,13 @@ from numpy import uint8
from ._builtin_templates import GeoSansLight_Italic, GeoSansLight_Regular
__all__ = [
"load_digit_template",
"load_builtin_digit_template",
"MatchTemplateMultipleResult",
"matchTemplateMultiple",
]
def load_digit_template(filename: str) -> Dict[int, Mat]:
"""