Commit 71033411 authored by dmMaze's avatar dmMaze
Browse files

support delete and restore region where OCR return empty string #258

parent 4fcd3b84
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -234,7 +234,7 @@ class TextBlock:

        return region

    def get_text(self):
    def get_text(self) -> str:
        if isinstance(self.text, str):
            return self.text
        text = ''
+1 −1
Original line number Diff line number Diff line
@@ -93,11 +93,11 @@ class ProgramConfig(Config):
    saladict_shortcut: str = "Alt+S"
    search_url: str = "https://www.google.com/search?q="
    ocr_sublist: dict = field(default_factory=lambda: [])
    restore_ocr_empty: bool = False
    mt_sublist: dict = field(default_factory=lambda: [])
    display_lang: str = C.DEFAULT_DISPLAY_LANG



    @staticmethod
    def load(cfg_path: str):
        
+1 −0
Original line number Diff line number Diff line
@@ -484,5 +484,6 @@ class ConfigPanel(Widget):
        self.saladict_shortcut.setKeySequence(pcfg.saladict_shortcut)
        self.searchurl_combobox.setCurrentText(pcfg.search_url)
        self.src_link_textbox.setText(pcfg.src_link_flag)
        self.ocr_config_panel.restoreEmptyOCRChecker.setChecked(pcfg.restore_ocr_empty)

        self.blockSignals(False)
 No newline at end of file
+8 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ from modules import GET_VALID_INPAINTERS, GET_VALID_TEXTDETECTORS, GET_VALID_TRA
from utils.logger import logger as LOGGER
from .stylewidgets import ConfigComboBox, NoBorderPushBtn, CustomComboBox
from .constants import CONFIG_FONTSIZE_CONTENT, CONFIG_COMBOBOX_MIDEAN, CONFIG_COMBOBOX_LONG, CONFIG_COMBOBOX_SHORT, CONFIG_COMBOBOX_HEIGHT
from .config import pcfg

from qtpy.QtWidgets import QPlainTextEdit, QHBoxLayout, QVBoxLayout, QWidget, QLabel, QComboBox, QCheckBox, QLineEdit
from qtpy.QtCore import Qt, Signal
@@ -353,4 +354,11 @@ class OCRConfigPanel(ModuleConfigParseWidget):
        self.replaceOCRkeywordBtn.clicked.connect(self.show_OCR_keyword_window)
        self.replaceOCRkeywordBtn.setFixedWidth(500)

        self.restoreEmptyOCRChecker = QCheckBox(self.tr("Delete and restore region where OCR return empty string."), self)
        self.restoreEmptyOCRChecker.clicked.connect(self.on_restore_empty_ocr)

        self.vlayout.addWidget(self.replaceOCRkeywordBtn)
        self.vlayout.addWidget(self.restoreEmptyOCRChecker)

    def on_restore_empty_ocr(self):
        pcfg.restore_ocr_empty = self.restoreEmptyOCRChecker.isChecked()
 No newline at end of file
+14 −0
Original line number Diff line number Diff line
@@ -243,11 +243,25 @@ class ProjImgTrans:
            imgname = self.current_img
        return osp.join(self.mask_dir(), osp.splitext(imgname)[0]+'.png')
    
    def load_mask_by_imgname(self, imgname: str) -> np.ndarray:
        mask = None
        mp = self.get_mask_path(imgname)
        if osp.exists(mp):
            mask = imread(mp, cv2.IMREAD_GRAYSCALE)
        return mask

    def get_inpainted_path(self, imgname: str = None) -> str:
        if imgname is None:
            imgname = self.current_img
        return osp.join(self.inpainted_dir(), osp.splitext(imgname)[0]+'.png')
    
    def load_inpainted_by_imgname(self, imgname: str) -> np.ndarray:
        inpainted = None
        mp = self.get_inpainted_path(imgname)
        if osp.exists(mp):
            inpainted = imread(mp)
        return inpainted

    def get_result_path(self, imgname: str) -> str:
        return osp.join(self.result_dir(), osp.splitext(imgname)[0]+'.png')
        
Loading