From 193ca77b0d0bd8f5ccdfc166b291bee2d2f06861 Mon Sep 17 00:00:00 2001 From: 283375 Date: Tue, 29 Aug 2023 23:36:34 +0800 Subject: [PATCH] feat: `DeviceV2AutoRois` --- src/arcaea_offline_ocr/device/v2/rois.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/arcaea_offline_ocr/device/v2/rois.py b/src/arcaea_offline_ocr/device/v2/rois.py index 1f1ba35..8a024ce 100644 --- a/src/arcaea_offline_ocr/device/v2/rois.py +++ b/src/arcaea_offline_ocr/device/v2/rois.py @@ -263,3 +263,23 @@ class DeviceV2Rois: @property def cover(self): return crop_xywh(self.img, self.cover_rect) + + +class DeviceV2AutoRois(DeviceV2Rois): + @staticmethod + def get_factor(width: int, height: int): + ratio = width / height + return ((width / 16) * 9) / 720 if ratio < (16 / 9) else height / 720 + + def __init__(self, img: Mat): + factor = self.get_factor(img.shape[1], img.shape[0]) + self.sizes = Sizes(factor) + self.__img = img + + @property + def img(self): + return self.__img + + @img.setter + def img(self, img: Mat): + self.__img = crop_black_edges(img)