简体   繁体   English

为什么 pytesseract 无法识别此图像

[英]Why pytesseract can't recognize this image

I am testing the pytesseract OCR on this image我正在这张图片上测试 pytesseract OCR

在此处输入图像描述

but the result is always 30770.0 but I would have wanted this number: 997,70 FYI: this image has already been transformed:但结果总是 30770.0 但我想要这个数字:997,70 仅供参考:这张图片已经被转换了:

img = img.convert('L')  # greyscale
img = img.resize((img.size[0] * 3, img.size[1] * 3), 1)
img = ImageEnhance.Contrast(img).enhance(5.0)
img = ImageOps.equalize(img)
img = ImageOps.invert(img)

Below the code:代码下方:

pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
img2 = "full_snap__1609584655.png"
numStr2 = pytesseract.image_to_string(img2, lang='eng',config='--psm 10 --oem 1 digits -c tessedit_char_whitelist=0123456789')
print('997,70 :',float(numStr2))

I have already tried to adjust the --psm parameter of the pytesseract function image_to_string but it doesn't work.我已经尝试调整 pytesseract function image_to_string 的 --psm 参数,但它不起作用。

Thank you for your help谢谢您的帮助

My solution to the problem is morphological-transformation.我对这个问题的解决方案是形态转换。

If you apply erosion如果你应用侵蚀

the thickness or size of the foreground object decreases or simply white region decreases in the image.前景 object 的厚度或大小减小或图像中的白色区域减小。 It is useful for removing small white noises (as we have seen in colorspace chapter), detach two connected objects etc.它对于去除小的白噪声(正如我们在色彩空间章节中所见)、分离两个连接的对象等很有用。

erd = cv2.erode(gry, None, iterations=1)

Result:结果:

在此处输入图像描述

Now, if you read it:现在,如果您阅读它:

print(pytesseract.image_to_string(erd))

Result:结果:

997 70€

Code:代码:


import cv2
import pytesseract

img = cv2.imread("R83OY.png")
h, w, c = img.shape
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
erd = cv2.erode(gry, None, iterations=1)
print(pytesseract.image_to_string(erd))

Possible Question: Why do you set kernel to None?可能的问题:为什么将 kernel 设置为 None?

If you initialize a kernel (ie (5, 5) ) and apply it to the image, result will be:如果初始化 kernel (即 (5, 5) )并将其应用于图像,结果将是:

在此处输入图像描述

As you can see, applying kernel is not improving the result.如您所见,应用 kernel 并没有改善结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM