tesseract 5.0集市+用户单词配置不起作用

时间:2019-12-12 14:51:41

标签: ocr tesseract python-tesseract

我尝试强制tesseract在执行OCR时仅使用我的单词列表。 首先,我将市集文件复制到/usr/share/tesseract-ocr/5/tessdata/configs/。这是我的集市文件:

load_system_dawg F
load_freq_dawg F
user_words_suffix user-words

然后,我在eng.user-words中创建了/usr/share/tesseract-ocr/5/tessdata。这是我的用户单词文件:

Items
VAT
included
CASH

然后我通过以下命令对此图像执行ocr:tesseract -l eng --oem 2 test_small.jpg stdout bazaar

test_img

这是我的结果:

2 Item(s) (VAT includsd) 36,000
casH 40,000
CHANGE 4. 000

如您所见,includsd不在我的用户单词文件中,应该被“包含”。此外,即使没有在命令中使用bazaaz config,我也得到了相同的结果。看来我的bazaareng.user-words配置在OCR输出中没有任何作用。那么如何使用bazaaruser-words的配置,以获得所需的结果?

2 个答案:

答案 0 :(得分:0)

user_words_suffix似乎不适用于--oem 2。 一种解决方法是使用user_words_file,其中包含您的用户单词文件的路径。

答案 1 :(得分:0)

您需要做的就是对图像进行上采样。

如果上采样两次

enter image description here

现在阅读:

2 Item(s) (VAT included) 36,000
CASH 40,000
CHANGE 4,000

代码:

import cv2
import pytesseract

# Load the image
img = cv2.imread("4nGXo.jpg")

# Convert to the gray-scale
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Up-sample
gry = cv2.resize(gry, (0, 0), fx=2, fy=2)

# OCR
print(pytesseract.image_to_string(gry))

# Display
cv2.imshow("", gry)
cv2.waitKey(0)
相关问题