使用pytesseract从类型为'PIL.PpmImagePlugin.PpmImageFile'的图像中提取文本时出现错误

时间:2019-07-09 06:30:36

标签: python python-tesseract

尝试使用'PIL.PpmImagePlugin.PpmImageFile'从类型为pytesseract的图像中提取文本。代码和错误如下

from pdf2image import convert_from_path
pages = convert_from_path('D:/pdf_csv/HealthCare/eRDS - ML/eRDS - ML/2001468/2001468,69,70.pdf',poppler_path='C:/Users/Hp/poppler-0.68.0/bin')
text = pyt.image_to_string(Image.open(pages[0]), lang='eng')

我得到的错误:

AttributeError: 'PpmImageFile' object has no attribute 'read'

或者是否有任何方法可以将PpmImageFile转换为'jpg'或'png'格式

1 个答案:

答案 0 :(得分:0)

fmt='jpeg'fmt='png'添加到函数调用中,以从pdf2image获取非PPM图像。

在您的示例中,更改

pages = convert_from_path('D:/pdf_csv/Health....001468,69,70.pdf',poppler_path='C:/Users/Hp/poppler-0.68.0/bin')

pages = convert_from_path('D:/pdf_csv/Health...001468,69,70.pdf', fmt='jpeg', poppler_path='C:/Users/Hp/poppler-0.68.0/bin')