gpt4 book ai didi

python - 使用 python 和 Tesseract OCR 从文本中提取特定内容

转载 作者:太空宇宙 更新时间:2023-11-04 01:51:20 26 4
gpt4 key购买 nike

我正在使用 tesseract OCR 从图像文件中提取文本 Image .

下面是我从图片中得到的示例文本:

Certificate No. Certificate Issued Date Acoount Reference Unique Doc. Reference IN-KA047969602415880 18-Feb-2016 01:39 PM NONACC(FI)/kakfscI08/BTM LAYOUT/KA-BA SUBIN-KAKAKSFCL0858710154264833O

如何从中提取证书编号?任何提示或解决方案都会在这里帮助我。

最佳答案

如果证书编号始终采用此处给出的结构(2 个字母、连字符、17 位数字),您可以使用 regex:

import regex as re

# i took the entire sequence originally but this is just an example
sequence = 'Reference IN-KA047969602415880 18-Feb-2016 01:39'
re.search('[A-Z]{2}-.{17}', seq).group()
#'IN-KA047969602415880'

.search 搜索您指定的特定模式,.group() 返回第一个结果(在本例中只有一个)。您可以在给定的字符串中搜索类似的内容,我建议查看 regex here .

关于python - 使用 python 和 Tesseract OCR 从文本中提取特定内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57952052/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com