@@ -1847,3 +1847,39 @@ from paddleocr import PaddleOCR
1847
1847
1848
1848
pipeline = PaddleOCR(paddlex_config = " PaddleOCR.yaml" )
1849
1849
```
1850
+
1851
+ #### 4.2.3 通过环境变量指定使用本地字体文件路径
1852
+ 在初始化产线对象前,可通过设置环境变量,指定本地字体文件路径,使产线在执行 save_to_img 方法保存标注结果图像时使用该字体。
1853
+ 方便离线部署时无需网络下载字体文件,便于文件的管理,** 通过该方法需要确保指定的字体文件存在!**
1854
+
1855
+ 示例如下:
1856
+ 假设字体文件 ` simfang.ttf ` 存放于当前目录下的 ` fonts ` 文件夹内
1857
+
1858
+ python脚本:
1859
+
1860
+ ``` python
1861
+ import os
1862
+
1863
+ # 在初始化产线前指定字体文件的位置
1864
+ os.environ[" PADDLE_PDX_LOCAL_FONT_FILE_PATH" ] = " ./fonts/simfang.ttf"
1865
+
1866
+ from paddleocr import PaddleOCR
1867
+
1868
+ ocr = PaddleOCR(
1869
+ use_doc_orientation_classify = False ,
1870
+ use_doc_unwarping = False ,
1871
+ use_textline_orientation = False ) # 文本检测+文本识别
1872
+ # ocr = PaddleOCR(use_doc_orientation_classify=True, use_doc_unwarping=True) # 文本图像预处理+文本检测+方向分类+文本识别
1873
+ # ocr = PaddleOCR(use_doc_orientation_classify=False, use_doc_unwarping=False) # 文本检测+文本行方向分类+文本识别
1874
+ # ocr = PaddleOCR(
1875
+ # text_detection_model_name="PP-OCRv5_server_det",
1876
+ # text_recognition_model_name="PP-OCRv5_server_rec",
1877
+ # use_doc_orientation_classify=False,
1878
+ # use_doc_unwarping=False,
1879
+ # use_textline_orientation=False) # 更换 PP-OCRv5_server 模型
1880
+ result = ocr.predict(" ./general_ocr_002.png" )
1881
+ for res in result:
1882
+ res.print()
1883
+ res.save_to_img(" output" )
1884
+ res.save_to_json(" output" )
1885
+ ```
0 commit comments