最近在使用Python识别PNG图像中包含的文字时遇到一个问题。解决过程记录如下。
(Python使用tesserocr的安装过程不再描述。)
在使用tesserocr识别PNG图像中的文字时,如果PNG比较"干净",背景没有噪音时,过程比较简单,代码如下:
from PIL import Image
import tesserocr
image = Image.open(r'../data/demo01.png')
print(tesserocr.image_to_text(image))
输出结果为:
This is some text, written in Arial, that will be read by
Tesseract. Here are some symbols: !@#$%"&'()
效果还算可以。