From 6d1b45181257e58d444f8fc162632ffe1ca73dab Mon Sep 17 00:00:00 2001 From: SWHL Date: Fri, 1 Aug 2025 09:55:45 +0800 Subject: [PATCH] fix: fixed repeating printing in font logs --- python/rapidocr/utils/download_file.py | 6 +++++- python/rapidocr/utils/vis_res.py | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/python/rapidocr/utils/download_file.py b/python/rapidocr/utils/download_file.py index 8e5d9d9..5e65b89 100644 --- a/python/rapidocr/utils/download_file.py +++ b/python/rapidocr/utils/download_file.py @@ -19,6 +19,7 @@ class DownloadFileInput: save_path: Union[str, Path] logger: logging.Logger sha256: Optional[str] = None + verbose: bool = True class DownloadFile: @@ -27,6 +28,8 @@ class DownloadFile: @classmethod def run(cls, input_params: DownloadFileInput): + cls.verbose = input_params.verbose + save_path = Path(input_params.save_path) logger = input_params.logger @@ -53,7 +56,8 @@ class DownloadFile: return True if cls.check_file_sha256(path, expected_sha256): - logger.info("File exists and is valid: %s", path) + if cls.verbose: + logger.info("File exists and is valid: %s", path) return True logger.warning("File exists but is invalid, redownloading: %s", path) diff --git a/python/rapidocr/utils/vis_res.py b/python/rapidocr/utils/vis_res.py index 162b0c1..2121d7e 100644 --- a/python/rapidocr/utils/vis_res.py +++ b/python/rapidocr/utils/vis_res.py @@ -37,9 +37,7 @@ class VisRes: self.load_img = LoadImage() self.font_cfg = OmegaConf.load(FONT_YAML_PATH).fonts - self.font_path = self.get_font_path(font_path, lang_type) - self.logger.info(f"Using {self.font_path} to visualize results.") def __call__( self, @@ -48,6 +46,8 @@ class VisRes: txts: Optional[Union[List[str], Tuple[str]]] = None, scores: Optional[Tuple[float]] = None, ) -> np.ndarray: + self.logger.info(f"Using {self.font_path} to visualize results.") + if txts is None: return self.draw_dt_boxes(img_content, dt_boxes, scores) return self.draw_ocr_box_txt(img_content, dt_boxes, txts, scores) @@ -120,6 +120,7 @@ class VisRes: sha256=font_sha256, save_path=save_font_path, logger=self.logger, + verbose=False, ) DownloadFile.run(input_param) return str(save_font_path)