我正在使用 tesseract OCR 从图像文件中提取文本 .
下面是我从图片中得到的示例文本:
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/