为什么pytesseract无法在此简单图像中识别数字? [英] Why does pytesseract fail to recognize digits in this simple image?
问题描述
我正在尝试使用pytesseract来识别图像中的两个数字:
I'm trying to use pytesseract to recognize two numbers from an image:
- 我尝试了
--psm 6
至10
- 我尝试了
-c tessedit_char_whitelist=0123456789'
- I have tried
--psm 6
up to10
- I have tried
-c tessedit_char_whitelist=0123456789'
以上都不返回49
号.我得到的最近的是返回的4
没有9
None of the above returns 49
number. Closest I got is returned 4
without 9
您有关于如何使tesseract识别它的任何提示吗?
Do you have any tips about how to make tesseract recognize it ?
推荐答案
尝试--psm 13 --oem 3
(oem
= 1或2也应这样做)
Try --psm 13 --oem 3
(oem
= 1 or 2 should do also)
import pytesseract
from PIL import Image
import requests
import io
response = requests.get('https://i.stack.imgur.com/oAAXR.png')
text = pytesseract.image_to_string(Image.open(io.BytesIO(response.content)), lang='eng',
config='--psm 13 --oem 3 -c tessedit_char_whitelist=0123456789')
print(text)
在您的机器上按预期输出49
.
yields 49
as you expect on my machine.
通过在本地下载图像并启动
I get the same result by downloading the image locally and firing
tesseract oAAXR.png output --oem 3 --psm 13 -l eng
我的tesseract --version
给出的参考
tesseract 4.0.0 leptonica-1.77.0 libgif 5.1.4 : libjpeg 8d (libjpeg-turbo 2.0.1) : libpng 1.6.36 : libtiff 4.0.10 : zlib 1.2.11 : libwebp 1.0.1 Found AVX2 Found AVX Found SSE
.
这篇关于为什么pytesseract无法在此简单图像中识别数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!