如何在 pytesseract 中使用经过训练的数据?
How to use trained data with pytesseract?
使用此工具http://trainyourtesseract.com/ 我希望能够通过 pytesseract 使用新字体。该工具给我一个名为 *.traineddata
的文件
现在我正在使用这个简单的脚本:
try:
import Image
except ImportError:
from PIL import Image
import pytesseract as tes
results = tes.image_to_string(Image.open('./test.jpg'),boxes=True)
file = open('parsing.text','a')
file.write(results)
print(results)
如何使用我的训练数据文件以便我能够使用 python 脚本读取新字体?
谢谢!
edit#1 :所以我知道 *.traineddata
可以作为命令行程序与 Tesseract 一起使用。所以我的问题仍然是一样的,我如何使用 traineddata with python ?
编辑#2:我的问题的答案在这里 How to access the command line for Tesseract from Python?
下面是带有选项的 pytesseract.image_to_string()
示例。
pytesseract.image_to_string(Image.open("./imagesWhosebug/xyz-small-gray.png"),
lang="eng",boxes=False,
config="--psm 4 --oem 3
-c tessedit_char_whitelist=-01234567890XYZ:"))
要使用您自己训练的语言数据,只需将 lang="eng"
中的 "eng"
替换为您的语言 name(.traineddata)
。
使用此工具http://trainyourtesseract.com/ 我希望能够通过 pytesseract 使用新字体。该工具给我一个名为 *.traineddata
的文件现在我正在使用这个简单的脚本:
try:
import Image
except ImportError:
from PIL import Image
import pytesseract as tes
results = tes.image_to_string(Image.open('./test.jpg'),boxes=True)
file = open('parsing.text','a')
file.write(results)
print(results)
如何使用我的训练数据文件以便我能够使用 python 脚本读取新字体?
谢谢!
edit#1 :所以我知道 *.traineddata
可以作为命令行程序与 Tesseract 一起使用。所以我的问题仍然是一样的,我如何使用 traineddata with python ?
编辑#2:我的问题的答案在这里 How to access the command line for Tesseract from Python?
下面是带有选项的 pytesseract.image_to_string()
示例。
pytesseract.image_to_string(Image.open("./imagesWhosebug/xyz-small-gray.png"),
lang="eng",boxes=False,
config="--psm 4 --oem 3
-c tessedit_char_whitelist=-01234567890XYZ:"))
要使用您自己训练的语言数据,只需将 lang="eng"
中的 "eng"
替换为您的语言 name(.traineddata)
。