mirror of
https://github.com/283375/arcaea-offline-ocr.git
synced 2025-04-18 13:00:18 +00:00
refactor: prepare for new Sizes
This commit is contained in:
parent
1f4aaf5728
commit
8389586ccd
@ -0,0 +1,4 @@
|
|||||||
|
from .definition import DeviceV2
|
||||||
|
from .ocr import DeviceV2Ocr
|
||||||
|
from .rois import DeviceV2AutoRois, DeviceV2Rois
|
||||||
|
from .shared import MAX_RECALL_CLOSE_KERNEL
|
@ -85,8 +85,8 @@ class DeviceV2Ocr:
|
|||||||
return ocr_digit_samples_knn(samples, self.knn_model)
|
return ocr_digit_samples_knn(samples, self.knn_model)
|
||||||
|
|
||||||
def ocr_song_id(self, rois: DeviceV2Rois):
|
def ocr_song_id(self, rois: DeviceV2Rois):
|
||||||
cover = cv2.cvtColor(rois.cover, cv2.COLOR_BGR2GRAY)
|
jacket = cv2.cvtColor(rois.jacket, cv2.COLOR_BGR2GRAY)
|
||||||
return self.sift_db.lookup_img(cover)[0]
|
return self.sift_db.lookup_img(jacket)[0]
|
||||||
|
|
||||||
def ocr_rating_class(self, rois: DeviceV2Rois):
|
def ocr_rating_class(self, rois: DeviceV2Rois):
|
||||||
roi = cv2.cvtColor(rois.max_recall_rating_class, cv2.COLOR_BGR2HSV)
|
roi = cv2.cvtColor(rois.max_recall_rating_class, cv2.COLOR_BGR2HSV)
|
||||||
|
@ -14,6 +14,87 @@ def apply_factor(num: Union[int, float], factor: float):
|
|||||||
|
|
||||||
|
|
||||||
class Sizes:
|
class Sizes:
|
||||||
|
def __init__(self, factor: float):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def TOP_BAR_HEIGHT(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def SCORE_PANEL(self) -> Tuple[int, int]:
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def PFL_TOP_FROM_VMID(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def PFL_LEFT_FROM_HMID(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def PFL_WIDTH(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def PFL_FONT_PX(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def PURE_FAR_GAP(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def FAR_LOST_GAP(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def SCORE_BOTTOM_FROM_VMID(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def SCORE_FONT_PX(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def SCORE_WIDTH(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def JACKET_RIGHT_FROM_HOR_MID(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def JACKET_WIDTH(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def MR_RT_RIGHT_FROM_HMID(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def MR_RT_WIDTH(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def MR_RT_HEIGHT(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def TITLE_BOTTOM_FROM_VMID(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def TITLE_FONT_PX(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
@property
|
||||||
|
def TITLE_WIDTH_RIGHT(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
class SizesV1(Sizes):
|
||||||
def __init__(self, factor: float):
|
def __init__(self, factor: float):
|
||||||
self.factor = factor
|
self.factor = factor
|
||||||
|
|
||||||
@ -29,11 +110,11 @@ class Sizes:
|
|||||||
return tuple(self.apply_factor(num) for num in [485, 239])
|
return tuple(self.apply_factor(num) for num in [485, 239])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def PFL_TOP_FROM_VER_MID(self):
|
def PFL_TOP_FROM_VMID(self):
|
||||||
return self.apply_factor(135)
|
return self.apply_factor(135)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def PFL_LEFT_FROM_HOR_MID(self):
|
def PFL_LEFT_FROM_HMID(self):
|
||||||
return self.apply_factor(5)
|
return self.apply_factor(5)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -53,7 +134,7 @@ class Sizes:
|
|||||||
return self.apply_factor(10)
|
return self.apply_factor(10)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def SCORE_BOTTOM_FROM_VER_MID(self):
|
def SCORE_BOTTOM_FROM_VMID(self):
|
||||||
return self.apply_factor(-50)
|
return self.apply_factor(-50)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -65,27 +146,27 @@ class Sizes:
|
|||||||
return self.apply_factor(280)
|
return self.apply_factor(280)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def COVER_RIGHT_FROM_HOR_MID(self):
|
def JACKET_RIGHT_FROM_HOR_MID(self):
|
||||||
return self.apply_factor(-235)
|
return self.apply_factor(-235)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def COVER_WIDTH(self):
|
def JACKET_WIDTH(self):
|
||||||
return self.apply_factor(375)
|
return self.apply_factor(375)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def MAX_RECALL_RATING_CLASS_RIGHT_FROM_HOR_MID(self):
|
def MR_RT_RIGHT_FROM_HMID(self):
|
||||||
return self.apply_factor(-300)
|
return self.apply_factor(-300)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def MAX_RECALL_RATING_CLASS_WIDTH(self):
|
def MR_RT_WIDTH(self):
|
||||||
return self.apply_factor(275)
|
return self.apply_factor(275)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def MAX_RECALL_RATING_CLASS_HEIGHT(self):
|
def MR_RT_HEIGHT(self):
|
||||||
return self.apply_factor(75)
|
return self.apply_factor(75)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def TITLE_BOTTOM_FROM_VER_MID(self):
|
def TITLE_BOTTOM_FROM_VMID(self):
|
||||||
return self.apply_factor(-265)
|
return self.apply_factor(-265)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -100,7 +181,7 @@ class Sizes:
|
|||||||
class DeviceV2Rois:
|
class DeviceV2Rois:
|
||||||
def __init__(self, device: DeviceV2, img: Mat):
|
def __init__(self, device: DeviceV2, img: Mat):
|
||||||
self.device = device
|
self.device = device
|
||||||
self.sizes = Sizes(self.device.factor)
|
self.sizes = SizesV1(self.device.factor)
|
||||||
self.__img = img
|
self.__img = img
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -122,7 +203,7 @@ class DeviceV2Rois:
|
|||||||
return self.img.shape[0]
|
return self.img.shape[0]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ver_mid(self):
|
def vmid(self):
|
||||||
return self.h / 2
|
return self.h / 2
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -130,25 +211,25 @@ class DeviceV2Rois:
|
|||||||
return self.img.shape[1]
|
return self.img.shape[1]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hor_mid(self):
|
def hmid(self):
|
||||||
return self.w / 2
|
return self.w / 2
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def h_fixed(self):
|
def h_without_top_bar(self):
|
||||||
"""img_height -= top_bar_height"""
|
"""img_height -= top_bar_height"""
|
||||||
return self.h - self.sizes.TOP_BAR_HEIGHT
|
return self.h - self.sizes.TOP_BAR_HEIGHT
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def h_fixed_mid(self):
|
def h_without_top_bar_mid(self):
|
||||||
return self.sizes.TOP_BAR_HEIGHT + self.h_fixed / 2
|
return self.sizes.TOP_BAR_HEIGHT + self.h_without_top_bar / 2
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pfl_top(self):
|
def pfl_top(self):
|
||||||
return self.h_fixed_mid + self.sizes.PFL_TOP_FROM_VER_MID
|
return self.h_without_top_bar_mid + self.sizes.PFL_TOP_FROM_VMID
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pfl_left(self):
|
def pfl_left(self):
|
||||||
return self.hor_mid + self.sizes.PFL_LEFT_FROM_HOR_MID
|
return self.hmid + self.sizes.PFL_LEFT_FROM_HMID
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pure_rect(self):
|
def pure_rect(self):
|
||||||
@ -197,10 +278,10 @@ class DeviceV2Rois:
|
|||||||
@property
|
@property
|
||||||
def score_rect(self):
|
def score_rect(self):
|
||||||
return self.construct_int_xywh_rect(
|
return self.construct_int_xywh_rect(
|
||||||
x=self.hor_mid - (self.sizes.SCORE_WIDTH / 2),
|
x=self.hmid - (self.sizes.SCORE_WIDTH / 2),
|
||||||
y=(
|
y=(
|
||||||
self.h_fixed_mid
|
self.h_without_top_bar_mid
|
||||||
+ self.sizes.SCORE_BOTTOM_FROM_VER_MID
|
+ self.sizes.SCORE_BOTTOM_FROM_VMID
|
||||||
- self.sizes.SCORE_FONT_PX
|
- self.sizes.SCORE_FONT_PX
|
||||||
),
|
),
|
||||||
w=self.sizes.SCORE_WIDTH,
|
w=self.sizes.SCORE_WIDTH,
|
||||||
@ -214,20 +295,20 @@ class DeviceV2Rois:
|
|||||||
@property
|
@property
|
||||||
def max_recall_rating_class_rect(self):
|
def max_recall_rating_class_rect(self):
|
||||||
x = (
|
x = (
|
||||||
self.hor_mid
|
self.hmid
|
||||||
+ self.sizes.COVER_RIGHT_FROM_HOR_MID
|
+ self.sizes.JACKET_RIGHT_FROM_HOR_MID
|
||||||
- self.sizes.COVER_WIDTH
|
- self.sizes.JACKET_WIDTH
|
||||||
- 25 * self.sizes.factor
|
- 25 * self.sizes.factor
|
||||||
)
|
)
|
||||||
return self.construct_int_xywh_rect(
|
return self.construct_int_xywh_rect(
|
||||||
x=x,
|
x=x,
|
||||||
y=(
|
y=(
|
||||||
self.h_fixed_mid
|
self.h_without_top_bar_mid
|
||||||
- self.sizes.SCORE_PANEL[1] / 2
|
- self.sizes.SCORE_PANEL[1] / 2
|
||||||
- self.sizes.MAX_RECALL_RATING_CLASS_HEIGHT
|
- self.sizes.MR_RT_HEIGHT
|
||||||
),
|
),
|
||||||
w=self.sizes.MAX_RECALL_RATING_CLASS_WIDTH,
|
w=self.sizes.MR_RT_WIDTH,
|
||||||
h=self.sizes.MAX_RECALL_RATING_CLASS_HEIGHT,
|
h=self.sizes.MR_RT_HEIGHT,
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -238,10 +319,10 @@ class DeviceV2Rois:
|
|||||||
def title_rect(self):
|
def title_rect(self):
|
||||||
return self.construct_int_xywh_rect(
|
return self.construct_int_xywh_rect(
|
||||||
x=0,
|
x=0,
|
||||||
y=self.h_fixed_mid
|
y=self.h_without_top_bar_mid
|
||||||
+ self.sizes.TITLE_BOTTOM_FROM_VER_MID
|
+ self.sizes.TITLE_BOTTOM_FROM_VMID
|
||||||
- self.sizes.TITLE_FONT_PX,
|
- self.sizes.TITLE_FONT_PX,
|
||||||
w=self.hor_mid + self.sizes.TITLE_WIDTH_RIGHT,
|
w=self.hmid + self.sizes.TITLE_WIDTH_RIGHT,
|
||||||
h=self.sizes.TITLE_FONT_PX,
|
h=self.sizes.TITLE_FONT_PX,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -250,19 +331,19 @@ class DeviceV2Rois:
|
|||||||
return crop_xywh(self.img, self.title_rect)
|
return crop_xywh(self.img, self.title_rect)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cover_rect(self):
|
def jacket_rect(self):
|
||||||
return self.construct_int_xywh_rect(
|
return self.construct_int_xywh_rect(
|
||||||
x=self.hor_mid
|
x=self.hmid
|
||||||
+ self.sizes.COVER_RIGHT_FROM_HOR_MID
|
+ self.sizes.JACKET_RIGHT_FROM_HOR_MID
|
||||||
- self.sizes.COVER_WIDTH,
|
- self.sizes.JACKET_WIDTH,
|
||||||
y=self.h_fixed_mid - self.sizes.SCORE_PANEL[1] / 2,
|
y=self.h_without_top_bar_mid - self.sizes.SCORE_PANEL[1] / 2,
|
||||||
w=self.sizes.COVER_WIDTH,
|
w=self.sizes.JACKET_WIDTH,
|
||||||
h=self.sizes.COVER_WIDTH,
|
h=self.sizes.JACKET_WIDTH,
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cover(self):
|
def jacket(self):
|
||||||
return crop_xywh(self.img, self.cover_rect)
|
return crop_xywh(self.img, self.jacket_rect)
|
||||||
|
|
||||||
|
|
||||||
class DeviceV2AutoRois(DeviceV2Rois):
|
class DeviceV2AutoRois(DeviceV2Rois):
|
||||||
@ -273,7 +354,7 @@ class DeviceV2AutoRois(DeviceV2Rois):
|
|||||||
|
|
||||||
def __init__(self, img: Mat):
|
def __init__(self, img: Mat):
|
||||||
factor = self.get_factor(img.shape[1], img.shape[0])
|
factor = self.get_factor(img.shape[1], img.shape[0])
|
||||||
self.sizes = Sizes(factor)
|
self.sizes = SizesV1(factor)
|
||||||
self.__img = None
|
self.__img = None
|
||||||
self.img = img
|
self.img = img
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user