Pytesseract可以检测数字和操作员

发布于 2025-01-29 00:04:22 字数 816 浏览 6 评论 0原文

我想从图像中提取两个数字和一个操作员(例如14 + 23),但是我写的这个脚本不起作用:

import cv2 as cv
import pytesseract

img = cv.imread('VerificationImage.jpg')
img = cv.cvtColor(img, cv.COLOR_BGR2RGB)

print(pytesseract.image_to_string(img))

conf = r'--oem 3 --psm 11 outputbase digits'
boxes = pytesseract.image_to_data(img, config=conf)

for x, b in enumerate(boxes.splitlines()):
    if x != 0:
        b = b.split()
        print(b)
        if len(b) == 12:
            x, y, w, h = int(b[6]), int(b[7]), int(b[8]), int(b[9])
            cv.rectangle(img, (x,y), (x+w, y+h), (0, 120, 0), 2)
        


cv.imshow("display", img)
cv.waitKey()

示例图像是这样的: 图像“

I want to extract two digits and an operator (e.g. 14 + 23) from an image, but this script that I wrote, won't work:

import cv2 as cv
import pytesseract

img = cv.imread('VerificationImage.jpg')
img = cv.cvtColor(img, cv.COLOR_BGR2RGB)

print(pytesseract.image_to_string(img))

conf = r'--oem 3 --psm 11 outputbase digits'
boxes = pytesseract.image_to_data(img, config=conf)

for x, b in enumerate(boxes.splitlines()):
    if x != 0:
        b = b.split()
        print(b)
        if len(b) == 12:
            x, y, w, h = int(b[6]), int(b[7]), int(b[8]), int(b[9])
            cv.rectangle(img, (x,y), (x+w, y+h), (0, 120, 0), 2)
        


cv.imshow("display", img)
cv.waitKey()

The sample image is like this:
The sample image

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文