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
    评论
Python OCR是一种用于识别图像中的文字的技术。在Python中,有多种库可以实现OCR功能,如cnocr、pytesseract等。引用\[1\]中的代码演示了如何使用cnocr库进行OCR识别,通过调用CnOcr类的ocr()函数,可以将指定图像中的文字识别出来。引用\[2\]中的代码展示了如何使用pytesseract库调用tesseract-ocr进行文字识别,通过调用image_to_string()函数,可以将指定图像中的文字转换为字符串。引用\[3\]中的代码也展示了使用pytesseract库进行OCR识别的简单示例,通过调用image_to_string()函数,同样可以将指定图像中的文字识别出来。所以,Python OCR是一种利用Python编程语言实现的文字识别技术,可以帮助我们从图像中提取文字信息。 #### 引用[.reference_title] - *1* *3* [pythonOCR文字识别](https://blog.csdn.net/wu_zhiyuan/article/details/125412990)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Python实现OCR文字识别](https://blog.csdn.net/weixin_50814640/article/details/129449260)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

巽为风-0815

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

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

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

打赏作者

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

抵扣说明:

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

余额充值