首页 > 解决方案 > 如何从填写的银行账户表格中自动提取用户信息

问题描述

我正在尝试从扫描的开户表格中提取手写信息。为此,我使用 Pytesseract python 库来提取文本数据。但是使用这个模块我在输出中有很多不规则的地方,因为我得到了不均匀的字符。

此外,用户填写个人信息(如姓名、地址、出生日期等)的表单中的框也会导致问题,因为模块 pytesseract 将其检测为字母“I”。那么有没有办法处理这些盒子呢?

还有其他方法可以完成这项任务吗?如果有请建议。这是我正在处理的扫描表格

下面是我做的代码

import matplotlib.pyplot as plt
import pytesseract
from PIL import Image
from nltk.tokenize import sent_tokenize, word_tokenize

image = Image.open('printer1.jpg')
print(image.info['dpi'])
image.save("new_img.jpg", dpi=(400,400)) # increased the dpi and saved it

new_img = Image.open('new_img.jpg')
width, height = new_img.size

new_size = width*2, height*2
new_img = new_img.resize(new_size, Image.LANCZOS) #sampling
new_img = new_img.convert('L') #converted it to grayscale

new_img = new_img.point(lambda x: 0 if x < 180 else 255, '1') 
#evaluatingevery single pixel in the image for binarization

plt.imshow(new_img)
plt.show()

text = pytesseract.image_to_string(new_img)
text_array = word_tokenize(text)
print(text_array)

Name_Data = text_array[text_array.index('Proof')+2 : 
text_array.index('FIRST')-1]
print(Name_Data)

Name = ""
for i in Name_Data:
   if i == 'I':
       pass
   else:
       Name += i

print(Name)

标签: python-3.xopencvimage-processingpython-imaging-librarypytesser

解决方案


推荐阅读