7行python代码实现核算检测批量复查

一起养成写作习惯!这是我参与「掘金日新计划 · 4 月更文挑战」的第18天,点击查看活动详情

一、为什么要弄该系统?

众所周知,当前大势下,核酸检测,验证复查是每天都少不了的场景。但是检测设备昂贵,且有次数限制,有的还需要向卫生相关部门申请,那么有没有可能搭建一套自己的核酸检测复查系统呢?答案是肯定的。

微信截图_20220418190257.png

二、PaddleHub快速部署

基本的思路是使用PaddleHub OCR模型对手机健康码等信息进行识别。可省去模型训练之烦恼,快速得到想要的效果,具体代码如下:

1.引入paddlehub包

import paddlehub as hub

2.引入 ocr 模型

调用chinese_ocr_db_crnn_server识别模型

三、代码

import paddlehub as hub, cv2, os, csv

if __name__ == '__main__':
    module = hub.Module(name="chinese_ocr_db_crnn_server")
    for root, dirs, all_list_path in os.walk("images"):
        results = module.recognize_text(images=[cv2.imread("images/" + image_path) for image_path in all_list_path],
                                        output_dir='ocr_result', visualization=True, box_thresh=0.5,
                                        text_thresh=0.5)  # use_gpu=True,
        for result in results:
            print(result)
复制代码

四、检测效果

{'save_path': 'ocr_result\\ndarray_1650280393.5890908.jpg', 'data': [{'text': 'HOD SGmN ', 'confidence': 0.5865637063980103, 'text_box_position': [[50, 0], [309, 14], [300, 75], [42, 53]]}, {'text': '3.8', 'confidence': 0.9981439113616943, 'text_box_position': [[289, 19], [329, 9], [337, 34], [298, 43]]}, {'text': '*56023:35', 'confidence': 0.8589357733726501, 'text_box_position': [[781, 19], [1018, 19], [1018, 56], [781, 56]]}, {'text': 'HD2', 'confidence': 0.9982423782348633, 'text_box_position': [[59, 43], [115, 43], [115, 68], [59, 68]]}, {'text': 'K/s', 'confidence': 0.9931795597076416, 'text_box_position': [[298, 39], [334, 39], [334, 63], [298, 63]]}, {'text': '核酸与抗体检测结:', 'confidence': 0.9794898629188538, 'text_box_position': [[50, 129], [697, 129], [697, 173], [50, 173]]}, {'text': '查询人员:', 'confidence': 0.9450464844703674, 'text_box_position': [[53, 275], [244, 275], [244, 321], [53, 321]]}, {'text': '切换', 'confidence': 0.9991570711135864, 'text_box_position': [[911, 304], [1029, 304], [1029, 363], [911, 363]]}, {'text': '张三33**************11', 'confidence': 0.9848297834396362, 'text_box_position': [[90, 333], [663, 324], [663, 385], [90, 394]]}, {'text': '省内核酸结果', 'confidence': 0.9990420937538147, 'text_box_position': [[157, 519], [435, 519], [435, 563], [157, 563]]}, {'text': '采样时间:2022-04-0614时', 'confidence': 0.974065363407135, 'text_box_position': [[98, 641], [694, 641], [694, 684], [98, 684]]}, {'text': '检测时间:2022-04-0700时', 'confidence': 0.9998931884765625, 'text_box_position': [[98, 719], [694, 719], [694, 762], [98, 762]]}, {'text': '阴性', 'confidence': 0.9995075464248657, 'text_box_position': [[852, 716], [945, 706], [950, 758], [857, 767]]}, {'text': '四川大学华西医院', 'confidence': 0.9998956918716431, 'text_box_position': [[98, 794], [424, 794], [424, 838], [98, 838]]}, {'text': '抗体检测结果', 'confidence': 0.9995054602622986, 'text_box_position': [[157, 953], [435, 953], [435, 996], [157, 996]]}, {'text': '未查询到您的检测结果', 'confidence': 0.9969052672386169, 'text_box_position': [[101, 1128], [559, 1128], [559, 1172], [101, 1172]]}, {'text': '服务说明:', 'confidence': 0.9897974133491516, 'text_box_position': [[56, 1326], [284, 1326], [284, 1379], [56, 1379]]}, {'text': '1.本服务支持查询本人14日内核酸检测结果和既往', 'confidence': 0.9986771941184998, 'text_box_position': [[59, 1413], [1015, 1413], [1015, 1450], [59, 1450]]}, {'text': '血清特异性lgG抗体检测结果。', 'confidence': 0.9697466492652893, 'text_box_position': [[56, 1474], [615, 1474], [615, 1518], [56, 1518]]}, {'text': '2.相关查询结果基于国家卫生健康部门数据库,根', 'confidence': 0.9759125709533691, 'text_box_position': [[56, 1555], [1015, 1555], [1015, 1591], [56, 1591]]}, {'text': '据各地检测数据提供,正在不断汇聚更新中。', 'confidence': 0.9888159036636353, 'text_box_position': [[56, 1618], [891, 1618], [891, 1655], [56, 1655]]}, {'text': '四川省应对新型冠状病毒肺炎疫情应急指挥部', 'confidence': 0.978419840335846, 'text_box_position': [[196, 2191], [880, 2191], [880, 2220], [196, 2220]]}, {'text': '四川省大数据中心提供支持', 'confidence': 0.981896162033081, 'text_box_position': [[334, 2242], [745, 2242], [745, 2271], [334, 2271]]}]}
{'save_path': 'ocr_result\\ndarray_1650280437.9316654.jpg', 'data': [{'text': 'HOD SGmN ', 'confidence': 0.5919920206069946, 'text_box_position': [[50, 0], [309, 14], [300, 75], [42, 53]]}, {'text': '3.8', 'confidence': 0.9982979893684387, 'text_box_position': [[289, 19], [329, 9], [337, 34], [298, 43]]}, {'text': '*≥6023:35', 'confidence': 0.8562882542610168, 'text_box_position': [[781, 19], [1018, 19], [1018, 56], [781, 56]]}, {'text': 'HD2', 'confidence': 0.9981972575187683, 'text_box_position': [[59, 43], [115, 43], [115, 68], [59, 68]]}, {'text': 'K/s', 'confidence': 0.9931250214576721, 'text_box_position': [[298, 39], [334, 39], [334, 63], [298, 63]]}, {'text': '核酸与抗体检测结:', 'confidence': 0.9796482920646667, 'text_box_position': [[50, 129], [697, 129], [697, 173], [50, 173]]}, {'text': ':', 'confidence': 0.6901877522468567, 'text_box_position': [[711, 124], [902, 117], [905, 170], [714, 177]]}, {'text': '查询人员:', 'confidence': 0.9437354207038879, 'text_box_position': [[53, 275], [244, 275], [244, 321], [53, 321]]}, {'text': '切换', 'confidence': 0.9991297721862793, 'text_box_position': [[911, 304], [1029, 304], [1029, 363], [911, 363]]}, {'text': '李四\u300033**************11', 'confidence': 0.9692168235778809, 'text_box_position': [[81, 331], [663, 324], [663, 385], [81, 392]]}, {'text': '省内核酸结果', 'confidence': 0.9991196990013123, 'text_box_position': [[157, 519], [435, 519], [435, 563], [157, 563]]}, {'text': '采样时间:2022-04-0614时', 'confidence': 0.9742894172668457, 'text_box_position': [[98, 641], [694, 641], [694, 684], [98, 684]]}, {'text': '检测时间:2022-04-0700时', 'confidence': 0.9998957514762878, 'text_box_position': [[98, 719], [694, 719], [694, 762], [98, 762]]}, {'text': '阴性', 'confidence': 0.9994761943817139, 'text_box_position': [[852, 716], [945, 706], [950, 758], [857, 767]]}, {'text': '四川大学华西医院', 'confidence': 0.9760406017303467, 'text_box_position': [[98, 794], [424, 794], [424, 838], [98, 838]]}, {'text': '抗体检测结果', 'confidence': 0.9995043277740479, 'text_box_position': [[157, 953], [435, 953], [435, 996], [157, 996]]}, {'text': '未查询到您的检测结果', 'confidence': 0.9970100522041321, 'text_box_position': [[101, 1128], [559, 1128], [559, 1172], [101, 1172]]}, {'text': '服务说明:', 'confidence': 0.9902758598327637, 'text_box_position': [[56, 1326], [284, 1326], [284, 1379], [56, 1379]]}, {'text': '1.本服务支持查询本人14日内核酸检测结果和既往', 'confidence': 0.9990904927253723, 'text_box_position': [[59, 1413], [1015, 1413], [1015, 1450], [59, 1450]]}, {'text': '血清特异性lgG抗体检测结果。', 'confidence': 0.9744695425033569, 'text_box_position': [[56, 1474], [615, 1474], [615, 1518], [56, 1518]]}, {'text': '2.相关查询结果基于国家卫生健康部门数据库,根', 'confidence': 0.9748148918151855, 'text_box_position': [[56, 1555], [1015, 1555], [1015, 1591], [56, 1591]]}, {'text': '据各地检测数据提供,正在不断汇聚更新中。', 'confidence': 0.986540675163269, 'text_box_position': [[56, 1618], [891, 1618], [891, 1655], [56, 1655]]}, {'text': '四川省应对新型冠状病毒肺炎疫情应急指挥部', 'confidence': 0.9854202270507812, 'text_box_position': [[196, 2191], [880, 2191], [880, 2220], [196, 2220]]}, {'text': '四川省大数据中心提供支持', 'confidence': 0.9782963991165161, 'text_box_position': [[334, 2242], [745, 2242], [745, 2271], [334, 2271]]}]}
{'save_path': 'ocr_result\\ndarray_1650280482.2817101.jpg', 'data': [{'text': 'HOD SGmN ', 'confidence': 0.5919920206069946, 'text_box_position': [[50, 0], [309, 14], [300, 75], [42, 53]]}, {'text': '3.8', 'confidence': 0.9982979893684387, 'text_box_position': [[289, 19], [329, 9], [337, 34], [298, 43]]}, {'text': '*≥6023:35', 'confidence': 0.8562882542610168, 'text_box_position': [[781, 19], [1018, 19], [1018, 56], [781, 56]]}, {'text': 'HD2', 'confidence': 0.9981972575187683, 'text_box_position': [[59, 43], [115, 43], [115, 68], [59, 68]]}, {'text': 'K/s', 'confidence': 0.9931250214576721, 'text_box_position': [[298, 39], [334, 39], [334, 63], [298, 63]]}, {'text': '核酸与抗体检测结:', 'confidence': 0.9796482920646667, 'text_box_position': [[50, 129], [697, 129], [697, 173], [50, 173]]}, {'text': ':', 'confidence': 0.6901877522468567, 'text_box_position': [[711, 124], [902, 117], [905, 170], [714, 177]]}, {'text': '查询人员:', 'confidence': 0.9880987405776978, 'text_box_position': [[53, 275], [241, 275], [241, 321], [53, 321]]}, {'text': '切换', 'confidence': 0.9991297721862793, 'text_box_position': [[911, 304], [1029, 304], [1029, 363], [911, 363]]}, {'text': '王五33**************11', 'confidence': 0.9995682835578918, 'text_box_position': [[95, 333], [663, 326], [663, 385], [95, 392]]}, {'text': '省内核酸结果', 'confidence': 0.9991196990013123, 'text_box_position': [[157, 519], [435, 519], [435, 563], [157, 563]]}, {'text': '采样时间:2022-04-0614时', 'confidence': 0.9742894172668457, 'text_box_position': [[98, 641], [694, 641], [694, 684], [98, 684]]}, {'text': '检测时间:2022-04-0700时', 'confidence': 0.9998957514762878, 'text_box_position': [[98, 719], [694, 719], [694, 762], [98, 762]]}, {'text': '阴性', 'confidence': 0.9994761943817139, 'text_box_position': [[852, 716], [945, 706], [950, 758], [857, 767]]}, {'text': '四川大学华西医院', 'confidence': 0.9760406017303467, 'text_box_position': [[98, 794], [424, 794], [424, 838], [98, 838]]}, {'text': '抗体检测结果', 'confidence': 0.9995043277740479, 'text_box_position': [[157, 953], [435, 953], [435, 996], [157, 996]]}, {'text': '未查询到您的检测结果', 'confidence': 0.9970100522041321, 'text_box_position': [[101, 1128], [559, 1128], [559, 1172], [101, 1172]]}, {'text': '服务说明:', 'confidence': 0.9902758598327637, 'text_box_position': [[56, 1326], [284, 1326], [284, 1379], [56, 1379]]}, {'text': '1.本服务支持查询本人14日内核酸检测结果和既往', 'confidence': 0.9990904927253723, 'text_box_position': [[59, 1413], [1015, 1413], [1015, 1450], [59, 1450]]}, {'text': '血清特异性lgG抗体检测结果。', 'confidence': 0.9744695425033569, 'text_box_position': [[56, 1474], [615, 1474], [615, 1518], [56, 1518]]}, {'text': '2.相关查询结果基于国家卫生健康部门数据库,根', 'confidence': 0.9748148918151855, 'text_box_position': [[56, 1555], [1015, 1555], [1015, 1591], [56, 1591]]}, {'text': '据各地检测数据提供,正在不断汇聚更新中。', 'confidence': 0.986540675163269, 'text_box_position': [[56, 1618], [891, 1618], [891, 1655], [56, 1655]]}, {'text': '四川省应对新型冠状病毒肺炎疫情应急指挥部', 'confidence': 0.9854202270507812, 'text_box_position': [[196, 2191], [880, 2191], [880, 2220], [196, 2220]]}, {'text': '四川省大数据中心提供支持', 'confidence': 0.9782963991165161, 'text_box_position': [[334, 2242], [745, 2242], [745, 2271], [334, 2271]]}]}

复制代码

ndarray_1650280393.5890908.jpg

ndarray_1650280437.9316654.jpg

ndarray_1650280482.2817101.jpg

五、其他

可以在学校等需要需要批量广泛核酸核查场景使用。识别结果可保存至excel表格,从而减轻工作量。

猜你喜欢

转载自juejin.im/post/7087901735296958472
今日推荐