Python图像到包含在五边形pytesseract中的文本

2024-05-20 05:10:46 发布

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

我正在尝试使用python准备EPC证书中的能效等级。EPC证书通常采用PDF格式。我已经将PDF转换为图像,并使用PyteSeract从图像中获取文本。然而,我没有得到预期的结果

示例图像: enter image description here

预期产出: 电流额定值:79,潜在额定值:79

到目前为止,我所尝试的:

from pdf2image import convert_from_path
import pytesseract
from PIL import Image

pages = convert_from_path(r'my_file.pdf', 500)
img =pages[0].save(r'F:\Freelancer\EPC rating\fwdepcs\out.jpg', 'JPEG')
text = pytesseract.image_to_string(Image.open(r'F:\Freelancer\EPC rating\fwdepcs\out.jpg'))

然而,文本并不能捕获79

我还尝试了cv2模式匹配和形状检测,但由于其他原因,这些都不起作用


Tags: pathfrom图像image文本importconvertpdf
1条回答
网友
1楼 · 发布于 2024-05-20 05:10:46

您说您已将此pdf转换为图像文件

使用PIL(.crop())或opencv裁剪图片。并按如下方式进行裁剪:

enter image description here

使用PILImage.convert("1"),也许tesseract可以捕捉到这个数字。 如果没有,我认为您可以使用jTessBoxEditor来培训tesseract

相关问题 更多 >