python OCR

from cnocr import CnOcr
import re


def ocr_front(path):
    ocr = CnOcr()
    s = ocr.ocr(path)
    text = ''
    for txt in s:
        text += txt['text']
    # print(text)
    dict_txt = {'国籍': text.split('居')[0],
                '证件类别': text.split('国')[1].split('签')[0],
                text.split('证')[1][:4]: text.split('关')[1].split('有')[0],
                '有' + text.split('有')[1][:3]: text.split('限')[1]
                }
    return dict_txt


def ocr_back(path):


    ocr = CnOcr()
    s = ocr.ocr(path)
    text = ''
    for txt in s:
        text += txt['text']
    # print(text)
    dict_txt = {'姓名': text[text.find('名')+1:text.find('别')-1],
                '性别': text[text.find('别')+1:text.find('民族')],
                '出生': re.sub(r'\D', '', text[text.find('生')+1:text.find('住')]),
                '住址': text[text.find('址')+1:text.find('公民')],
                '公民身份号码': text[text.find('份号码')+3:text.find('份号码')+21]
                }
    return dict_txt


if __name__ == '__main__':
    Idc_front = ocr_front('Id_Card_n.jpeg')
    Idc_back = ocr_back('123456.png')
    for key in Idc_front:
        print("{}:{}".format(key, Idc_front[key]))
    for key in Idc_back:
        print("{}:{}".format(key, Idc_back[key]))

cnocr再训练:

一、获取源代码

git clone https://github.com/breezedeus/cnocr.git

二、准备训练数据

 引用+参考:CNOCR重训练_萧班的博客-CSDN博客_cnocr 训练

如侵权,联系删除

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

采蘑菇的小郎儿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值