学习OCR具体使用

Tesseract-OCR

使用Python和Tesseract-OCR库来识别图片中的文本,确保已经安装了pytesseractPillow库,并且已经在系统中安装了Tesseract-OCR。

1. 安装库:

pip install pytesseract Pillow

2. 安装Tesseract-OCR:

  • 对于Windows用户,下载并安装Tesseract 这里
  • 对于macOS用户,使用Homebrew安装:
brew install tesseract
  • 对于Linux用户,使用包管理器安装,例如在Ubuntu上:
sudo apt-get install tesseract-ocr

3. 安装中文语言包:

  • 对于Windows用户,下载中文语言包文件(chi_sim.traineddatachi_tra.traineddata)并将其放置在Tesseract的tessdata目录下,通常是C:\Program Files\Tesseract-OCR\tessdata\

  • 对于macOS和Linux用户,可以使用以下命令安装中文语言包:

# macOS
brew install tesseract-lang

# Ubuntu
sudo apt-get install tesseract-ocr-chi-sim
sudo apt-get install tesseract-ocr-chi-tra

安装链接:

  1. 简体中文(chi_sim.traineddata)下载链接:

  2. 繁体中文(chi_tra.traineddata)下载链接:

下载后,将这两个文件放置在Tesseract的tessdata目录下:

  • Windows通常为C:\Program Files\Tesseract-OCR\tessdata\
  • macOS和Linux则视安装路径而定,通常为/usr/local/share/tessdata/或者/usr/share/tessdata/

4. Python代码:

from PIL import Image
import pytesseract

# 如果你使用的是Windows,并且Tesseract安装路径不是默认的,
# 你可能需要设置pytesseract的路径:
# pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'

# 打开要进行OCR的图片
image_path = 'path_to_your_image.png'  # 替换为你的图片路径
image = Image.open(image_path)

# 使用pytesseract进行OCR,指定中文语言包
text = pytesseract.image_to_string(image, lang='chi_sim')  # 使用简体中文
# text = pytesseract.image_to_string(image, lang='chi_tra')  # 使用繁体中文

# 打印识别出的文本
print(text)

'path_to_your_image.png'替换为你要识别的图片的实际路径。如果你使用的是Windows,并且Tesseract安装路径不是默认的,你需要将pytesseract.pytesseract.tesseract_cmd路径设置为Tesseract可执行文件的实际路径。可以根据需要选择使用简体中文(chi_sim)或繁体中文(chi_tra)语言包。

5. 运行结果

001

B0ARD 1NG PASS

航 班 FLI1GHT “ 日 期 _DATE 舱 位 _CLASS 序 号 SERIAL N0 座 位 号 iSERTN ‖

MU 2379 _03DE6C W 035 不
目 的 地 T0 姜 发 地 FROM [ 耶 颜 3
福 H
TAIYUAN L_GH
乡〈名苇_熹`J'磊`煮^_昏)【J 身 份 识 别 10 N0.
ZHANGQIWEI
票 号 TKT N0.

票 价 FARE

Miiiiiiii 训胁‖

登 机 口 二 起 飞 前 10 分 钟 关 闭 GATBS CL0SF 10 MINUTES BBF0RE 惦PART

动

002

5 -
阪 州 东 07512 八
Hang ZhoaDon8 Shan8 HaiHon8 Qiao

羊 73.00 元
限 乘 当 日 当 次 咤

余 友 红 国
多 23501993xs0941 检 票 16
9004-1300-570 暗 -08M0-0190

已
和 谐 号

pomepmpomm

003

191

( 临 床歹〉

门 诊 号 :E05535540 标 本 种 类 : 血 清 标 志 提 示 :
“ 门 诊 科 别 : 门 诊 内 分 泌 条 码 号 :10080603139 临 床 诊 断 :
林 申 请 医 生 : 孙 首 悦 检 测 日 期 :2010-
水 _
结 果 围
312 262--649pmol/L
1540 9.01--19.04pmolL
131 0.35--4.94bIU/ml
025 <411IU/ml
0.1 <5.0U/L
027 <5.61IU/ml
01

01--10.0pg/ml

cnOCR

cnOCR是一个专门用于中文OCR的Python库,它使用了深度学习模型来进行中文字符的识别。下面是如何安装和使用cnOCR进行中文OCR的步骤。

1. 安装cnOCR

pip install cnocr

cnOCR 依赖于 onnxruntime 来运行深度学习模型。你需要安装 onnxruntime 才能使用 cnOCR。你可以通过以下命令来安装它:

pip install onnxruntime

如果你使用的是 GPU 加速的环境,你可以安装 onnxruntime-gpu 版本:

pip install onnxruntime-gpu

2. 使用cnOCR进行OCR:

from cnocr import CnOcr  
  
# 创建CnOcr对象  
ocr = CnOcr()  
  
# 图片文件路径  
image_path = 'your_image_path.jpg'  
  
# 使用ocr方法识别图片中的文字  
result = ocr.ocr(image_path)  
  
# 遍历识别结果并打印  
for item in result:  
    print(item['text'])  # 打印识别出的文字  
    # 如果需要,还可以访问其他字段,如位置信息(item['position'])  

确保将'your_image_path.jpg'替换为你的图片路径。cnOCR会自动处理图像并返回识别的文本结果。

3. 运行结果

001

E:\anaconda\python.exe E:\PythonCode\OCR\cnOCR.py 
www.9gpp88. cem

登机牌
BOARDING PASS
航班FLIGHT
日期DATE
舱位
CLASS
序号SERIAL NO.

座位号 SEATNO
MU2379
O3DEG
W
035
2F
目的地T0
始发地
FROM
登机口
GATE
登机时间、BDT
福州
TAIYUAN
G11
FUZHOU
身份识别IDNO
姓名NAME
ZHANGQIWET
票号TKTNO
张祺伟
票价 FARE
ETKT7813699238489/1
登机口于起飞前10分钟关闭 GATES CLOSE 1O MINUTES BEFORE DEPARTURE TIME

进程已结束,退出代码0

002

E:\anaconda\python.exe E:\PythonCode\OCR\cnOCR.py 
7788.com
Z57A001950
杭州东售
2013年07月07日13:39开
06车12B号
二等座
杭州东
G7512次
上海虹桥
HangZhouDong
ShangHaiHongOiao
¥73.00元
限乘当日当次车
余友红
检票口16
3623301993****0941
9004-1300-570-08A0-01950
和谐号
Canon PowerShot 43400 15 F2.8 1/'20s 150400

进程已结束,退出代码0

003

E:\anaconda\python.exe E:\PythonCode\OCR\cnOCR.py 
NBSAl"
3504811979
工元时属瑞金医院
标本号:OA
重燕技告单(临床内分泌
入
门诊号:E05535540
标本种类:血清
标志提示:
加女
门诊科别:门诊内分泌
条码号:100806031391
临床诊断:
年龄:31
申请医生:孙首悦
检测日期:2010
检验备注:
项目
结果
参考范围
FT3
3.12
2.62--6.49pmol/L
FT4
15.40
9.01--19.04pmol/L
STSH
1.31
0.35--4.94uIU/mi
TGAB
0.15
<4.11IU/mi
TRAb
0.1
<5.OU/L
TPOAb
0.17
<5.61IU/m
降钙素
0.1
0.1--10.0pg/mi
采样时间:10-08-06 11:23
收到时间:10-08-06 11:44
报告时间:10-08-0711:28
打印时间:1
以上7项检验结果仅供临床医师参考
检验:李纪平
核对:

进程已结束,退出代码0

PaddleOCR

安装和使用 PaddleOCR 的步骤:

1. 安装 PaddleOCR:

首先,需要安装 PaddlePaddle。如果你有 GPU 并且想使用 GPU 版本,请参考 PaddlePaddle 的安装指南

对于 CPU 版本,可以使用以下命令:

pip install paddlepaddle

然后,安装 PaddleOCR:

pip install paddleocr

2. 使用 PaddleOCR 进行 OCR:

from paddleocr import PaddleOCR, draw_ocr
import matplotlib.pyplot as plt
from PIL import Image

# 初始化OCR模型
ocr = PaddleOCR(use_angle_cls=True, lang='ch')  # 需要检测中文请设置 lang='ch'

# 图片路径
image_path = 'path_to_your_image.png'  # 替换为你的图片路径

# 运行OCR
result = ocr.ocr(image_path, cls=True)

# 打印识别结果
for line in result:
    print(line)

# 如果你想绘制结果
image = Image.open(image_path).convert('RGB')
boxes = [elements[0] for elements in line for line in result]
txts = [elements[1][0] for elements in line for line in result]
scores = [elements[1][1] for elements in line for line in result]

# 使用PaddleOCR的绘图函数
im_show = draw_ocr(image, boxes, txts, scores, font_path='path_to_your_font.ttc')  # 替换为你的字体路径
im_show = Image.fromarray(im_show)

# 显示结果
plt.imshow(im_show)
plt.axis('off')
plt.show()

在这个示例中:

  • PaddleOCR 类初始化时使用 lang='ch' 来设置语言为中文。
  • 使用 ocr.ocr(image_path, cls=True) 方法进行 OCR 识别。
  • draw_ocr 函数用于绘制识别结果。

确保将 path_to_your_image.png 替换为你的图片路径。如果你需要绘制结果,path_to_your_font.ttc 需要替换为你的字体文件路径,常见中文字体文件可以从系统字体目录中找到。

这是一个简单的示例,PaddleOCR 还支持更多的配置和高级功能,可以参考 PaddleOCR 的文档 了解更多信息。

3. 这种写法会有一定问题

这个错误是由于多次初始化 OpenMP 运行时导致的,它可能会影响性能或产生不正确的结果。这个问题通常在使用多线程的库时出现,尤其是在同时使用多个依赖 OpenMP 的库时。要解决这个问题,可以设置环境变量 KMP_DUPLICATE_LIB_OK=TRUE,但这只是一个临时的解决方法。

你可以按如下步骤设置环境变量并继续运行你的代码:

临时解决方法:

在你的 Python 代码中添加以下内容:

import os
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"

这样设置环境变量后,可以避免 OpenMP 初始化错误。

进一步解决方法:

彻底解决这个问题,可以尝试以下方法:

  1. 检查环境:确保你没有同时使用多个依赖 OpenMP 的库。例如,如果你在同一个环境中同时使用 PaddlePaddle 和其他依赖 OpenMP 的库(如 TensorFlowPyTorch 等),尝试将这些库分开使用,或者创建一个单独的虚拟环境来运行 PaddleOCR

  2. 更新库:确保你使用的是最新版本的 PaddlePaddlePaddleOCR。有时候库的更新会修复一些兼容性问题。

  3. 避免静态链接:如果你自己编译了某些库,确保它们没有静态链接 OpenMP 运行时。

通过这些方法,可以更彻底地解决 OpenMP 运行时初始化问题。

4. 运行结果

001

E:\anaconda\python.exe E:\PythonCode\OCR\PaddleOCR.py 
[2024/07/22 16:28:36] ppocr DEBUG: Namespace(help='==SUPPRESS==', use_gpu=False, use_xpu=False, use_npu=False, use_mlu=False, ir_optim=True, use_tensorrt=False, min_subgraph_size=15, precision='fp32', gpu_mem=500, gpu_id=0, image_dir=None, page_num=0, det_algorithm='DB', det_model_dir='C:\\Users\\jyk/.paddleocr/whl\\det\\ch\\ch_PP-OCRv4_det_infer', det_limit_side_len=960, det_limit_type='max', det_box_type='quad', det_db_thresh=0.3, det_db_box_thresh=0.6, det_db_unclip_ratio=1.5, max_batch_size=10, use_dilation=False, det_db_score_mode='fast', det_east_score_thresh=0.8, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2, det_sast_score_thresh=0.5, det_sast_nms_thresh=0.2, det_pse_thresh=0, det_pse_box_thresh=0.85, det_pse_min_area=16, det_pse_scale=1, scales=[8, 16, 32], alpha=1.0, beta=1.0, fourier_degree=5, rec_algorithm='SVTR_LCNet', rec_model_dir='C:\\Users\\jyk/.paddleocr/whl\\rec\\ch\\ch_PP-OCRv4_rec_infer', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_batch_num=6, max_text_length=25, rec_char_dict_path='C:\\Users\\jyk\\AppData\\Roaming\\Python\\Python311\\site-packages\\paddleocr\\ppocr\\utils\\ppocr_keys_v1.txt', use_space_char=True, vis_font_path='./doc/fonts/simfang.ttf', drop_score=0.5, e2e_algorithm='PGNet', e2e_model_dir=None, e2e_limit_side_len=768, e2e_limit_type='max', e2e_pgnet_score_thresh=0.5, e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_pgnet_valid_set='totaltext', e2e_pgnet_mode='fast', use_angle_cls=True, cls_model_dir='C:\\Users\\jyk/.paddleocr/whl\\cls\\ch_ppocr_mobile_v2.0_cls_infer', cls_image_shape='3, 48, 192', label_list=['0', '180'], cls_batch_num=6, cls_thresh=0.9, enable_mkldnn=False, cpu_threads=10, use_pdserving=False, warmup=False, sr_model_dir=None, sr_image_shape='3, 32, 128', sr_batch_num=1, draw_img_save_dir='./inference_results', save_crop_res=False, crop_res_save_dir='./output', use_mp=False, total_process_num=1, process_id=0, benchmark=False, save_log_path='./log_output/', show_log=True, use_onnx=False, return_word_box=False, output='./output', table_max_len=488, table_algorithm='TableAttn', table_model_dir=None, merge_no_span_structure=True, table_char_dict_path=None, layout_model_dir=None, layout_dict_path=None, layout_score_threshold=0.5, layout_nms_threshold=0.5, kie_algorithm='LayoutXLM', ser_model_dir=None, re_model_dir=None, use_visual_backbone=True, ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ocr_order_method=None, mode='structure', image_orientation=False, layout=True, table=True, ocr=True, recovery=False, use_pdf2docx_api=False, invert=False, binarize=False, alphacolor=(255, 255, 255), lang='ch', det=True, rec=True, type='ocr', savefile=False, ocr_version='PP-OCRv4', structure_version='PP-StructureV2')
[2024/07/22 16:28:37] ppocr DEBUG: dt_boxes num : 32, elapsed : 0.36597633361816406
[2024/07/22 16:28:37] ppocr DEBUG: cls num  : 32, elapsed : 0.14300084114074707
[2024/07/22 16:28:38] ppocr DEBUG: rec_res num  : 32, elapsed : 0.9479615688323975
[[[[160.0, 28.0], [353.0, 23.0], [354.0, 68.0], [161.0, 72.0]], ('登机牌', 0.9982693791389465)], [[[424.0, 26.0], [657.0, 21.0], [657.0, 57.0], [424.0, 61.0]], ('BOARDING', 0.9880115985870361)], [[[701.0, 19.0], [821.0, 14.0], [822.0, 55.0], [702.0, 60.0]], ('PASS', 0.9771671295166016)], [[[340.0, 105.0], [458.0, 103.0], [458.0, 125.0], [340.0, 127.0]], ('舱位CLASS', 0.9973748326301575)], [[[489.0, 103.0], [648.0, 100.0], [648.0, 122.0], [489.0, 125.0]], ('序号SERIALNO.', 0.9620336890220642)], [[[678.0, 98.0], [742.0, 98.0], [742.0, 121.0], [678.0, 121.0]], ('座位号', 0.9977888464927673)], [[[751.0, 98.0], [834.0, 96.0], [834.0, 116.0], [751.0, 119.0]], ('SEAT NO', 0.9321314692497253)], [[[64.0, 113.0], [192.0, 109.0], [192.0, 130.0], [64.0, 133.0]], ('航班 FLIGHT', 0.9577866792678833)], [[[213.0, 108.0], [317.0, 106.0], [317.0, 127.0], [213.0, 129.0]], ('日期DATE', 0.9968903660774231)], [[[84.0, 139.0], [212.0, 137.0], [212.0, 162.0], [84.0, 164.0]], ('MU 2379', 0.9460418820381165)], [[[234.0, 136.0], [328.0, 136.0], [328.0, 161.0], [234.0, 161.0]], ('03DEC', 0.9828975796699524)], [[[406.0, 134.0], [431.0, 134.0], [431.0, 158.0], [406.0, 158.0]], ('W', 0.9725339412689209)], [[[510.0, 130.0], [569.0, 130.0], [569.0, 157.0], [510.0, 157.0]], ('035', 0.9989141821861267)], [[[344.0, 175.0], [411.0, 175.0], [411.0, 197.0], [344.0, 197.0]], ('始发地', 0.9984915852546692)], [[[403.0, 175.0], [470.0, 175.0], [470.0, 194.0], [403.0, 194.0]], ('FROM', 0.9937996864318848)], [[[490.0, 174.0], [554.0, 174.0], [554.0, 196.0], [490.0, 196.0]], ('登机口', 0.9991149306297302)], [[[566.0, 173.0], [614.0, 173.0], [614.0, 193.0], [566.0, 193.0]], ('GATE', 0.9933360815048218)], [[[678.0, 170.0], [811.0, 167.0], [811.0, 189.0], [678.0, 192.0]], ('登机时间BDT', 0.9975901246070862)], [[[67.0, 181.0], [169.0, 178.0], [169.0, 200.0], [67.0, 202.0]], ('目的地TO', 0.9764602780342102)], [[[98.0, 207.0], [169.0, 205.0], [170.0, 228.0], [99.0, 230.0]], ('福州', 0.9982196688652039)], [[[339.0, 219.0], [476.0, 214.0], [476.0, 236.0], [339.0, 240.0]], ('TAIYUAN', 0.9902319312095642)], [[[509.0, 216.0], [553.0, 216.0], [553.0, 235.0], [509.0, 235.0]], ('G11', 0.9465179443359375)], [[[90.0, 229.0], [203.0, 227.0], [203.0, 249.0], [90.0, 252.0]], ('FUZHOU', 0.9948038458824158)], [[[345.0, 239.0], [482.0, 235.0], [482.0, 257.0], [345.0, 261.0]], ('身份识别IDNO', 0.9955540895462036)], [[[67.0, 251.0], [173.0, 248.0], [173.0, 271.0], [67.0, 273.0]], ('姓名NAME', 0.9940476417541504)], [[[76.0, 277.0], [265.0, 272.0], [265.0, 297.0], [76.0, 301.0]], ('ZHANGQIWEI', 0.9928168058395386)], [[[462.0, 297.0], [578.0, 295.0], [578.0, 316.0], [462.0, 319.0]], ('票号TKTNO', 0.9919643402099609)], [[[102.0, 313.0], [209.0, 309.0], [210.0, 335.0], [103.0, 338.0]], ('张祺伟', 0.9940171241760254)], [[[69.0, 344.0], [164.0, 340.0], [165.0, 363.0], [70.0, 366.0]], ('票价FARE', 0.9954412579536438)], [[[346.0, 350.0], [662.0, 346.0], [662.0, 367.0], [346.0, 370.0]], ('ETKT7813699238489/1', 0.9942991137504578)], [[[101.0, 458.0], [832.0, 443.0], [832.0, 464.0], [101.0, 479.0]], ('登机口于起飞前10分钟关闭GATESCLOSE10MINUTESBEFOREDEPARTURETIME', 0.9630523920059204)]]

进程已结束,退出代码0

001结果

002

E:\anaconda\python.exe E:\PythonCode\OCR\PaddleOCR.py 
[2024/07/22 16:31:12] ppocr DEBUG: Namespace(help='==SUPPRESS==', use_gpu=False, use_xpu=False, use_npu=False, use_mlu=False, ir_optim=True, use_tensorrt=False, min_subgraph_size=15, precision='fp32', gpu_mem=500, gpu_id=0, image_dir=None, page_num=0, det_algorithm='DB', det_model_dir='C:\\Users\\jyk/.paddleocr/whl\\det\\ch\\ch_PP-OCRv4_det_infer', det_limit_side_len=960, det_limit_type='max', det_box_type='quad', det_db_thresh=0.3, det_db_box_thresh=0.6, det_db_unclip_ratio=1.5, max_batch_size=10, use_dilation=False, det_db_score_mode='fast', det_east_score_thresh=0.8, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2, det_sast_score_thresh=0.5, det_sast_nms_thresh=0.2, det_pse_thresh=0, det_pse_box_thresh=0.85, det_pse_min_area=16, det_pse_scale=1, scales=[8, 16, 32], alpha=1.0, beta=1.0, fourier_degree=5, rec_algorithm='SVTR_LCNet', rec_model_dir='C:\\Users\\jyk/.paddleocr/whl\\rec\\ch\\ch_PP-OCRv4_rec_infer', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_batch_num=6, max_text_length=25, rec_char_dict_path='C:\\Users\\jyk\\AppData\\Roaming\\Python\\Python311\\site-packages\\paddleocr\\ppocr\\utils\\ppocr_keys_v1.txt', use_space_char=True, vis_font_path='./doc/fonts/simfang.ttf', drop_score=0.5, e2e_algorithm='PGNet', e2e_model_dir=None, e2e_limit_side_len=768, e2e_limit_type='max', e2e_pgnet_score_thresh=0.5, e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_pgnet_valid_set='totaltext', e2e_pgnet_mode='fast', use_angle_cls=True, cls_model_dir='C:\\Users\\jyk/.paddleocr/whl\\cls\\ch_ppocr_mobile_v2.0_cls_infer', cls_image_shape='3, 48, 192', label_list=['0', '180'], cls_batch_num=6, cls_thresh=0.9, enable_mkldnn=False, cpu_threads=10, use_pdserving=False, warmup=False, sr_model_dir=None, sr_image_shape='3, 32, 128', sr_batch_num=1, draw_img_save_dir='./inference_results', save_crop_res=False, crop_res_save_dir='./output', use_mp=False, total_process_num=1, process_id=0, benchmark=False, save_log_path='./log_output/', show_log=True, use_onnx=False, return_word_box=False, output='./output', table_max_len=488, table_algorithm='TableAttn', table_model_dir=None, merge_no_span_structure=True, table_char_dict_path=None, layout_model_dir=None, layout_dict_path=None, layout_score_threshold=0.5, layout_nms_threshold=0.5, kie_algorithm='LayoutXLM', ser_model_dir=None, re_model_dir=None, use_visual_backbone=True, ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ocr_order_method=None, mode='structure', image_orientation=False, layout=True, table=True, ocr=True, recovery=False, use_pdf2docx_api=False, invert=False, binarize=False, alphacolor=(255, 255, 255), lang='ch', det=True, rec=True, type='ocr', savefile=False, ocr_version='PP-OCRv4', structure_version='PP-StructureV2')
[2024/07/22 16:31:13] ppocr DEBUG: dt_boxes num : 19, elapsed : 0.32050275802612305
[2024/07/22 16:31:14] ppocr DEBUG: cls num  : 19, elapsed : 0.16436052322387695
[2024/07/22 16:31:14] ppocr DEBUG: rec_res num  : 19, elapsed : 0.72969651222229
[[[[4.0, 2.0], [158.0, 5.0], [157.0, 52.0], [3.0, 48.0]], ('7788.com', 0.9982924461364746)], [[[77.0, 101.0], [231.0, 101.0], [231.0, 128.0], [77.0, 128.0]], ('Z57A001950', 0.9952950477600098)], [[[408.0, 102.0], [508.0, 105.0], [507.0, 133.0], [408.0, 130.0]], ('杭州东售', 0.9974438548088074)], [[[69.0, 139.0], [325.0, 139.0], [325.0, 162.0], [69.0, 162.0]], ('2013年07月07日13:39开', 0.9727839231491089)], [[[392.0, 137.0], [506.0, 137.0], [506.0, 161.0], [392.0, 161.0]], ('06车12B号', 0.997517466545105)], [[[453.0, 159.0], [507.0, 159.0], [507.0, 185.0], [453.0, 185.0]], ('二等座', 0.8282411694526672)], [[[240.0, 173.0], [354.0, 175.0], [354.0, 203.0], [239.0, 201.0]], ('G7512次', 0.9981548190116882)], [[[93.0, 183.0], [194.0, 183.0], [194.0, 215.0], [93.0, 215.0]], ('杭州东', 0.9982073903083801)], [[[388.0, 182.0], [519.0, 186.0], [518.0, 216.0], [388.0, 213.0]], ('上海虹桥', 0.9968946576118469)], [[[81.0, 215.0], [220.0, 217.0], [220.0, 241.0], [81.0, 239.0]], ('HangZhouDong', 0.9954153895378113)], [[[362.0, 215.0], [531.0, 217.0], [530.0, 241.0], [362.0, 239.0]], ('ShangHaiHongQiao', 0.9900991916656494)], [[[77.0, 246.0], [180.0, 246.0], [180.0, 267.0], [77.0, 267.0]], ('¥73.00元', 0.9703517556190491)], [[[76.0, 274.0], [219.0, 274.0], [219.0, 298.0], [76.0, 298.0]], ('限乘当日当次车', 0.9975977540016174)], [[[76.0, 302.0], [146.0, 302.0], [146.0, 327.0], [76.0, 327.0]], ('余友红', 0.9941067695617676)], [[[295.0, 316.0], [404.0, 308.0], [406.0, 337.0], [298.0, 345.0]], ('检票口16', 0.9946401715278625)], [[[72.0, 330.0], [288.0, 325.0], [288.0, 352.0], [72.0, 358.0]], ('3623301993****0941', 0.9971020817756653)], [[[62.0, 365.0], [324.0, 365.0], [324.0, 384.0], [62.0, 384.0]], ('9004-1300-5707-08A0-0195-0', 0.9852203726768494)], [[[422.0, 360.0], [512.0, 360.0], [512.0, 381.0], [422.0, 381.0]], ('和谐号', 0.9985259175300598)], [[[16.0, 492.0], [244.0, 492.0], [244.0, 506.0], [16.0, 506.0]], ('CanonPowerShotA3400 ISF2.8 1/20s IS0400', 0.9463545083999634)]]

进程已结束,退出代码0

002结果

003

E:\anaconda\python.exe E:\PythonCode\OCR\PaddleOCR.py 
[2024/07/22 16:32:34] ppocr DEBUG: Namespace(help='==SUPPRESS==', use_gpu=False, use_xpu=False, use_npu=False, use_mlu=False, ir_optim=True, use_tensorrt=False, min_subgraph_size=15, precision='fp32', gpu_mem=500, gpu_id=0, image_dir=None, page_num=0, det_algorithm='DB', det_model_dir='C:\\Users\\jyk/.paddleocr/whl\\det\\ch\\ch_PP-OCRv4_det_infer', det_limit_side_len=960, det_limit_type='max', det_box_type='quad', det_db_thresh=0.3, det_db_box_thresh=0.6, det_db_unclip_ratio=1.5, max_batch_size=10, use_dilation=False, det_db_score_mode='fast', det_east_score_thresh=0.8, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2, det_sast_score_thresh=0.5, det_sast_nms_thresh=0.2, det_pse_thresh=0, det_pse_box_thresh=0.85, det_pse_min_area=16, det_pse_scale=1, scales=[8, 16, 32], alpha=1.0, beta=1.0, fourier_degree=5, rec_algorithm='SVTR_LCNet', rec_model_dir='C:\\Users\\jyk/.paddleocr/whl\\rec\\ch\\ch_PP-OCRv4_rec_infer', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_batch_num=6, max_text_length=25, rec_char_dict_path='C:\\Users\\jyk\\AppData\\Roaming\\Python\\Python311\\site-packages\\paddleocr\\ppocr\\utils\\ppocr_keys_v1.txt', use_space_char=True, vis_font_path='./doc/fonts/simfang.ttf', drop_score=0.5, e2e_algorithm='PGNet', e2e_model_dir=None, e2e_limit_side_len=768, e2e_limit_type='max', e2e_pgnet_score_thresh=0.5, e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_pgnet_valid_set='totaltext', e2e_pgnet_mode='fast', use_angle_cls=True, cls_model_dir='C:\\Users\\jyk/.paddleocr/whl\\cls\\ch_ppocr_mobile_v2.0_cls_infer', cls_image_shape='3, 48, 192', label_list=['0', '180'], cls_batch_num=6, cls_thresh=0.9, enable_mkldnn=False, cpu_threads=10, use_pdserving=False, warmup=False, sr_model_dir=None, sr_image_shape='3, 32, 128', sr_batch_num=1, draw_img_save_dir='./inference_results', save_crop_res=False, crop_res_save_dir='./output', use_mp=False, total_process_num=1, process_id=0, benchmark=False, save_log_path='./log_output/', show_log=True, use_onnx=False, return_word_box=False, output='./output', table_max_len=488, table_algorithm='TableAttn', table_model_dir=None, merge_no_span_structure=True, table_char_dict_path=None, layout_model_dir=None, layout_dict_path=None, layout_score_threshold=0.5, layout_nms_threshold=0.5, kie_algorithm='LayoutXLM', ser_model_dir=None, re_model_dir=None, use_visual_backbone=True, ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ocr_order_method=None, mode='structure', image_orientation=False, layout=True, table=True, ocr=True, recovery=False, use_pdf2docx_api=False, invert=False, binarize=False, alphacolor=(255, 255, 255), lang='ch', det=True, rec=True, type='ocr', savefile=False, ocr_version='PP-OCRv4', structure_version='PP-StructureV2')
[2024/07/22 16:32:35] ppocr DEBUG: dt_boxes num : 49, elapsed : 0.3851795196533203
[2024/07/22 16:32:35] ppocr DEBUG: cls num  : 49, elapsed : 0.1552412509918213
[2024/07/22 16:32:36] ppocr DEBUG: rec_res num  : 49, elapsed : 1.2833442687988281
[[[[6.0, 2.0], [65.0, 2.0], [65.0, 25.0], [6.0, 25.0]], ('AlicialLilac', 0.8227503299713135)], [[[9.0, 18.0], [45.0, 18.0], [45.0, 30.0], [9.0, 30.0]], ('Iibe.com', 0.6899917125701904)], [[[34.0, 32.0], [213.0, 0.0], [218.0, 28.0], [39.0, 62.0]], ('3504811979110', 0.9949384927749634)], [[[582.0, 57.0], [809.0, 46.0], [811.0, 79.0], [583.0, 90.0]], ('院市属瑞金医院', 0.8991981148719788)], [[[864.0, 90.0], [997.0, 86.0], [998.0, 117.0], [865.0, 121.0]], ('标本号:OA', 0.9697385430335999)], [[[377.0, 104.0], [685.0, 95.0], [686.0, 128.0], [378.0, 137.0]], ('报告单(临床内分泌)', 0.9352215528488159)], [[[620.0, 145.0], [755.0, 140.0], [755.0, 166.0], [620.0, 171.0]], ('标本种类:血清', 0.9918188452720642)], [[[850.0, 137.0], [946.0, 137.0], [946.0, 163.0], [850.0, 163.0]], ('标志提示:', 0.9854207038879395)], [[[349.0, 151.0], [540.0, 148.0], [541.0, 170.0], [349.0, 174.0]], ('门诊号:E05535540', 0.9973800182342529)], [[[621.0, 172.0], [859.0, 165.0], [860.0, 187.0], [621.0, 194.0]], ('条码号:10080603139', 0.9976526498794556)], [[[849.0, 166.0], [946.0, 166.0], [946.0, 189.0], [849.0, 189.0]], ('临床诊断:', 0.9855963587760925)], [[[126.0, 178.0], [187.0, 175.0], [188.0, 202.0], [127.0, 205.0]], ('别女', 0.627216100692749)], [[[348.0, 176.0], [536.0, 175.0], [537.0, 197.0], [348.0, 198.0]], ('门诊科别:门诊内分泌', 0.9945945739746094)], [[[622.0, 196.0], [775.0, 193.0], [775.0, 215.0], [622.0, 219.0]], ('申请医生:孙首悦', 0.9865230321884155)], [[[851.0, 190.0], [995.0, 186.0], [996.0, 212.0], [851.0, 215.0]], ('检测日期:2010', 0.9941444396972656)], [[[73.0, 203.0], [127.0, 203.0], [127.0, 226.0], [73.0, 226.0]], ('年', 0.9997568726539612)], [[[126.0, 202.0], [189.0, 202.0], [189.0, 226.0], [126.0, 226.0]], ('龄:31', 0.9798538684844971)], [[[72.0, 227.0], [168.0, 227.0], [168.0, 252.0], [72.0, 252.0]], ('检验备注:', 0.9906638860702515)], [[[70.0, 262.0], [121.0, 262.0], [121.0, 291.0], [70.0, 291.0]], ('项目', 0.9997086524963379)], [[[469.0, 258.0], [520.0, 258.0], [520.0, 287.0], [469.0, 287.0]], ('结果', 0.9980945587158203)], [[[691.0, 253.0], [792.0, 250.0], [793.0, 280.0], [692.0, 283.0]], ('参考范围', 0.9953070878982544)], [[[70.0, 297.0], [108.0, 297.0], [108.0, 322.0], [70.0, 322.0]], ('FT3', 0.9937674403190613)], [[[475.0, 293.0], [520.0, 293.0], [520.0, 317.0], [475.0, 317.0]], ('3.12', 0.9927419424057007)], [[[695.0, 289.0], [862.0, 286.0], [863.0, 311.0], [695.0, 313.0]], ('2.62--6.49pmol/L', 0.9501959085464478)], [[[69.0, 328.0], [107.0, 328.0], [107.0, 353.0], [69.0, 353.0]], ('FT4', 0.9952511787414551)], [[[476.0, 324.0], [530.0, 324.0], [530.0, 347.0], [476.0, 347.0]], ('15.40', 0.996757984161377)], [[[695.0, 320.0], [875.0, 316.0], [875.0, 342.0], [695.0, 345.0]], ('9.01--19.04pmol/L', 0.9781156182289124)], [[[67.0, 359.0], [121.0, 357.0], [122.0, 381.0], [69.0, 384.0]], ('STSH', 0.9913753271102905)], [[[476.0, 354.0], [520.0, 354.0], [520.0, 378.0], [476.0, 378.0]], ('1.31', 0.9948142766952515)], [[[696.0, 351.0], [864.0, 347.0], [865.0, 373.0], [696.0, 376.0]], ('0.35--4.94uIU/ml', 0.9357396364212036)], [[[477.0, 385.0], [521.0, 385.0], [521.0, 408.0], [477.0, 408.0]], ('0.15', 0.9976096153259277)], [[[700.0, 380.0], [810.0, 378.0], [811.0, 404.0], [700.0, 406.0]], ('<4.11IU/ml', 0.9650557637214661)], [[[68.0, 391.0], [125.0, 391.0], [125.0, 414.0], [68.0, 414.0]], ('TGAB', 0.9940923452377319)], [[[477.0, 414.0], [510.0, 414.0], [510.0, 440.0], [477.0, 440.0]], ('0.1', 0.9944899678230286)], [[[702.0, 412.0], [780.0, 412.0], [780.0, 436.0], [702.0, 436.0]], ('<5.0U/L', 0.9557269215583801)], [[[68.0, 422.0], [122.0, 422.0], [122.0, 445.0], [68.0, 445.0]], ('TRAb', 0.9839630126953125)], [[[477.0, 447.0], [521.0, 444.0], [522.0, 469.0], [478.0, 472.0]], ('0.17', 0.9835587739944458)], [[[701.0, 443.0], [814.0, 441.0], [815.0, 466.0], [701.0, 469.0]], ('<5.61IU/ml', 0.9220072031021118)], [[[67.0, 454.0], [135.0, 454.0], [135.0, 477.0], [67.0, 477.0]], ('TPOAb', 0.9806221127510071)], [[[477.0, 476.0], [512.0, 476.0], [512.0, 502.0], [477.0, 502.0]], ('0.1', 0.9947983622550964)], [[[702.0, 474.0], [850.0, 474.0], [850.0, 500.0], [702.0, 500.0]], ('0.1--10.0pg/ml', 0.9855452179908752)], [[[64.0, 485.0], [129.0, 485.0], [129.0, 511.0], [64.0, 511.0]], ('降钙素', 0.9983868598937988)], [[[622.0, 671.0], [852.0, 663.0], [852.0, 689.0], [622.0, 697.0]], ('报告时间:10-08-0711:28', 0.9753931760787964)], [[[890.0, 664.0], [999.0, 661.0], [999.0, 687.0], [891.0, 689.0]], ('打印时间:1', 0.9848820567131042)], [[[50.0, 683.0], [287.0, 676.0], [288.0, 701.0], [50.0, 708.0]], ('采样时间:10-08-0611:23', 0.9758442640304565)], [[[348.0, 677.0], [581.0, 670.0], [581.0, 694.0], [348.0, 701.0]], ('收到时间:10-08-0611:44', 0.9783890843391418)], [[[623.0, 703.0], [782.0, 700.0], [782.0, 726.0], [623.0, 730.0]], ('检验:李纪平', 0.9757030606269836)], [[[890.0, 695.0], [999.0, 691.0], [999.0, 721.0], [891.0, 725.0]], ('核对:', 0.9645571112632751)], [[[47.0, 716.0], [343.0, 709.0], [344.0, 735.0], [47.0, 742.0]], ('以上7项检验结果仅供临床医师参考', 0.9923603534698486)]]

进程已结束,退出代码0

003结果
图片不知道为什么跳出来的时候就这么糊……回头再看看

5. 找到别人的教程,但是我运行结果始终卡在跳出窗口然后一片空白,不理解,图片也是直接拿了这个教程里的

链接放这

测试图片

001

001

002

002

003

003

代码库

https://gitee.com/jiang-yangkk/ocr.git

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值