python - Tesseract OCR - 指定模式
问题描述
我正在尝试使用 Tesseract(版本 3.04.00)执行 OCR。我所有的图像都有相同的模式(数字点数字,即精度为 2 位的小数)。我尝试使用该--user-patterns
选项,但我无法让它工作。
我做了什么:
patterns.txt
在\d.\d\d
第一行创建一个文件- 使用选项
--user-patterns patterns.txt
但我收到以下错误:
pytesseract.pytesseract.TesseractError: (1, "Tesseract Open Source OCR Engine v3.04.00 with Leptonica read_params_file: Can't open 1 read_params_file: Can't open user-patterns read_params_file: parameter not found: \\d.\\d\\d")
如何将我的模式指定给 Tesseract ?这甚至是正确的方法吗?在此先感谢您的帮助或建议,我在 Tesseract 上找不到太多文档。
编辑:添加 Python 代码
img = cv2.imread("path/to/image", cv2.IMREAD_GRAYSCALE)
text = pytesseract.image_to_string(img, config="-psm 7 --user-patterns patterns.txt")
print(text)
解决方案
没关系,我认为 Tesseract 对我的用例来说太过分了。
我拍摄了从 0 到 9 的每个数字的图像,并选择了我想要预测的图像的最小均方误差。在我的测试数据集上获得 100% 的准确率。
推荐阅读
- html - 如何使用 QT Creator 获取网页源代码?
- python - 如何为 keras 模型使用 tensorflow 自定义损失?
- mongodb - (MongoDB)聚合(.out)将值移动到错误的字段
- pdf - 使用 Ghostscript 从 PDF 中提取 cmyk 和点分离
- create-react-app - 当服务器代码发生更改时,create-react-app 不会重新启动
- node.js - Mongoose UnhandledPromiseRejectionWarning: MissingSchemaError: Schema还没有为模型注册
- javascript - 如何将包含数组值的 Map/JSON 对象放入本地存储
- python - 为什么我的 python 代码不能正确绘制星星?
- sql - 如何从没有父级的表中删除子记录
- r - ggplot2 在同一个图块中绘制组变量的所有级别