我试图识别下图底部左上角代表时间的数字。
具体来说,这是我需要识别的图像:
数字采用七格格式。
我正在使用opencv和tesseract,但是我使用的任何过滤器都无法获得良好的结果。
这是开发的代码(我假设已经确定了数字所在的部分,所以这是我的起点):
image = cv2.imread("C:\example2.jpg")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
edged = cv2.Canny(blurred, 50, 200, 255)
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
text = pytesseract.image_to_string(edged)
尝试过使用另一组滤镜,但没有一个滤镜能给我接近图像的结果。提前致谢。
最佳答案
Tesseract喜欢在白色背景上的黑色文本。另外,它喜欢characters to be a minimum height。
我通过cv2.THRESH_OTSU
进行Otsu thresholding和cv2.THRESH_BINARY_INV
来反转图像(将黑变白,白变黑)。以原始大小,“9”被识别为“q”。我将尺寸调整为2,识别度更好。
import cv2
import pytesseract
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
img = cv2.imread('example2.jpg', cv2.IMREAD_GRAYSCALE)
thresh = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)[1]
thresh = cv2.resize(thresh, (0,0), fx=2, fy=2) # scale image 2X
detected_text = pytesseract.image_to_string(thresh, config = '--psm 6')
print(detected_text)
这使9:47
关于python - 七个小节数字识别-计算机视觉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63529678/