feat: Enhance OCR functionality and template matching for 福袋 detection

- Updated `config.json` to include new settings for `enable_ocr_mode1` and `fudai_template_match_threshold`.
- Refactored `douyin_detection.py` to implement template matching for 福袋 detection, replacing the previous pixel-based method.
- Improved error handling and logging for template matching operations.
- Added GUI options for enabling OCR mode and adjusting template matching threshold.
- Enhanced command-line interface to support new OCR and template matching parameters.
This commit is contained in:
Your Name committed 2025-12-19 14:11:16 +08:00
1 parent 836a31d817
commit 0163f27318
12 files changed
+472 -210

No files matched your search

+33
View File
@@ -815,6 +815,8 @@ class underlying_operations:
text = self.extract_ocr_content(result)
# 如果识别为空且图片较小,尝试放大重试(精度优化:使用更好的放大算法和增强处理)
img2 = None
text2 = None
if (not text) and max(w, h) <= 1200:
try:
# 使用LANCZOS重采样算法(更高质量的放大)
@@ -855,6 +857,37 @@ class underlying_operations:
except Exception:
pass
# 如果OCR识别成功(返回非空文本),保存一份图片到ocr文件夹(与cut_pic保存的图片区分开)
if text and text.strip() and picname:
try:
# 使用_find_pic_path获取ocr文件夹路径(写入模式)
base_dir = os.path.dirname(__file__)
pic_base = os.path.join(base_dir, 'pic')
ocr_dir = os.path.join(pic_base, 'ocr')
os.makedirs(ocr_dir, exist_ok=True)
# 保存文件名:{picname}_success.png,与cut_pic保存的{picname}.png区分开
success_path = os.path.join(ocr_dir, f'{picname}_success.png')
# 保存识别成功时的图片(使用预处理后的图片,即实际用于OCR的图片)
try:
# 如果使用了放大后的图片且识别成功,保存放大后的图片
if img2 is not None and text2 and text2.strip():
img_to_save = img2
else:
# 否则保存预处理后的图片(img1)
img_to_save = img1
img_to_save.save(success_path)
except Exception:
# 如果保存预处理后的图片失败,保存原始图片
try:
img.save(success_path)
except Exception:
pass
except Exception:
# 保存失败不影响OCR识别结果
pass
return text
def extract_ocr_content(self, content=[]):