Commit 3d8edf32 authored by Sergey Pinus's avatar Sergey Pinus
Browse files

"optional" paddle ocr

parent 042486b4
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -216,6 +216,7 @@ This project is heavily dependent upon [manga-image-translator](https://github.c
   * The current implementation uses OCR on each textblock individually, resulting in slower speed and no significant improvement in accuracy. It is not recommended. If needed, please use the Tuanzi Detector instead.
   * When using the Tuanzi Detector for text detection, it is recommended to set OCR to none_ocr to directly read the text, saving time and reducing the number of requests.
   * For detailed instructions, see **Tuanzi OCR Instructions**: ([Chinese](doc/团子OCR说明.md) & [Brazilian Portuguese](doc/Manual_TuanziOCR_pt-BR.md) only)
* Added as an "optional" PaddleOCR module. In Debug mode you will see a message stating that it is not there. You can simply install it by following the instructions described there. If you don’t want to install the package yourself, just uncomment (remove the `#`) the lines with paddlepaddle(gpu) and paddleocr. Bet everything at your own peril andrisk. For me (bropines) and two testers, everything was installed fine, you may have an error. Write about it in issue and tag me.

## Inpainting
  * AOT is from [manga-image-translator](https://github.com/zyddnys/manga-image-translator).
+297 −293
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ try:
except ImportError:
    PADDLE_OCR_AVAILABLE = False
    logging.warning(
        'PaddleOCR is not installed. Install it by following https://www.paddlepaddle.org.cn/en/install/quick?docurl'
        'PaddleOCR is not installed, so the module will not be initialized. \nInstall core it by following https://www.paddlepaddle.org.cn/en/install/quick?docurl \nand then run `pip install paddleocr`'
    )

import cv2
@@ -22,6 +22,7 @@ PADDLE_OCR_PATH = os.path.join('data', 'models', 'paddle-ocr')
# Set an environment variable to store PaddleOCR models
os.environ['PPOCR_HOME'] = PADDLE_OCR_PATH

if PADDLE_OCR_AVAILABLE:
    @register_OCR('paddle_ocr')
    class PaddleOCRModule(OCRBase):
        # Mapping language names to PaddleOCR codes
@@ -185,7 +186,7 @@ class PaddleOCRModule(OCRBase):
            lang_code = self.lang_map[self.language]
            use_gpu = True if self.device == 'cuda' else False
            if self.debug_mode:
            self.logger.info(f"Load the PaddleOCR model for the language: {self.language} ({lang_code}), GPU: {use_gpu}")
                self.logger.info(f"Loading PaddleOCR model for language: {self.language} ({lang_code}), GPU: {use_gpu}")
            self.model = PaddleOCR(
                use_angle_cls=self.use_angle_cls,
                lang=lang_code,
@@ -202,10 +203,10 @@ class PaddleOCRModule(OCRBase):

        def ocr_img(self, img: np.ndarray) -> str:
            if self.debug_mode:
            self.logger.debug(f"Start OCR for image size: {img.shape}")
                self.logger.debug(f"Starting OCR for image size: {img.shape}")
            result = self.model.ocr(img, det=True, rec=True, cls=self.use_angle_cls)
            if self.debug_mode:
            self.logger.debug(f"Recognition result: {result}")
                self.logger.debug(f"OCR recognition result: {result}")
            text = self._process_result(result)
            return text

@@ -227,13 +228,13 @@ class PaddleOCRModule(OCRBase):
                        raw_text = ' '.join(raw_texts)
                        
                        if self.debug_mode:
                        self.logger.debug(f"Raw OCR text from the block ({x1}, {y1}, {x2}, {y2}): {raw_text}")
                            self.logger.debug(f"Raw OCR text from block ({x1}, {y1}, {x2}, {y2}): {raw_text}")
                        
                        # Process the OCR result
                        text = self._process_result(result)
                        
                        if self.debug_mode:
                        self.logger.debug(f"Processed text from the block ({x1}, {y1}, {x2}, {y2}): {text}")
                            self.logger.debug(f"Processed text from block ({x1}, {y1}, {x2}, {y2}): {text}")
                        
                        blk.text = text if text else ''
                        
@@ -335,3 +336,6 @@ class PaddleOCRModule(OCRBase):
                self.text_case = self.params['text_case']['value']
            elif param_key == 'output_format':
                self.output_format = self.params['output_format']['value']
else:
    # If PaddleOCR is not installed, you can define a stub or alternative module
    logging.info('PaddleOCR module will not be loaded as the library is not installed.')
+3 −0
Original line number Diff line number Diff line
@@ -56,3 +56,6 @@ pyobjc-framework-cocoa; sys_platform == 'darwin'
pyobjc-framework-coreml; sys_platform == 'darwin'
pyobjc-framework-quartz; sys_platform == 'darwin'
pyobjc-framework-vision; sys_platform == 'darwin'
#paddleocr
#paddlepaddle - one of these. If you have a CUDA video card, then uncomment paddlepaddle-gpu
#paddlepaddle-gpu
 No newline at end of file