refactor: module structure

This commit is contained in:
283375 2023-10-10 01:30:12 +08:00
parent d13076c667
commit 6a19ead8d1
Signed by: 283375
SSH Key Fingerprint: SHA256:UcX0qg6ZOSDOeieKPGokA5h7soykG61nz2uxuQgVLSk
3 changed files with 11 additions and 10 deletions

View File

@ -7,7 +7,7 @@ from PIL import Image
from ....crop import crop_xywh from ....crop import crop_xywh
from ....ocr import FixRects, ocr_digits_by_contour_knn, preprocess_hog 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 ....types import Mat, cv2_ml_KNearest
from ....utils import construct_int_xywh_rect from ....utils import construct_int_xywh_rect
from ...shared import B30OcrResultItem from ...shared import B30OcrResultItem
@ -20,7 +20,7 @@ class ChieriBotV4Ocr:
self, self,
score_knn: cv2_ml_KNearest, score_knn: cv2_ml_KNearest,
pfl_knn: cv2_ml_KNearest, pfl_knn: cv2_ml_KNearest,
phash_db: ImagePHashDatabase, phash_db: ImagePhashDatabase,
factor: Optional[float] = 1.0, factor: Optional[float] = 1.0,
): ):
self.__score_knn = score_knn self.__score_knn = score_knn
@ -49,7 +49,7 @@ class ChieriBotV4Ocr:
return self.__phash_db return self.__phash_db
@phash_db.setter @phash_db.setter
def phash_db(self, phash_db: ImagePHashDatabase): def phash_db(self, phash_db: ImagePhashDatabase):
self.__phash_db = phash_db self.__phash_db = phash_db
@property @property

View File

@ -10,18 +10,19 @@ from ..ocr import (
preprocess_hog, preprocess_hog,
resize_fill_square, resize_fill_square,
) )
from ..phash_db import ImagePHashDatabase from ..phash_db import ImagePhashDatabase
from .roi.extractor import DeviceRoiExtractor from .common import DeviceOcrResult
from .roi.masker import DeviceRoiMasker from .rois.extractor import DeviceRoisExtractor
from .rois.masker import DeviceRoisMasker
class DeviceOcr: class DeviceOcr:
def __init__( def __init__(
self, self,
extractor: DeviceRoiExtractor, extractor: DeviceRoisExtractor,
masker: DeviceRoiMasker, masker: DeviceRoisMasker,
knn_model: cv2.ml.KNearest, knn_model: cv2.ml.KNearest,
phash_db: ImagePHashDatabase, phash_db: ImagePhashDatabase,
): ):
self.extractor = extractor self.extractor = extractor
self.masker = masker self.masker = masker

View File

@ -35,7 +35,7 @@ def hamming_distance_sql_function(user_input, db_entry) -> int:
) )
class ImagePHashDatabase: class ImagePhashDatabase:
def __init__(self, db_path: str): def __init__(self, db_path: str):
with sqlite3.connect(db_path) as conn: with sqlite3.connect(db_path) as conn:
self.hash_size = int( self.hash_size = int(