python tesseract OCR:仅获取数字

2024-06-07 04:25:21 发布

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

我正在使用tesseract OCRwith python tesseract。 在tesseract FAQ中,关于数字,我们有:

Use

TessBaseAPI::SetVariable("tessedit_char_whitelist", "0123456789");

BEFORE calling an Init function or put this in a text file called tessdata/configs/digits:

tessedit_char_whitelist 0123456789

and then your command line becomes:

tesseract image.tif outputbase nobatch digits

Warning: Until the old and new config variables get merged, you must have the nobatch parameter too.

在python tesseract中,SetVariable方法存在。我试过了,但是OCR的结果是一样的:

api = tesseract.TessBaseAPI()
api.SetVariable("tessedit_char_whitelist", "0123456789")
api.Init('.','eng',tesseract.OEM_DEFAULT)
api.SetPageSegMode(tesseract.PSM_AUTO)

有人已经让它工作了吗,或者我应该认为它是python tesseract中的一个bug吗?


Tags: andtheapiinit数字faqwhitelistdigits