pytesseract和image.tif fi

2024-03-29 14:04:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要抄写图像.tif使用pytesseract编写多页文本。 我有下一个代码:

> From PIL import Image
> Import pytesseract
> Pytesseract.pytesseract.tesseract_cmd = 'C: / Program Files (x86) / Tesseract-
> OCR / tesseract '
> Print (pytesseract.image_to_string (Image.open ('CAMARA.tif'), lang = "spa"))

问题是只提取第一页。我怎样才能把它们全部提取出来?在


Tags: 代码from图像image文本importcmdpil
3条回答

我猜你只提到了一个形象”卡马拉.tif“,首先你必须把所有的pdf页面转换成你可以看到的图片link。在

然后使用pytesseract逐个循环图像,从图像中提取文本。在

我刚才也遇到了同样的问题。。。你能做的就是直接打电话给tesseract

# test.py
import subprocess

in_filename = 'file_0.tiff'
out_filename = 'out'
lang = 'spa'
subprocess.call(['tesseract', in_filename, '-l', lang, out_filename ])

会处理所有页面

^{pr2}$

我可以通过调用如下方法convert()来解决相同的问题

image = Image.open(imagePath).convert("RGBA")
text = pytesseract.image_to_string(image)
print(text)

相关问题 更多 >