40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
import os
|
||
# conda activate py310
|
||
# pip install easyocr
|
||
'''
|
||
手动下载模型文件
|
||
访问 EasyOCR 的 GitHub 发布页面:
|
||
https://github.com/JaidedAI/EasyOCR/releases
|
||
下载所需的模型文件(检测模型craft_mlt_25k.pth 和 中文识别模型zh_sim_g2.pth和英文识别模型english_g2.pth)
|
||
https://www.jaided.ai/easyocr/modelhub/
|
||
'''
|
||
import easyocr
|
||
print(easyocr.__file__) # 输出类似:C:\Python39\lib\site-packages\easyocr\__init__.py
|
||
|
||
# 指定自定义模型目录
|
||
custom_model_dir = r"D:\Model" # 替换为你放置模型文件的路径
|
||
|
||
# 从自定义目录加载模型
|
||
reader = easyocr.Reader(
|
||
['ch_sim', 'en'],
|
||
model_storage_directory=custom_model_dir,
|
||
download_enabled=False # 避免重复下载
|
||
)
|
||
print("模型加载成功!")
|
||
|
||
# 注意:这里需要真实图片路径,可替换为你的测试图片
|
||
test_image_path = r'D:\dsWork\dsProject\dsLightRag\Test\extracted\a62dce9d67c818accf94113aabefe172\1_2_TXT.png'
|
||
if os.path.exists(test_image_path):
|
||
print(f"测试图片: {test_image_path}")
|
||
results = reader.readtext(test_image_path)
|
||
|
||
if results:
|
||
print("识别结果:")
|
||
for (bbox, text, prob) in results:
|
||
print(f"- 文本: {text}, 置信度: {prob:.2f}")
|
||
else:
|
||
print("未检测到文本")
|
||
else:
|
||
print(f"请准备测试图片: {test_image_path}")
|
||
|