只是厌倦了使用你的小的和放大的(x4)图像馈送到Tesseract 4.0.0a。即使调整了Tesseract参数,小图像也没有输出。扩大后的一个能够OCR在所有三个案例测试-没有进一步的处理,灰度和进一步增强。在
使用的Tesseract集成到OpenCV 3.2.0中。以下是代码。在import cv2
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
def show(img):
plt.imshow(img, cmap="gray")
plt.show()
def ocr(img):
# Tesseract mode settings:
# Page Segmentation mode (PSmode) = 3 (defualt = 3)
# OCR Enginer Mode (OEM) = 3 (defualt = 3)
tesser = cv2.text.OCRTesseract_create(C:/Program Files/Tesseract 4.0.0/tessdata/,eng, 123456789,3,3)
retval = tesser.run(img, 0) # return string type
print OCR Output: + retval
# Directly feed image to Tesseact
img = cv2.imread(./imagesStackoverflow/SmallDigits-x4.png)
ocr(img)