2025-05-20 18:05:03 +08:00
### Installation
2024-10-28 22:52:28 +08:00
2024-10-29 21:34:25 +08:00
#### 1. Install PaddlePaddle
2025-05-20 18:05:03 +08:00
Installation for CPU:
2024-10-28 22:52:28 +08:00
2025-05-20 18:05:03 +08:00
```bash
python -m pip install paddlepaddle==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/
```
2024-10-28 22:52:28 +08:00
2025-05-20 18:05:03 +08:00
Installation for GPU: Since GPU installation requires specific CUDA versions, the following example is for installing NVIDIA GPU on the Linux platform with CUDA 11.8. For other platforms, please refer to the instructions in the [PaddlePaddle official installation documentation ](https://www.paddlepaddle.org.cn/install/quick ).
2024-10-28 22:52:28 +08:00
2025-05-20 18:05:03 +08:00
```bash
python -m pip install paddlepaddle-gpu==3.0.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
```
2024-10-28 22:52:28 +08:00
2025-05-20 18:05:03 +08:00
#### 2. Install `paddleocr`
2024-10-28 22:52:28 +08:00
2025-05-20 18:05:03 +08:00
```bash
pip install paddleocr
```
2024-10-28 22:52:28 +08:00
2025-05-20 18:05:03 +08:00
### Command Line Usage
2024-10-28 22:52:28 +08:00
2025-05-20 18:05:03 +08:00
=== "OCR Pipeline"
2024-10-28 22:52:28 +08:00
2025-05-20 18:05:03 +08:00
```bash linenums="1"
paddleocr ocr -i ./general_ocr_002.png
2024-10-28 22:52:28 +08:00
```
2025-05-20 18:05:03 +08:00
=== "Text Detection Module"
2024-10-28 22:52:28 +08:00
2025-05-20 18:05:03 +08:00
```bash linenums="1"
paddleocr text_detection -i ./general_ocr_001.png
2024-10-28 22:52:28 +08:00
```
2025-05-20 18:05:03 +08:00
=== "Text Recognition Module"
2024-10-28 22:52:28 +08:00
2025-05-20 18:05:03 +08:00
```bash linenums="1"
paddleocr text_recognition -i ./general_ocr_rec_001.png
2024-10-28 22:52:28 +08:00
```
2025-05-20 18:05:03 +08:00
=== "PP-StructureV3 Pipeline"
2024-10-28 22:52:28 +08:00
2025-05-20 18:05:03 +08:00
```bash linenums="1"
paddleocr pp_structurev3 -i ./pp_structure_v3_demo.png
2024-10-28 22:52:28 +08:00
```
2025-05-20 18:05:03 +08:00
### Python Script Usage
2024-10-28 22:52:28 +08:00
2025-05-20 18:05:03 +08:00
=== "OCR Pipeline"
2024-10-28 22:52:28 +08:00
```python linenums="1"
from paddleocr import PaddleOCR
2025-05-20 18:05:03 +08:00
ocr = PaddleOCR() # text image preprocessing + text detection + text orientation classification + text recognition
# ocr = PaddleOCR(use_doc_orientation_classify=False, use_doc_unwarping=False) # text detection + text orientation classification + text recognition
# ocr = PaddleOCR(use_doc_orientation_classify=False, use_doc_unwarping=False, use_textline_orientation=False) # text detection + text recognition
result = ocr.predict("./general_ocr_002.png")
for res in result:
res.print()
res.save_to_img("output")
res.save_to_json("output")
2024-10-28 22:52:28 +08:00
```
2025-05-20 18:05:03 +08:00
Example output:
2024-10-29 08:29:34 +08:00
2025-05-20 18:05:03 +08:00
```bash
{'res': {'input_path': './general_ocr_002.png', 'page_index': None, 'model_settings': {'use_doc_preprocessor': True, 'use_textline_orientation': False}, 'doc_preprocessor_res': {'input_path': None, 'page_index': None, 'model_settings': {'use_doc_orientation_classify': False, 'use_doc_unwarping': False}, 'angle': -1}, 'dt_polys': array([[[ 1, 4],
...,
[ 1, 33]],
2024-10-29 08:29:34 +08:00
2025-05-20 18:05:03 +08:00
...,
2024-10-29 08:29:34 +08:00
2025-05-20 18:05:03 +08:00
[[ 99, 455],
...,
[ 99, 480]]], dtype=int16), 'text_det_params': {'limit_side_len': 960, 'limit_type': 'max', 'thresh': 0.3, 'max_side_limit': 4000, 'box_thresh': 0.6, 'unclip_ratio': 1.5}, 'text_type': 'general', 'textline_orientation_angles': array([-1, ..., -1]), 'text_rec_score_thresh': 0.0, 'rec_texts': ['www.997788.com', '登机牌', 'BOARDING PASS', '舱位CLASS', '序号 SERIAL NO.', '座位号', 'SEAT NO', '航班FLIGHT', '日期', 'DATE', 'MU 2379', '03DEC', 'W', '035', '', '始发地', 'FROM', '登机口', 'GATE', '登机时间BDT', '目的地TO', '福州', 'TAIYUAN', 'G11', 'FUZHOU', '身份识别IDNO.', '姓名NAME', 'ZHANGQIWEI', '票号TKTNO.', '张祺伟', '票价FARE', 'ETKT7813699238489/1', '登机口于起飞前10分钟关闭 GATESCL0SE10MINUTESBEFOREDEPARTURETIME'], 'rec_scores': array([0.99684608, ..., 0.97179604]), 'rec_polys': array([[[ 1, 4],
...,
[ 1, 33]],
2024-10-29 08:29:34 +08:00
2025-05-20 18:05:03 +08:00
...,
2024-10-29 08:29:34 +08:00
2025-05-20 18:05:03 +08:00
[[ 99, 455],
...,
[ 99, 480]]], dtype=int16), 'rec_boxes': array([[ 1, ..., 33],
...,
[ 99, ..., 480]], dtype=int16)}}
2024-10-29 08:29:34 +08:00
```
2025-05-20 18:05:03 +08:00
=== "Text Detection Module"
2024-10-29 08:29:34 +08:00
```python linenums="1"
2025-05-20 18:05:03 +08:00
from paddleocr import TextDetection
2024-10-29 08:29:34 +08:00
2025-05-20 18:05:03 +08:00
model = TextDetection()
output = model.predict("general_ocr_001.png")
for res in output:
res.print()
res.save_to_img(save_path="./output/")
res.save_to_json(save_path="./output/res.json")
2024-10-29 08:29:34 +08:00
```
2025-05-20 18:05:03 +08:00
```bash
{'res': {'input_path': 'general_ocr_001.png', 'page_index': None, 'dt_polys': array([[[ 77, 551],
...,
[ 78, 587]],
2024-10-29 08:29:34 +08:00
2025-05-20 18:05:03 +08:00
...,
2024-10-29 08:29:34 +08:00
2025-05-20 18:05:03 +08:00
[[ 34, 408],
...,
[ 36, 456]]], dtype=int16), 'dt_scores': [0.8562385635646694, 0.8818259002228059, 0.8406072284043453, 0.8855339313157491]}}
2024-10-29 08:29:34 +08:00
```
2025-05-20 18:05:03 +08:00
=== "Text Recognition Module"
2024-10-29 08:29:34 +08:00
```python linenums="1"
2025-05-20 18:05:03 +08:00
from paddleocr import TextRecognition
2024-10-29 08:29:34 +08:00
2025-05-20 18:05:03 +08:00
model = TextRecognition()
output = model.predict(input="general_ocr_rec_001.png")
for res in output:
res.print()
res.save_to_img(save_path="./output/")
res.save_to_json(save_path="./output/res.json")
2024-10-29 08:29:34 +08:00
```
2025-05-20 18:05:03 +08:00
Example output:
```bash
{'res': {'input_path': 'general_ocr_rec_001.png', 'page_index': None, 'rec_text': '绿洲仕格维花园公寓', 'rec_score': 0.990813672542572}}
2024-10-29 08:29:34 +08:00
```
2025-05-20 18:05:03 +08:00
=== "PP-StructureV3 Pipeline"
2024-10-29 08:29:34 +08:00
```python linenums="1"
2025-05-20 18:05:03 +08:00
from paddleocr import PPStructureV3
2024-10-29 08:29:34 +08:00
2025-05-20 18:05:03 +08:00
pipeline = PPStructureV3()
output = pipeline.predict(
input="./pp_structure_v3_demo.png",
use_doc_orientation_classify=False,
use_doc_unwarping=False,
use_textline_orientation=False,
)
for res in output:
res.print()
res.save_to_json(save_path="output")
res.save_to_markdown(save_path="output")
2024-10-29 08:29:34 +08:00
```
2025-05-20 18:05:03 +08:00
Example output:
2024-10-28 22:52:28 +08:00
2025-05-20 18:05:03 +08:00
```bash
{'res': {'input_path': './pp_structure_v3_demo.png', 'page_index': None, 'model_settings': {'use_doc_preprocessor': False, 'use_seal_recognition': True, 'use_table_recognition': True, 'use_formula_recognition': True, 'use_chart_recognition': False, 'use_region_detection': True}, 'layout_det_res': {'input_path': None, 'page_index': None, 'boxes': [{'cls_id': 1, 'label': 'image', 'score': 0.9864752888679504, 'coordinate': [774.821, 201.05177, 1502.1008, 685.7733]}, {'cls_id': 2, 'label': 'text', 'score': 0.9859225749969482, 'coordinate': [769.8655, 776.2446, 1121.5986, 1058.417]}, {'cls_id': 2, 'label': 'text', 'score': 0.9857110381126404, 'coordinate': [1151.98, 1112.5356, 1502.7852, 1346.3569]}, {'cls_id': 2, 'label': 'text', 'score': 0.9847239255905151, 'coordinate': [389.0322, 1136.3547, 740.2322, 1345.928]}, {'cls_id': 2, 'label': 'text', 'score': 0.9842492938041687, 'coordinate': [1152.1504, 800.1625, 1502.1265, 986.1522]}, {'cls_id': 2, 'label': 'text', 'score': 0.9840831160545349, 'coordinate': [9.158066, 848.8696, 358.5725, 1057.832]}, {'cls_id': 2, 'label': 'text', 'score': 0.9802583456039429, 'coordinate': [9.335953, 201.10046, 358.31543, 338.78876]}, {'cls_id': 2, 'label': 'text', 'score': 0.9801402688026428, 'coordinate': [389.1556, 297.4113, 740.07556, 435.41647]}, {'cls_id': 2, 'label': 'text', 'score': 0.9793564081192017, 'coordinate': [389.18976, 752.0959, 740.0832, 889.88043]}, {'cls_id': 2, 'label': 'text', 'score': 0.9793409109115601, 'coordinate': [389.02496, 896.34143, 740.7431, 1033.9465]}, {'cls_id': 2, 'label': 'text', 'score': 0.9776486754417419, 'coordinate': [8.950775, 1184.7842, 358.75067, 1297.8755]}, {'cls_id': 2, 'label': 'text', 'score': 0.9773538708686829, 'coordinate': [770.7178, 1064.5714, 1121.2249, 1177.9928]}, {'cls_id': 2, 'label': 'text', 'score': 0.9773064255714417, 'coordinate': [389.38086, 609.7071, 740.0553, 745.3206]}, {'cls_id': 2, 'label': 'text', 'score': 0.9765821099281311, 'coordinate': [1152.0112, 992.296, 1502.4927, 1106.1166]}, {'cls_id': 2, 'label': 'text', 'score': 0.9761461019515991, 'coordinate': [9.46727, 536.993, 358.2047, 651.32025]}, {'cls_id': 2, 'label': 'text', 'score': 0.975399911403656, 'coordinate': [9.353531, 1064.3059, 358.45312, 1177.8347]}, {'cls_id': 2, 'label': 'text', 'score': 0.9730532169342041, 'coordinate': [9.932312, 345.36237, 358.03476, 435.1646]}, {'cls_id': 2, 'label': 'text', 'score': 0.9722575545310974, 'coordinate': [388.91736, 200.93637, 740.00793, 290.80692]}, {'cls_id': 2, 'label': 'text', 'score': 0.9710633158683777, 'coordinate': [389.39496, 1040.3186, 740.0091, 1129.7168]}, {'cls_id': 2, 'label': 'text', 'score': 0.9696939587593079, 'coordinate': [9.6145935, 658.1123, 359.06088, 770.0288]}, {'cls_id': 2, 'label': 'text', 'score': 0.9664146900177002, 'coordinate': [770.235, 1280.4562, 1122.0927, 1346.4742]}, {'cls_id': 2, 'label': 'text', 'score': 0.9597565531730652, 'coordinate': [389.66678, 537.5609, 740.06274, 603.17725]}, {'cls_id': 2, 'label': 'text', 'score': 0.9594324827194214, 'coordinate': [10.162949, 776.86414, 359.08307, 842.1771]}, {'cls_id': 2, 'label': 'text', 'score': 0.9484634399414062, 'coordinate': [10.402863, 1304.7743, 358.9441, 1346.3749]}, {'cls_id': 0, 'label': 'paragraph_title', 'score': 0.9476125240325928, 'coordinate': [28.159409, 456.7627, 339.5631, 514.9665]}, {'cls_id': 0, 'label': 'paragraph_title', 'score': 0.9427680969238281, 'coordinate': [790.6992, 1200.3663, 1102.3799, 1259.1647]}, {'cls_id': 0, 'label': 'paragraph_title', 'score': 0.9424256682395935, 'coordinate': [409.02832, 456.6831, 718.8154, 515.5757]}, {'cls_id': 10, 'label': 'doc_title', 'score': 0.9376171827316284, 'coordinate': [133.77905, 36.8844, 1379.6667, 123.46869]}, {'cls_id': 2, 'label': 'text', 'score': 0.9020252823829651, 'coordinate': [584.9165, 159.1416, 927.22876, 179.01605]}, {'cls_id': 2, 'label': 'text', 'score': 0.895164430141449, 'coordinate': [1154.3364, 776.74646, 1331.8564, 794.2301]}, {'cls_id': 6, 'label': 'figure_title', 'score': 0.7892374396324158, 'coordinate': [808.9641, 704.2555, 1484.0623, 747.2296]}]}, 'ove
...,
[ 129, 140]],
2024-10-28 22:52:28 +08:00
2025-05-20 18:05:03 +08:00
...,
2024-10-29 21:34:25 +08:00
2025-05-20 18:05:03 +08:00
[[1156, 1330],
...,
[1156, 1351]]], dtype=int16), 'text_det_params': {'limit_side_len': 736, 'limit_type': 'min', 'thresh': 0.3, 'max_side_limit': 4000, 'box_thresh': 0.6, 'unclip_ratio': 1.5}, 'text_type': 'general', 'textline_orientation_angles': array([-1, ..., -1]), 'text_rec_score_thresh': 0.0, 'rec_texts': ['助力双方交往', '搭建友谊桥梁', '本报记者沈小晓', '任', '彦', '黄培昭', '身着中国传统民族服装的厄立特里亚青', '厄立特里亚高等教育与研究院合作建立,开', '年依次登台表演中国民族舞、现代舞、扇子舞', '设了中国语言课程和中国文化课程,注册学', '等,曼妙的舞姿赢得现场观众阵阵掌声。这', '生2万余人次。10余年来, 厄特孔院已成为', '是日前危立特里亚高等教育与研究院孔子学', '当地民众了解中国的一扇窗口。', '院(以下简称“厄特孔院")举办“喜迎新年"中国', '黄鸣飞表示,随着来学习中文的人日益', '歌舞比赛的场景。', '增多,阿斯马拉大学教学点已难以满足教学', '中国和厄立特里亚传统友谊深厚。近年', '需要。2024年4月, 由中企蜀道集团所属四', '来,在高质量共建“一带一路”框架下,中厄两', '川路桥承建的孔院教学楼项目在阿斯马拉开', '国人文交流不断深化,互利合作的民意基础', '工建设,预计今年上半年竣工,建成后将为危', '日益深厚。', '特孔院提供全新的办学场地。', '“学好中文,我们的', '“在中国学习的经历', '未来不是梦”', '让我看到更广阔的世界”', '“鲜花曾告诉我你怎样走过,大地知道你', '多年来,厄立特里亚广大赴华留学生和', '心中的每一个角落……"厄立特里亚阿斯马拉', '培训人员积极投身国家建设,成为助力该国', '大学综合楼二层,一阵优美的歌声在走廊里回', '发展的人才和厄中友好的见证者和推动者。', '响。循着熟悉的旋律轻轻推开一间教室的门,', '在厄立特里亚全国妇女联盟工作的约翰', '学生们正跟着老师学唱中文歌曲《同一首歌》。', '娜·特韦尔德·凯莱塔就是其中一位。她曾在', '这是厄特孔院阿斯马拉大学教学点的一', '中华女子学院攻读硕士学位,研究方向是女', '节中文歌曲课。为了让学生们更好地理解歌', '性领导力与社会发展。其间,她实地走访中国', '词大意,老师尤斯拉·穆罕默德萨尔·侯赛因逐', '多个地区,获得了观察中国社会发展的第一', '在厄立特里亚不久前举办的第六届中国风筝文化节上,当地小学生体验风筝制作。', '字翻译和解释歌词。随着伴奏声响起,学生们', '手资料。', '中国驻厄立特里亚大使馆供图', '边唱边随着节拍摇动身体,现场气氛热烈。', '谈起在中国求学的经历,约翰娜记忆犹', '“这是中文歌曲初级班, 共有32人。学', '新:“中国的发展在当今世界是独一无二的。', '“不管远近都是客人,请不用客气;相约', '瓦的北红海省博物馆。', '生大部分来自首都阿斯马拉的中小学,年龄', '沿着中国特色社会主义道路坚定前行,中国', '好了在一起,我们欢迎你……”在一场中厄青', '博物馆二层陈列着一个发掘自阿杜利', '最小的仅有6岁。”尤斯拉告诉记者。', '创造了发展奇迹,这一切都离不开中国共产党', '年联谊活动上,四川路桥中方员工同当地大', '斯古城的中国古代陶制酒器,罐身上写着', '尤斯拉今年23岁, 是厄立特里亚一所公立', '的领导。中国的发展经验值得许多国家学习', '学生合唱《北京欢迎你》。厄立特里亚技术学', '“万”“和”“禅”“山”等汉字。“这件文物证', '学校的艺术老师。她12岁开始在厄特孔院学', '借鉴。”', '院计算机科学与工程专业学生鲁夫塔·谢拉', '明,很早以前我们就通过海上丝绸之路进行', '习中<E4B9A0>
...,
[ 129, 140]],
2024-10-28 22:52:28 +08:00
2025-05-20 18:05:03 +08:00
...,
2024-10-28 22:52:28 +08:00
2025-05-20 18:05:03 +08:00
[[1156, 1330],
...,
[1156, 1351]]], dtype=int16), 'rec_boxes': array([[ 129, ..., 140],
...,
[1156, ..., 1351]], dtype=int16)}}}
```