python ocr识别身份证_如何使用Tesseract训练基于Python的OCR以使用不同的国家身份证?...

提高Pytesseract识别率的步骤:

1)清理图像数组,只留下文本(字体生成,而不是手写)。字母的边缘应不变形。应用阈值(尝试不同的值)。同时应用一些平滑过滤器。我也推荐使用形态上的开/关-但这只是一个奖励。这是以数组形式进入pytesseract识别的夸张示例:https://i.ytimg.com/vi/1ns8tGgdpLY/maxresdefault.jpg

2)使用要识别的文本将图像大小调整为更高的分辨率

3)Pytesseract通常应该可以识别任何类型的字母,但是通过安装文本所用的字体,您可以极大地提高准确性。

如何在pytesseract中安装新字体:

1)以TIFF格式获取所需字体

3)将训练数据文件(.trained data)添加到此文件夹C:\程序文件(x86)\ Tesseract OCR\tessdata

4)将此字符串命令添加到pytesseract重新复制函数:假设您有两种经过训练的字体:font1.traineddata和font2.traineddata

要同时使用这两个命令

txt=pytesseract.image_to_字符串(img,lang='font1+font2')

这里有一个代码来测试您在网络图像上的识别:import cv2

import pytesseract

import cv2

import numpy as np

import urllib

import requests

pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'

TESSDATA_PREFIX = 'C:/Program Files (x86)/Tesseract-OCR'

from PIL import Image

def url_to_image(url):

resp = urllib.request.urlopen(url)

image = np.asarray(bytearray(resp.read()), dtype="uint8")

image = cv2.imdecode(image, cv2.IMREAD_COLOR)

return image

url='http://jeroen.github.io/images/testocr.png'

img = url_to_image(url)

#img = cv2.GaussianBlur(img,(5,5),0)

img = cv2.medianBlur(img,5)

retval, img = cv2.threshold(img,150,255, cv2.THRESH_BINARY)

txt = pytesseract.image_to_string(img, lang='eng')

print('recognition:', txt)

>>> txt

'This ts a lot of 12 point text to test the\nocr code and see if it works on all types\nof file format\n\nThe quick brown dog jumped over the\nlazy fox The quick brown dog jumped\nover the lazy fox The quick brown dog\njumped over the lazy fox The quick\nbrown dog jumped over the lazy fox'

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值