From 6a19ead8d1f8076fa453bb715c10fcd03ffa1ac3 Mon Sep 17 00:00:00 2001 From: 283375 Date: Tue, 10 Oct 2023 01:30:12 +0800 Subject: [PATCH] refactor: module structure --- src/arcaea_offline_ocr/b30/chieri/v4/ocr.py | 6 +++--- src/arcaea_offline_ocr/device/ocr.py | 13 +++++++------ src/arcaea_offline_ocr/phash_db.py | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/arcaea_offline_ocr/b30/chieri/v4/ocr.py b/src/arcaea_offline_ocr/b30/chieri/v4/ocr.py index 07dd434..302b9a5 100644 --- a/src/arcaea_offline_ocr/b30/chieri/v4/ocr.py +++ b/src/arcaea_offline_ocr/b30/chieri/v4/ocr.py @@ -7,7 +7,7 @@ from PIL import Image from ....crop import crop_xywh from ....ocr import FixRects, ocr_digits_by_contour_knn, preprocess_hog -from ....phash_db import ImagePHashDatabase +from ....phash_db import ImagePhashDatabase from ....types import Mat, cv2_ml_KNearest from ....utils import construct_int_xywh_rect from ...shared import B30OcrResultItem @@ -20,7 +20,7 @@ class ChieriBotV4Ocr: self, score_knn: cv2_ml_KNearest, pfl_knn: cv2_ml_KNearest, - phash_db: ImagePHashDatabase, + phash_db: ImagePhashDatabase, factor: Optional[float] = 1.0, ): self.__score_knn = score_knn @@ -49,7 +49,7 @@ class ChieriBotV4Ocr: return self.__phash_db @phash_db.setter - def phash_db(self, phash_db: ImagePHashDatabase): + def phash_db(self, phash_db: ImagePhashDatabase): self.__phash_db = phash_db @property diff --git a/src/arcaea_offline_ocr/device/ocr.py b/src/arcaea_offline_ocr/device/ocr.py index bf5b9a6..7232bcb 100644 --- a/src/arcaea_offline_ocr/device/ocr.py +++ b/src/arcaea_offline_ocr/device/ocr.py @@ -10,18 +10,19 @@ from ..ocr import ( preprocess_hog, resize_fill_square, ) -from ..phash_db import ImagePHashDatabase -from .roi.extractor import DeviceRoiExtractor -from .roi.masker import DeviceRoiMasker +from ..phash_db import ImagePhashDatabase +from .common import DeviceOcrResult +from .rois.extractor import DeviceRoisExtractor +from .rois.masker import DeviceRoisMasker class DeviceOcr: def __init__( self, - extractor: DeviceRoiExtractor, - masker: DeviceRoiMasker, + extractor: DeviceRoisExtractor, + masker: DeviceRoisMasker, knn_model: cv2.ml.KNearest, - phash_db: ImagePHashDatabase, + phash_db: ImagePhashDatabase, ): self.extractor = extractor self.masker = masker diff --git a/src/arcaea_offline_ocr/phash_db.py b/src/arcaea_offline_ocr/phash_db.py index 384b244..a0a406d 100644 --- a/src/arcaea_offline_ocr/phash_db.py +++ b/src/arcaea_offline_ocr/phash_db.py @@ -35,7 +35,7 @@ def hamming_distance_sql_function(user_input, db_entry) -> int: ) -class ImagePHashDatabase: +class ImagePhashDatabase: def __init__(self, db_path: str): with sqlite3.connect(db_path) as conn: self.hash_size = int(