Surya 是一个文档OCR工具包,提供强大的OCR(光学字符识别)和线条检测功能,支持90多种语言。
近期热文:
5.5K Star 强强强!!!PPT在线制作的开源方案13.8K Star开源!这个电子表格厉害了1.5K 强强强!!!开源超强的AI助手,支持多系统OA必备!!!开源一个好看的工作流设计器 |
---|
surya-ocr
需要 Python 3.9+ 和 PyTorch。首次运行会自动下载模型权重。pip install surya-ocr
from PIL import Image
from surya.ocr import run_ocr
from surya.model.detection import segformer
from surya.model.recognition.model import load_model
from surya.model.recognition.processor import load_processor
# 读取图像
image = Image.open(IMAGE_PATH)
langs = ["en"] # 替换为具体语言
det_processor, det_model = segformer.load_processor(), segformer.load_model()
rec_model, rec_processor = load_model(), load_processor()
# 运行 OCR
predictions = run_ocr([image], [langs], det_model, det_processor, rec_model, rec_processor)
from PIL import Image
from surya.detection import batch_text_detection
from surya.model.detection.segformer import load_model, load_processor
# 读取图像
image = Image.open(IMAGE_PATH)
model, processor = load_model(), load_processor()
# 进行文本行检测
predictions = batch_text_detection([image], model, processor)
from PIL import Image
from surya.detection import batch_text_detection
from surya.layout import batch_layout_detection
from surya.model.detection.segformer import load_model, load_processor
from surya.settings import settings
# 读取图像
image = Image.open(IMAGE_PATH)
model = load_model(checkpoint=settings.LAYOUT_MODEL_CHECKPOINT)
processor = load_processor(checkpoint=settings.LAYOUT_MODEL_CHECKPOINT)
det_model = load_model()
det_processor = load_processor()
# 进行排版分析
line_predictions = batch_text_detection([image], det_model, det_processor)
layout_predictions = batch_layout_detection([image], model, processor, line_predictions)
from PIL import Image
from surya.ordering import batch_ordering
from surya.model.ordering.processor import load_processor
from surya.model.ordering.model import load_model
image = Image.open(IMAGE_PATH)
# bboxes应该是一个包含[x1,y1,x2,y2]格式的图像布局框的列表
# 例如,可以从layout_model获取此信息,参见上面的用法示例
bboxes = [bbox1, bbox2, ...]
model = load_model()
processor = load_processor()
# 进行阅读顺序检测
order_predictions = batch_ordering([image], [bboxes], model, processor)
Surya 的强大功能使其适用于处理各种类型的文档,其中包括文字识别、文本行检测、排版分析和内容阅读顺序检测。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有