Tesseract无法从简单图像中识别数字

发布于 2025-01-29 03:53:50 字数 539 浏览 6 评论 0原文

这是图像,我正在尝试提取“ 3158”

 导入CV2
导入Tesseract
    
img = cv2.imread('cropped.png')
convert_to_string = pytesseract.image_to_string(img)
打印(convert_to_string)
 

但不幸的是,它没有打印

我尝试过的

pytesseract.image_to_string(img,config=' --psm 1 --oem 3)

任何东西,

pytesseract.image_to_string(img,config=' --psm 6)

但仍然没有运气

This is the image and I'm trying to extract "3158"

enter image description here

And this is the code

import cv2
import tesseract
    
img = cv2.imread('cropped.png')
convert_to_string = pytesseract.image_to_string(img)
print (convert_to_string)

But unfortunately it failed to print anything

I've tried

pytesseract.image_to_string(img,config=' --psm 1 --oem 3)

and

pytesseract.image_to_string(img,config=' --psm 6)

But still no luck

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

粉红×色少女 2025-02-05 03:53:50

尝试首先对图像进行二进制,如果字体在背景中没有清晰脱颖而出,则Tesseract无法正常工作。由于背景中有梯度,因此您可能会通过自适应阈值预处理获得一些优秀结果:

import cv2
import pytesseract

img = cv2.imread('cropped.png')
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

img_bin = cv2.adaptiveThreshold(
    img_gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 11, 10
)

img_bin = cv2.cvtColor(img_bin, cv2.COLOR_GRAY2BGR)

convert_to_string = pytesseract.image_to_string(img_bin)
print(convert_to_string)

Try to binarize the image first, Tesseract does not work well if the font does not stand out clearly from the background. Since there's a gradient in the background, you may get some first good results with adaptive thresholding preprocessing:

import cv2
import pytesseract

img = cv2.imread('cropped.png')
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

img_bin = cv2.adaptiveThreshold(
    img_gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 11, 10
)

img_bin = cv2.cvtColor(img_bin, cv2.COLOR_GRAY2BGR)

convert_to_string = pytesseract.image_to_string(img_bin)
print(convert_to_string)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文