【发布时间】:2020-12-07 01:16:56
【问题描述】:
我有这张图片
我正在阅读框中的数字,它显然应该是数字1;但是,后面的代码始终将其读取为数字4。似乎很奇怪,它会出错,因为我正在使用的 pdf 表单中有许多类似的实例,它确实正确。我能做些什么来纠正这种特殊情况而不妨碍正确执行的操作吗?
图像只是可填写的 pdf 表单的一部分。我阅读了 pdf 并将其保存为图像。然后 tesseract 将图像读入文本文件。
这是文本转换为jpg 文件后的样子
image_counter=1
pages = convert_from_path(filename, poppler_path= dir_path+r'\poppler-0.68.0\bin')
for page in pages:
filename = "page_"+str(image_counter)+".jpg"
# Save the image of the page in system
page.save(filename, 'JPEG')
# Increment the counter to update filename
image_counter+=1
# Variable to get count of total number of pages
filelimit = image_counter-1
# Iterate from 1 to total number of pages
for i in range(1, filelimit + 1):
filename = "page_"+str(i)+".jpg"
# Recognize the text as string in image using pytesserct
text = str(pytesseract.image_to_string(Image.open(filename), config='--psm 6 --dpi 300 --oem 3'))
f.write(text) # f is the file I am writing to
【问题讨论】:
标签: python-3.x pdf ocr tesseract