chore: Clean up and refactor codebase for improved maintainability
- Removed obsolete command-line test parameters from `run_cli.py` to streamline functionality. - Introduced a new `ocr_preprocess.py` module for unified OCR image preprocessing, enhancing recognition stability. - Updated various components to utilize the new preprocessing function, improving code organization and readability. - Adjusted configuration values in `config.json` for better performance and consistency. - Added comprehensive technical documentation for the Douyin project, detailing code modification standards and operational guidelines. - Cleaned up excessive blank lines across multiple files to enhance overall readability.
This commit is contained in:
1 parent
efe6e2252f
commit
223c127e11
70 files changed
+17121
-1752
No files matched your search
@@ -38,7 +38,7 @@ class OCRProcessor:
|
||||
# 首先尝试EasyOCR
|
||||
try:
|
||||
# 在Windows上,避免使用stderr重定向,可能会导致"lost sys.stderr"问题
|
||||
import easyocr # type: ignore[import-untyped] # pyright: ignore[reportMissingImports]
|
||||
import easyocr # type: ignore[import-untyped, import] # pyright: ignore[reportMissingImports, reportMissingModuleSource]
|
||||
|
||||
# 只加载中文和英文,加快初始化速度
|
||||
# 自动检测GPU可用性,如果可用则启用GPU加速
|
||||
@@ -67,19 +67,8 @@ class OCRProcessor:
|
||||
), contextlib.redirect_stderr(devnull):
|
||||
from paddleocr import PaddleOCR
|
||||
|
||||
# PaddleOCR的GPU支持需要paddlepaddle-gpu版本
|
||||
# 使用 PaddleOCR(强制 CPU 模式,不进行 GPU 检测)
|
||||
use_gpu = False
|
||||
try:
|
||||
import paddle
|
||||
|
||||
if (
|
||||
paddle.device.is_compiled_with_cuda()
|
||||
and paddle.device.get_device()
|
||||
):
|
||||
use_gpu = False
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
self.ocr = PaddleOCR(
|
||||
lang="ch",
|
||||
ocr_version="PP-OCRv4",
|
||||
@@ -90,8 +79,7 @@ class OCRProcessor:
|
||||
use_textline_orientation=False,
|
||||
)
|
||||
self.ocr_type = "paddleocr"
|
||||
gpu_status = "GPU加速" if use_gpu else "CPU模式"
|
||||
print(f"[OCR] EasyOCR不可用,使用 PaddleOCR({gpu_status})")
|
||||
print(f"[OCR] EasyOCR不可用,使用 PaddleOCR(CPU模式)")
|
||||
print(
|
||||
f"[OCR] 提示:安装EasyOCR可提升速度,运行: pip install easyocr"
|
||||
)
|
||||
@@ -146,19 +134,8 @@ class OCRProcessor:
|
||||
):
|
||||
from paddleocr import PaddleOCR
|
||||
|
||||
# PaddleOCR的GPU支持需要paddlepaddle-gpu版本
|
||||
# 使用 PaddleOCR(强制 CPU 模式)
|
||||
use_gpu = False
|
||||
try:
|
||||
import paddle
|
||||
|
||||
if (
|
||||
paddle.device.is_compiled_with_cuda()
|
||||
and paddle.device.get_device()
|
||||
):
|
||||
use_gpu = False
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
self.ocr = PaddleOCR(
|
||||
lang="ch",
|
||||
ocr_version="PP-OCRv4",
|
||||
@@ -169,8 +146,7 @@ class OCRProcessor:
|
||||
use_textline_orientation=False,
|
||||
)
|
||||
self.ocr_type = "paddleocr"
|
||||
gpu_status = "GPU加速" if use_gpu else "CPU模式"
|
||||
print(f"[OCR] 延迟初始化:EasyOCR不可用,使用 PaddleOCR({gpu_status})")
|
||||
print(f"[OCR] 延迟初始化:EasyOCR不可用,使用 PaddleOCR(CPU模式)")
|
||||
except Exception as e:
|
||||
print(f"[OCR] OCR引擎初始化失败: {e}")
|
||||
self.ocr = None
|
||||
@@ -228,4 +204,4 @@ __all__ = [
|
||||
"extract_ocr_content",
|
||||
"_ensure_ocr",
|
||||
]
|
||||
|
||||
|
||||
Reference in new issue
Block a user