【发布时间】:2021-09-08 08:11:03
【问题描述】:
我想阅读线圈上的文字(一些由数字组成的 ID)。但是 OCR 程序无法识别它。当我给出小部分时,它只能识别线性部分(3个数字)。我认为这是因为 ID 是半圆形的。我必须检测 ID,并且我正在使用带有 tesseract 库的 python 代码。我怎样才能做到这一点?谢谢。
# import the necessary packages
import numpy as np
import pytesseract
import argparse
import imutils
import cv2
pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
image = cv2.imread('1.jpg')
#Cropping and having Region Of Interest
(h, w) = image.shape[:2]
ROI = image[200:450, 1100:1550]
cv2.imshow("ROI", ROI)
gray = cv2.cvtColor(ROI, cv2.COLOR_BGR2GRAY)
cv2.imshow("ROI", gray)
# threshold the image using Otsu's thresholding method
thresh = cv2.threshold(gray, 0, 255,
cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cv2.imshow("Otsu", thresh)
options = "--psm 3 -c tessedit_char_whitelist=0123456789"
text = pytesseract.image_to_string(thresh, config=options)
print(text)
cv2.waitKey(0)
【问题讨论】:
-
从线圈的轴线看并应用极性展开。
-
请提供足够的代码,以便其他人更好地理解或重现问题。
-
我已经把我正在处理的代码放在了。
标签: python image-processing ocr tesseract python-tesseract