Commit 9613950a authored by PiDanShouRouZhouXD's avatar PiDanShouRouZhouXD
Browse files

fix <skip>, add some font size control

parent 3be64ed4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -52,5 +52,5 @@ class StariverOCR:

        texts_list = ["".join(block.get('texts', '')).strip()
                      for block in response_data.get('text_block', [])]
        texts_str = "".join(texts_list)
        texts_str = "".join(texts_list).replace('<skip>', '')
        return texts_str
+25 −2
Original line number Diff line number Diff line
import base64
from re import T
from tkinter import font
import requests
import numpy as np
import cv2
@@ -140,6 +141,9 @@ class StariverDetector(TextDetectorBase):
            'options': [True, False],
            'select': False
        },
        "font_size_offset": "0",
        "font_size_min(set to -1 to disable)": "-1",
        "font_size_max(set to -1 to disable)": "-1",
        'description': '星河云(团子翻译器) OCR 文字检测器'
    }

@@ -194,6 +198,18 @@ class StariverDetector(TextDetectorBase):
        elif self.params['force_expand']['select'] == 'False':
            return False
        
    @property
    def font_size_offset(self):
        return int(self.params['font_size_offset'])

    @property
    def font_size_min(self):
        return int(self.params['font_size_min(set to -1 to disable)'])

    @property
    def font_size_max(self):
        return int(self.params['font_size_max(set to -1 to disable)'])

    def __init__(self, **params) -> None:
        super().__init__(**params)
        self.url = 'https://dl.ap-sh.starivercs.cn/v2/manga_trans/advanced/manga_ocr'
@@ -242,13 +258,20 @@ class StariverDetector(TextDetectorBase):
                    int(max(coord[1] for coord in block['block_coordinate'].values()))]
            lines = [np.array([[coord[pos][0], coord[pos][1]] for pos in ['upper_left', 'upper_right',
                              'lower_right', 'lower_left']], dtype=np.float32) for coord in block['coordinate']]
            texts = block.get('texts', '')
            texts = [text.replace('<skip>', '') for text in block.get('texts', [])]

            original_font_size = block.get('text_size', 0)
            font_size_recalculated = min(max(original_font_size + self.font_size_offset, self.font_size_min), self.font_size_max)

            if self.debug:
                self.logger.debug(f'原始字体大小:{original_font_size},修正后字体大小:{font_size_recalculated}')

            blk = TextBlock(
                xyxy=xyxy,
                lines=lines,
                language=block.get('language', 'unknown'),
                vertical=block.get('is_vertical', False),
                font_size=block.get('text_size', 0),
                font_size=font_size_recalculated,

                text=texts,
                fg_colors=np.array(block.get('foreground_color', [