You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

42 lines
1.1 KiB

import sys
import os
sys.path.append('/root/.agents/skills/ocr-document-processor/scripts')
from ocr_processor import OCRProcessor
# 测试图片路径 - 请替换为实际图片路径
image_path = "/path/to/your/image.png"
if not os.path.exists(image_path):
print(f"错误:图片文件 {image_path} 不存在")
print("请将图片上传到服务器,然后修改脚本中的 image_path 为实际路径")
sys.exit(1)
try:
# 创建处理器,指定中文
processor = OCRProcessor(image_path, lang='chi_sim')
# 启用预处理提高准确率
processor.preprocess(
deskew=True,
denoise=True,
threshold=True,
contrast=1.5
)
# 提取文本
text = processor.extract_text()
print("=" * 60)
print("OCR 识别结果:")
print("=" * 60)
print(text)
print("=" * 60)
# 获取结构化结果
result = processor.extract_structured()
print(f"\n识别置信度: {result['confidence']:.1f}%")
print(f"检测到的语言: {result['language']}")
except Exception as e:
print(f"识别失败: {str(e)}")