python-3.x - 如何从填写的银行账户表格中自动提取用户信息
问题描述
我正在尝试从扫描的开户表格中提取手写信息。为此,我使用 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)
解决方案
推荐阅读
- javascript - 在外部单击时隐藏下拉菜单(使用 JavaScript)
- python - 为什么 selenium driver.page_source 不匹配 requests.get().text?
- javascript - (Javascript)如何从 4 个可能的变量中选择一个随机变量并使用它们的值(x 和 y 坐标)在 Canvas 上绘制图像?
- python - 如何防止直接设置实例属性?
- bash - 用点和数字对字母进行排序的排序选项
- c - 从字符串数组中删除头部
- java - 在底部导航栏中保存片段状态
- neo4j - 在图投影的子集上运行 allShortestPaths
- python - 在elpy下执行时如何向python脚本输入参数?
- python - 通用详细视图 ProductListView 必须在 URLconf 中使用对象 pk 或 slug 调用