最近公司天天在排查核酸检测报告情况,看的我是眼花缭乱。作为机器视觉的我深知,计算机代替人可是事半功倍。于是准备上手写一个代码。
原图大体类似这种:
我需要每天看大量的这类图。于是。我决定使用paddle
安装python3.6.6版本
开始手写代码:
import paddlehub as hub
import cv2
import os
import csv
os.environ['CUDA_VISIBLE_DEVICES']="0"
def manyImages(dirpath):
dirpath = dirpath
all_list = []
all_list_path = []
i = 0
for root,dirs,files in os.walk(dirpath):
for file in files:
i = i + 1
imgpath = os.path.join(root,file)
all_list.append(imgpath+"\n")
all_list_path.append(imgpath)
allstr = ''.join(all_list)
f = open('all_list.txt','w',encoding='utf-8')
f.write(allstr)
return all_list_path , i
all_list_path,all_lenth = manyImages("test")
ocr = hub.Module(name="chinese_ocr_db_crnn_server")
np_images =[cv2.imread(image_path) for image_path in all_list_path]
results = ocr.recognize_text(
images=np_images,
use_gpu=True,
output_dir='ocr_result',
visualization=True,
box_thresh=0.5,
text_thresh=0.5)
with open('result.csv', 'w') as f:
row=['姓名_身份证号码','检测时间','结果','检测时间','结果','检测时间','结果','检测时间','结果']
write=csv.writer(f)
write.writerow(row)
f.close()
for result in results:
data = result['data']
with open('result.csv', 'a',newline='') as f:
write=csv.writer(f)
r = []
for information in data:
#抽取规则用if判断,写入到csv文件
if(("*" in information['text']) or (":" in information['text']) or ("阴性" in information['text'])):
r.append(information['text'])
write.writerow(r)
f.close
运行时只需要 pip install paddle
pip install paddlehub 就好了
这样我们就可以直接识别了。核酸检测文件大量的截图放到test里,直接读取该文件夹里全部图片。
经检测后。效果图如下:
项目文件结构如下:
你如果想替换你需要的规则输出csv表文件的话代码只需要改这里:
if(("*" in information['text']) or ("时间" in information['text']) or ("阴性" in information['text'])):
更改代码 重新运行程序后,保存的csv文件如图:
好了。想体验ocr的快去尝试吧!我已经解放自己双手了。继续摸鱼去了……
项目下载:
手把手叫你用python做一个ocr核酸检测报告统计表-深度学习文档类资源-CSDN下载手把手叫你用python做一个ocr核酸检测报告统计表更多下载资源、学习资料请访问CSDN下载频道.https://download.csdn.net/download/xifenglie123321/85191654