我一直在使用tesseract将文档转换为文本.文档的质量范围非常广泛,我正在寻找有关哪种图像处理可能会改善结果的提示.我注意到高度像素化的文本 - 例如由传真机生成的文本 - 对于tesseract来说特别难以处理 - 可能是角色的所有锯齿状边缘都会混淆形状识别算法.
什么样的图像处理技术可以提高准确度?我一直在使用高斯模糊来平滑像素化图像并看到一些小的改进,但我希望有更具体的技术可以产生更好的结果.假设一个过滤器被调整为黑白图像,这将平滑不规则的边缘,然后是一个过滤器,它会增加对比度,使角色更加清晰.
对于图像处理新手的任何一般提示?
我需要使用ImageMagick,因为PIL没有我正在寻找的图像功能.但是,我想使用Python.
python绑定(PythonMagick)自2009年以来一直没有更新.我唯一能找到的就是os.system调用命令行界面,但这看起来很笨拙.
有没有办法直接使用ctypes和转换某种类型的API ?作为最后的手段,还有其他任何图书馆都有大量的ImageMagick图像编辑工具,我已经查看了吗?
它是Python 3中的一个简单的光学字符识别(OCR)程序,用于获取字符串,我已经在此处上传了目标gif文件,请下载并将其另存为/tmp/target.gif。
try:
from PIL import Image
except ImportError:
import Image
import pytesseract
print(pytesseract.image_to_string(Image.open('/tmp/target.gif')))
Run Code Online (Sandbox Code Playgroud)
我将所有错误信息粘贴到此处,请修复它以从图像中获取字符。
/usr/lib/python3/dist-packages/PIL/Image.py:925: UserWarning: Couldn't allocate palette entry for transparency
"for transparency")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/pytesseract/pytesseract.py", line 309, in image_to_string
}[output_type]()
File "/usr/local/lib/python3.5/dist-packages/pytesseract/pytesseract.py", line 308, in <lambda>
Output.STRING: lambda: run_and_get_output(*args),
File "/usr/local/lib/python3.5/dist-packages/pytesseract/pytesseract.py", line 208, in run_and_get_output
temp_name, input_filename = save_image(image)
File "/usr/local/lib/python3.5/dist-packages/pytesseract/pytesseract.py", line 136, in save_image
image.save(input_file_name, format=img_extension, **image.info)
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 1728, in save
save_handler(self, …Run Code Online (Sandbox Code Playgroud)