Pytesseract可以检测数字和操作员
我想从图像中提取两个数字和一个操作员(例如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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论